Skip to content

Commit

Permalink
Create matrix-from-previous-job-output-3.yml (#1346)
Browse files Browse the repository at this point in the history
* Create matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update matrix-from-previous-job-output-3.yml

* Update README.md
  • Loading branch information
nakamasato authored May 25, 2024
1 parent 597f071 commit 4f34eb8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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
Expand Up @@ -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
Expand Down

0 comments on commit 4f34eb8

Please sign in to comment.