Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create matrix-from-previous-job-output-3.yml #1346

Merged
merged 12 commits into from
May 25, 2024
38 changes: 38 additions & 0 deletions .github/workflows/matrix-from-previous-job-output-3.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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