diff --git a/actions/actions.sh b/actions/actions.sh index ceb8c04c..5ddffd1f 100755 --- a/actions/actions.sh +++ b/actions/actions.sh @@ -176,5 +176,9 @@ function test_actions() { if dpkg --compare-versions $version ge 9.0; then run actions_verify_example schedule-noncancel fi + + if dpkg --compare-versions $version ge 14.0; then + run actions_verify_example matrix-dynamic + fi done } diff --git a/actions/example-matrix-dynamic/.forgejo/workflows/test.yml b/actions/example-matrix-dynamic/.forgejo/workflows/test.yml new file mode 100644 index 00000000..170a009b --- /dev/null +++ b/actions/example-matrix-dynamic/.forgejo/workflows/test.yml @@ -0,0 +1,49 @@ +on: [push] +jobs: + define-matrix: + runs-on: docker + outputs: + scalar-value: ${{ steps.define.outputs.scalar }} + array-value: ${{ steps.define.outputs.array }} + matrix-value: ${{ steps.define.outputs.matrix }} + steps: + - id: define + run: | + echo 'scalar=scalar value' >> "$FORGEJO_OUTPUT" + echo 'array=["value 1", "value 2"]' >> "$FORGEJO_OUTPUT" + echo 'matrix={"dimension-1": ["d1 v1", "d1 v2"], "dimension-2": ["d2 v1", "d2 v2"]}' >> "$GITHUB_OUTPUT" + + scalar-job: + runs-on: docker + needs: define-matrix + strategy: + matrix: + scalar: + - "${{ needs.define-matrix.outputs.scalar-value }}" + - hard-coded value + steps: + - run: | + set -x + [ "${{ matrix.scalar }}" = "scalar value" ] || [ "${{ matrix.scalar }}" = "hard-coded value" ] || exit 1 + + array-job: + runs-on: docker + needs: define-matrix + strategy: + matrix: + array: ${{ fromJSON(needs.define-matrix.outputs.array-value) }} + steps: + - run: | + set -x + [ "${{ matrix.array }}" = "value 1" ] || [ "${{ matrix.array }}" = "value 2" ] || exit 1 + + matrix-job: + runs-on: docker + needs: define-matrix + strategy: + matrix: ${{ fromJSON(needs.define-matrix.outputs.matrix-value) }} + steps: + - run: | + set -x + [ "${{ matrix.dimension-1 }}" = "d1 v1" ] || [ "${{ matrix.dimension-1 }}" = "d1 v2" ] || exit 1 + [ "${{ matrix.dimension-2 }}" = "d2 v1" ] || [ "${{ matrix.dimension-2 }}" = "d2 v2" ] || exit 1 diff --git a/actions/example-matrix-dynamic/run.sh b/actions/example-matrix-dynamic/run.sh new file mode 100644 index 00000000..18b8fc05 --- /dev/null +++ b/actions/example-matrix-dynamic/run.sh @@ -0,0 +1,10 @@ +forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example setup-forgejo $token + +# Verify that the matrix in the job was expanded correctly by checking that +# there are 9 completed jobs, by their commit statuses being present on the +# main branch's HEAD. +api=$url/api/v1 +sha=$(forgejo-curl.sh api_json $api/repos/root/example-matrix-dynamic/branches/main | jq -r ".commit.id") +num_runs=$(forgejo-curl.sh api_json $api/repos/root/example-matrix-dynamic/commits/$sha/status | jq ".total_count") +echo "Expecting 9 commit statuses, found $num_runs commit statuses" +test $num_runs = 9