diff --git a/.github/workflows/matrix-from-previous-job-output-3.yml b/.github/workflows/matrix-from-previous-job-output-3.yml new file mode 100644 index 00000000..6072f3b8 --- /dev/null +++ b/.github/workflows/matrix-from-previous-job-output-3.yml @@ -0,0 +1,38 @@ +name: matrix-from-previous-job-output-3 + +on: + pull_request: + push: + branches: + - main + +jobs: + # From https://github.com/dorny/paths-filter + # JOB to run change detection + set-matrix: + runs-on: ubuntu-latest + outputs: + include: ${{ steps.set-matrix.outputs.include }} + steps: + - uses: actions/checkout@v4 + # Deploy each app to dev for pull request + # Deploy each app to both prod and dev for push (main) + - name: set matrix + id: set-matrix + run: | + if [[ "${{ github.event_name }}" = "pull_request" ]]; then + echo "include=[{\"app\": \"app1\", \"env\": \"dev\"}, {\"app\": \"app2\", \"env\": \"dev\"}]" >> "$GITHUB_OUTPUT" + elif [[ "${{ github.event_name }}" = "push" ]]; then + echo "include=[{\"app\": \"app1\", \"env\": \"dev\"}, {\"app\": \"app1\", \"env\": \"prod\"}, {\"app\": \"app2\", \"env\": \"dev\"}, {\"app\": \"app2\", \"env\": \"prod\"}]" >> "$GITHUB_OUTPUT" + fi + + execute: + strategy: + matrix: + include: ${{ fromJson(needs.set-matrix.outputs.include) }} + runs-on: ubuntu-latest + needs: [set-matrix] + steps: + - name: "app: ${{ matrix.app }}, matrix: ${{ matrix.env }}" + run: | + echo "app: ${{ matrix.app }}, matrix: ${{ matrix.env }}" diff --git a/README.md b/README.md index f1b87fd3..fe09a307 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ |---|---|---| |[matrix-from-previous-job-output](.github/workflows/matrix-from-previous-job-output.yml)|pull_request|matrix execution from the output of the previous step. `fromJson`| |[matrix-from-previous-job-output-2](.github/workflows/matrix-from-previous-job-output-2.yml)|pull_request, push|matrix execution from the output of the previous step. `fromJson`| +|[matrix-from-previous-job-output-3](.github/workflows/matrix-from-previous-job-output-3.yml)|pull_request, push| do something for both `prod` and `dev` for `push` event and do sth only for `dev` for `pull_request` event| |[matrix-by-condition](.github/workflows/matrix-by-condition.yml)|pull_request, push|run for dev and prod when merged to main. run only for dev for pull_request.| ## CheatSheet