Skip to content

Commit

Permalink
Task A-4: Run image_build_push only after tests pass successfully
Browse files Browse the repository at this point in the history
Approach:
Converted test-with-docker and test-with-manual-install to reusable workflows.
Added them as jobs in image_build_push workflow.
Build job in this workflow needs these test jobs as dependencies.

-------

Test Workflow run
https://github.com/MukuFlash03/e-mission-server/actions/runs/11096277197/job/30825929886

-----

Notes

Github actions didn't have out of the box solution for running a workflow based on results of multiple workflows where ALL workflows must have completed successfully.
We need this since both the test-with-docker and test-with-manual-install must pass.
So this needs an "AND" logic.

"workflow_run" is there but this triggers the dependent workflow when either of the workflow dependencies defined as prerequisites are completed.
So this has an "OR" logic.
https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run

----

Found an alternative suggestion here:
https://stackoverflow.com/a/75597437

This suggests converting the pre-requisite workflows into reusable workflows.
These workflows can then be called in jobs in the workflow that needs these workflows to be run before.
Finally, these jobs can be added as dependencies for the requisite job.

In our scenario, two new jobs are added to the image_build_push.yml for each of the two tests environments.
These will run parallelly.

Then in the build image job, these jobs are added in the "needs" field, indicating that these jobs must pass successfully before running the build job.

-------

Also corrected the branch in reusable workflow for fetching latest server image tag.
Need to update in the currently open PRs as well.

------

Also, removed the `push` trigger from the two `test` workflows since the `image_build_push` workflow would also be triggered on a `push` event which in its workflow triggers these two test workflows.
Thus if not removed, each test workflow would run twice.
  • Loading branch information
MukuFlash03 committed Sep 30, 2024
1 parent b2382ec commit d56f652
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/image_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ env:
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}

jobs:
test-with-docker:
uses: e-mission/e-mission-server/.github/workflows/test-with-docker.yml@master

test-with-manual-install:
uses: e-mission/e-mission-server/.github/workflows/test-with-manual-install.yml@master

build:
runs-on: ubuntu-latest
needs: [test-with-docker, test-with-manual-install]

outputs:
date: ${{ steps.date.outputs.date }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_image_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
id: get-server-tag
run: |
if [ "${{ inputs.repo }}" = "op-admin-dashboard" ] || [ "${{ inputs.repo }}" = "em-public-dashboard" ]; then
response=$(curl -s https://raw.githubusercontent.com/e-mission/e-mission-server/refs/heads/cleanup-cicd/.env)
response=$(curl -s https://raw.githubusercontent.com/e-mission/e-mission-server/refs/heads/master/.env)
SERVER_IMAGE_TAG=$(echo "$response" | grep "SERVER_IMAGE_TAG=" | cut -d'=' -f2)
echo "SERVER_IMAGE_TAG=$SERVER_IMAGE_TAG" >> "$GITHUB_OUTPUT"
fi
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-with-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ name: test-with-docker
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '5 4 * * 0'

workflow_call:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test-with-manual-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ name: ubuntu-only-test-with-manual-install
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
- gis-based-mode-detection
pull_request:
branches:
- master
Expand All @@ -17,6 +13,8 @@ on:
# * is a special character in YAML so you have to quote this string
- cron: '5 4 * * 0'

workflow_call:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
Expand Down

0 comments on commit d56f652

Please sign in to comment.