parallel-job-example #3
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
# Workflow name | |
name: parallel-job-example | |
# Triggers for the workflow | |
on: | |
# Manual trigger using the workflow_dispatch event | |
workflow_dispatch: | |
# Automatic trigger on push events to the main branch | |
push: | |
branches: | |
- main | |
# Automatic trigger on pull request events targeting the main branch | |
pull_request: | |
branches: | |
- main | |
# Scheduled trigger at 5:00 AM UTC, Monday through Friday | |
schedule: | |
- cron: '0 5 * * 1-5' | |
# Jobs defined in the workflow | |
jobs: | |
build-and-test-1: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: latest | |
- name: Print a message for main branch | |
if: github.ref == 'refs/heads/main' | |
run: echo "This is the main branch." | |
- name: Print a message for non-main branches | |
if: github.ref != 'refs/heads/main' | |
run: echo "This is not the main branch." | |
- name: Run tests | |
run: npm test | |
- name: Debug message | |
if: env.DEBUG == 'true' | |
run: echo "Debugging is enabled." | |
build-and-test-2: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: latest | |
- name: Print a message for main branch | |
if: github.ref == 'refs/heads/main' | |
run: echo "This is the main branch." | |
- name: Print a message for non-main branches | |
if: github.ref != 'refs/heads/main' | |
run: echo "This is not the main branch." | |
- name: Run tests | |
run: npm test | |
- name: Debug message | |
if: env.DEBUG == 'true' | |
run: echo "Debugging is enabled." | |
post-build-actions: | |
needs: [build-and-test-1, build-and-test-2] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Publish test results | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-results | |
path: test-results.xml |