From d56f6528882d3c050ed5b14103bc326715e535db Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Sun, 29 Sep 2024 16:40:25 -0700 Subject: [PATCH] Task A-4: Run image_build_push only after tests pass successfully 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. --- .github/workflows/image_build_push.yml | 7 +++++++ .github/workflows/reusable_image_build_push.yml | 2 +- .github/workflows/test-with-docker.yml | 4 ++-- .github/workflows/test-with-manual-install.yml | 6 ++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index 1afab6fca..bbc092cd8 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -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 }} diff --git a/.github/workflows/reusable_image_build_push.yml b/.github/workflows/reusable_image_build_push.yml index 6bbfcf8e2..5de4eb7eb 100644 --- a/.github/workflows/reusable_image_build_push.yml +++ b/.github/workflows/reusable_image_build_push.yml @@ -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 diff --git a/.github/workflows/test-with-docker.yml b/.github/workflows/test-with-docker.yml index 1b54ed5ba..d661e6a02 100644 --- a/.github/workflows/test-with-docker.yml +++ b/.github/workflows/test-with-docker.yml @@ -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" diff --git a/.github/workflows/test-with-manual-install.yml b/.github/workflows/test-with-manual-install.yml index 4a81eb000..75f920682 100644 --- a/.github/workflows/test-with-manual-install.yml +++ b/.github/workflows/test-with-manual-install.yml @@ -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 @@ -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"