Skip to content

Commit 51a26ee

Browse files
committed
feat: make pi-matrix reusable
1 parent b7006b6 commit 51a26ee

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

.github/workflows/pi_matrix.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Parent Images: Matrix'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
parent_image_type:
7+
description: 'If specified, "include" only outputs apps associated to this parent image type'
8+
required: false
9+
type: string
10+
default: ''
11+
outputs:
12+
parent_image_type:
13+
description: 'List[str] of parent image types'
14+
value: ${{ jobs.pi-matrix.outputs.parent_image_type }}
15+
include:
16+
description: 'List[Dict] of apps associated to parent image types'
17+
value: ${{ jobs.pi-matrix.outputs.include }}
18+
19+
jobs:
20+
pi-matrix:
21+
name: 'Parent Images: Generate Matrix'
22+
runs-on: ubuntu-latest
23+
environment: dev
24+
env:
25+
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
26+
outputs:
27+
parent_image_type: ${{ steps.generate-matrix.outputs.parent_image_type }}
28+
include: ${{ steps.generate-matrix.outputs.include }}
29+
steps:
30+
- name: Checkout Repository
31+
uses: actions/checkout@v4
32+
with:
33+
repository: ${{ github.repository_owner }}/refinery-submodule-parent-images
34+
ref: ${{ github.event.pull_request.head.ref }}
35+
36+
- name: GitHub Configuration
37+
run: git config --global url."https://oauth2:${{ secrets.GH_TOKEN }}@github.com".insteadOf https://github.com
38+
39+
- name: Clone cicd-deployment-scripts
40+
run: git clone --branch parent-images https://github.com/code-kern-ai/cicd-deployment-scripts.git
41+
42+
- name: Generate Matrix
43+
id: generate-matrix
44+
run: |
45+
bash cicd-deployment-scripts/pi/matrix.sh \
46+
-p "${{ github.event.pull_request.number }}" \
47+
-s cicd-deployment-scripts/pi/settings.sh \
48+
-t "${{ inputs.parent_image_type }}"

pi/generate_matrix.sh renamed to pi/matrix.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
set -e
44

5+
PARENT_IMAGE_TYPE=""
56
PR_NUMBER=""
67
SOURCE_SCRIPT="pi/settings.sh"
78

8-
while getopts p:s: flag
9+
while getopts t:p:s: flag
910
do
1011
case "${flag}" in
12+
t) PARENT_IMAGE_TYPE=${OPTARG};;
1113
p) PR_NUMBER=${OPTARG};;
1214
s) SOURCE_SCRIPT=${OPTARG};;
1315
esac
@@ -27,8 +29,14 @@ while IFS= read -r file; do
2729

2830
done <<< "$UPDATED_FILES"
2931

32+
if [ -n $PARENT_IMAGE_TYPE ]; then
33+
UPDATED_PARENT_TYPES=( $PARENT_IMAGE_TYPE )
34+
fi
35+
36+
PARENT_IMAGE_TYPES=""
3037
INCLUDES=""
3138
for parent_image_type in "${UPDATED_PARENT_TYPES[@]}"; do
39+
PARENT_IMAGE_TYPES+="\"$parent_image_type\","
3240
eval 'APP_REPOS=( "${'$(echo ${parent_image_type} | sed "s|-|_|g")'[@]}" )'
3341
for app in "${APP_REPOS[@]}"; do
3442
INCLUDES+='{ "parent_image_type": "'${parent_image_type}'", "app": "'${app}'" },'
@@ -37,4 +45,5 @@ done
3745

3846
MATRIX='{"include": ['${INCLUDES::-1}']}'
3947
echo $MATRIX | jq -C --indent 2 '.'
40-
echo "include=[${INCLUDES::-1}]" >> $GITHUB_OUTPUT
48+
echo "include=[${INCLUDES::-1}]" >> $GITHUB_OUTPUT
49+
echo "parent_image_type=[${PARENT_IMAGE_TYPES::-1}]" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)