Test using a n8n workflow #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 16 - Conditional | |
on: | |
issues: | |
types: [opened] | |
workflow_dispatch: | |
jobs: | |
job1: | |
runs-on: ubuntu-latest | |
steps: | |
- name: handle-all-issues | |
run: echo "This step runs for all issues" | |
- if: startsWith(github.event.issue.title, 'bug') | |
name: handle-bug-reports | |
run: echo "This step runs only for bug reports" | |
- if: startsWith(github.event.issue.title, 'feature request') | |
name: handle-feature-requests | |
run: echo "This step runs only for feature requests" | |
- name: Create file status_job1.txt and write the job status into it | |
if: always() | |
run: | | |
echo ${{ job.status }} > status_job1.txt | |
- name: Upload file status_job1.txt as an artifact | |
if: always() | |
uses: actions/[email protected] | |
with: | |
name: pass_status_job1 | |
path: status_job1.txt | |
job2: | |
runs-on: ubuntu-latest | |
needs: job1 | |
continue-on-error: true | |
steps: | |
- if: true | |
name: step-1 | |
run: echo "Step 1" | |
- if: always() | |
name: step-2 | |
run: echo "Step 2" | |
- if: 1 == 1 | |
name: step-3 | |
run: echo "Step 3" | |
- if: startsWith('foo', 'f') | |
name: step-4 | |
run: echo "Step 4" | |
- run: cat ERROR.md | |
- name: Create file status_job2.txt and write the job status into it | |
if: always() | |
run: | | |
echo ${{ job.status }} > status_job2.txt | |
- name: Upload file status_job2.txt as an artifact | |
if: always() | |
uses: actions/[email protected] | |
with: | |
name: pass_status_job2 | |
path: status_job2.txt | |
job3: | |
runs-on: ubuntu-latest | |
needs: job2 | |
if: always() | |
steps: | |
- run: echo "THis command will always be executed even if previous job2 fails" | |
- name: Create file status_job3.txt and write the job status into it | |
if: always() | |
run: | | |
echo ${{ job.status }} > status_job3.txt | |
- name: Upload file status_job3.txt as an artifact | |
if: always() | |
uses: actions/[email protected] | |
with: | |
name: pass_status_job3 | |
path: status_job3.txt | |
job4: | |
runs-on: ubuntu-latest | |
needs: [job1, job2, job3] | |
if: always() | |
steps: | |
- name: Download artifact pass_status_job1 | |
uses: actions/[email protected] | |
with: | |
name: pass_status_job1 | |
- name: Download artifact pass_status_job2 | |
uses: actions/[email protected] | |
with: | |
name: pass_status_job2 | |
- name: Download artifact pass_status_job3 | |
uses: actions/[email protected] | |
with: | |
name: pass_status_job3 | |
- name: Set the statuses of Job 1, Job 2, Job3 as output parameters | |
id: set_outputs | |
run: | | |
echo "::set-output name=status_job1::$(<pass_status_job1/status_job1.txt)" | |
echo "::set-output name=status_job2::$(<pass_status_job2/status_job2.txt)" | |
echo "::set-output name=status_job3::$(<pass_status_job3/status_job3.txt)" | |
- name: Show the values of the outputs | |
run: | | |
# using the syntax steps.<step_id>.outputs.<output_name> to access the output parameters | |
echo "status_job1 = ${{ steps.set_outputs.outputs.status_job1 }}" | |
echo "status_job2 = ${{ steps.set_outputs.outputs.status_job2 }}" | |
echo "status_job3 = ${{ steps.set_outputs.outputs.status_job3 }}" | |
check-secret: | |
runs-on: ubuntu-latest | |
outputs: | |
my-key: ${{ steps.my-key.outputs.defined }} | |
steps: | |
- id: my-key | |
env: | |
MY_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
if: "${{ env.MY_KEY != '' }}" | |
run: echo "defined=true" >> $GITHUB_OUTPUT | |
job5: | |
runs-on: ubuntu-latest | |
needs: [check-secret] | |
if: needs.check-secret.outputs.my-key == 'true' | |
steps: | |
- run: echo "This command is executed if AWS_ACCESS_KEY_ID secret IS NOT empty" | |
job6: | |
runs-on: ubuntu-latest | |
needs: [check-secret] | |
if: needs.check-secret.outputs.my-key != 'true' | |
steps: | |
- run: echo "This command is executed if AWS_ACCESS_KEY_ID secret IS empty" | |
job7: | |
runs-on: ubuntu-latest | |
steps: | |
- id: step1 | |
run: echo "test=hello" >> $GITHUB_OUTPUT | |
- name: step 2 | |
if: contains(steps.step1.outputs.test, 'hello') | |
run: echo 'is executed' | |
- name: step 3 | |
if: contains(steps.step1.outputs.test, 'not_hello') | |
run: echo 'not executed' |