Skip to content

Commit

Permalink
fix: conditional run matrix (#129)
Browse files Browse the repository at this point in the history
throws error if matrix is empty, prevent that with if check
  • Loading branch information
ishaansehgal99 committed Nov 2, 2023
1 parent b556e6a commit 098f032
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/preset-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ jobs:

- name: Get Modified files
run: |
git fetch origin main
git checkout --detach
git fetch origin main:main
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" == "main" ] || [ "$current_branch" == "master" ]; then
files=$(git diff --name-only HEAD^ HEAD)
else
files=$(git diff --name-only main...HEAD)
files=$(git diff --name-only origin/main...HEAD)
fi
echo "Modified files: $files"
FILES_MODIFIED=""
Expand Down Expand Up @@ -139,6 +140,7 @@ jobs:
runs-on: self-hosted
outputs:
matrix: ${{ steps.set_matrix.outputs.matrix }}
matrix_empty: ${{ steps.set_matrix.outputs.matrix_empty }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -151,12 +153,19 @@ jobs:
run: |
matrix=$(jq --arg FALCON_MODIFIED "${{ needs.setup.outputs.FALCON_MODIFIED }}" --arg LLAMA2_MODIFIED "${{ needs.setup.outputs.LLAMA2_MODIFIED }}" --arg LLAMA2_CHAT_MODIFIED "${{ needs.setup.outputs.LLAMA2_CHAT_MODIFIED }}" 'map(
. | select((.shouldBuildFalcon == $FALCON_MODIFIED) or (.shouldBuildLlama2 == $LLAMA2_MODIFIED) or (.shouldBuildLlama2Chat == $LLAMA2_CHAT_MODIFIED))
)' .github/matrix-configs.json)
)' .github/matrix-configs.json)
# Check if matrix is empty and set an output variable
if [[ $matrix == "[]" ]]; then
echo "matrix_empty=true" >> $GITHUB_OUTPUT
else
echo "matrix_empty=false" >> $GITHUB_OUTPUT
fi
echo "matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
build-models:
needs: [setup, matrix_prep]
runs-on: self-hosted
if: ${{needs.matrix_prep.outputs.matrix_empty == 'false'}}
strategy:
fail-fast: false
matrix: ${{fromJson(needs.matrix_prep.outputs.matrix)}}
Expand Down

0 comments on commit 098f032

Please sign in to comment.