From 6eaacbbac3137dab7c26d796308832ffa677013d Mon Sep 17 00:00:00 2001 From: Benjamin Lee <130000039+benlee0423@users.noreply.github.com> Date: Thu, 4 Jan 2024 12:43:39 -0800 Subject: [PATCH] Run actions when PR is created and updated. (#74) * refactor to support to run actions on pr * add debug * add docker token * add input * add env * define env * define env * define env * define env * add secrets * add secrets * secrets inherit * fix tag name * fix tag name * fix tag name * set input required * fix * use vars * fix variable * remove debug --- .../build-and-push/action.yaml | 5 +- .github/workflows/docker_deps_image.yml | 9 +-- .../workflows/docker_image_main_branch.yml | 63 +++++++++++++------ .github/workflows/docker_ngen_image.yml | 14 +---- .github/workflows/docker_troute_image.yml | 14 +---- 5 files changed, 57 insertions(+), 48 deletions(-) diff --git a/.github/action_templates/build-and-push/action.yaml b/.github/action_templates/build-and-push/action.yaml index 25266066..54215477 100644 --- a/.github/action_templates/build-and-push/action.yaml +++ b/.github/action_templates/build-and-push/action.yaml @@ -14,6 +14,9 @@ inputs: dockerfile-name: description: 'The name of dockerfile to use' required: true + tag-name: + description: 'The name of tag to use' + required: true runs: using: "composite" @@ -39,7 +42,7 @@ runs: push: true platforms: linux/arm64 tags: | - awiciroh/${{ inputs.image-name}}:latest + awiciroh/${{ inputs.image-name}}:${{ inputs.tag-name}} builder: mybuilder no-cache: true env: diff --git a/.github/workflows/docker_deps_image.yml b/.github/workflows/docker_deps_image.yml index a9f19855..ee8d27be 100644 --- a/.github/workflows/docker_deps_image.yml +++ b/.github/workflows/docker_deps_image.yml @@ -4,12 +4,8 @@ on: branches: [ main ] paths: - docker/** - pull_request: - branches: [ main ] - paths: - - docker/** workflow_dispatch: - + workflow_call: jobs: build-and-push: runs-on: self-hosted @@ -25,4 +21,5 @@ jobs: docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }} github-sha: ${{ github.sha }} image-name: "ngen-deps" - dockerfile-name: "Dockerfile.ngen-deps" \ No newline at end of file + dockerfile-name: "Dockerfile.ngen-deps" + tag-name: ${{vars.TAG_NAME}} \ No newline at end of file diff --git a/.github/workflows/docker_image_main_branch.yml b/.github/workflows/docker_image_main_branch.yml index 1f6d4c9c..ba01db3f 100644 --- a/.github/workflows/docker_image_main_branch.yml +++ b/.github/workflows/docker_image_main_branch.yml @@ -4,16 +4,25 @@ on: branches: [ main ] paths: - docker/** - workflow_run: - workflows: [Build and push ngen image] - types: - - completed + pull_request: + branches: [ main ] workflow_dispatch: - + jobs: - on-success: + deps: + uses: ./.github/workflows/docker_deps_image.yml + secrets: inherit + troute: + needs: deps + uses: ./.github/workflows/docker_troute_image.yml + secrets: inherit + ngen: + needs: troute + uses: ./.github/workflows/docker_ngen_image.yml + secrets: inherit + final: + needs: ngen runs-on: self-hosted - if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: deploy uses: actions/checkout@v2 @@ -24,24 +33,40 @@ jobs: github-sha: ${{ github.sha }} image-name: "ciroh-ngen-image" dockerfile-name: "Dockerfile" - - name: Publish slack message - if: always() - uses: ./.github/action_templates/slack - with: - slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} - job-status: ${{ job.status }} - pull_request_url: ${{ github.event.pull_request.html_url }} - head_commit_url: ${{ github.event.head_commit.url }} - on-failure: + tag-name: ${{vars.TAG_NAME}} + check_result: + needs: final + runs-on: self-hosted + outputs: + output1: ${{ steps.step1.outputs.result }} + steps: + - id: step1 + run: echo "result=success" >> "$GITHUB_OUTPUT" + + slack: runs-on: self-hosted - if: ${{ github.event.workflow_run.conclusion == 'failure' }} + if: ${{ always() }} + needs: [deps, troute, ngen, final, check_result] + env: + OUTPUT: ${{needs.check_result.outputs.output1}} steps: - - run: echo 'The triggering workflow failed' + - name: Set env JOBSTATUS + run: | + echo "$OUTPUT" + if [[ "success" = "$OUTPUT" ]] + then + echo "JOBSTATUS=success" >> "$GITHUB_ENV" + else + echo "JOBSTATUS=failure" >> "$GITHUB_ENV" + fi + - run: echo "$JOBSTATUS" + - name: deploy + uses: actions/checkout@v2 - name: Publish slack message if: always() uses: ./.github/action_templates/slack with: slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} - job-status: ${{ job.status }} + job-status: ${{ env.JOBSTATUS }} pull_request_url: ${{ github.event.pull_request.html_url }} head_commit_url: ${{ github.event.head_commit.url }} \ No newline at end of file diff --git a/.github/workflows/docker_ngen_image.yml b/.github/workflows/docker_ngen_image.yml index 6aa6405e..09d40a9a 100644 --- a/.github/workflows/docker_ngen_image.yml +++ b/.github/workflows/docker_ngen_image.yml @@ -4,16 +4,12 @@ on: branches: [ main ] paths: - docker/** - workflow_run: - workflows: [Build and push t-route image] - types: - - completed workflow_dispatch: + workflow_call: jobs: - on-success: + build-and-push: runs-on: self-hosted - if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: deploy uses: actions/checkout@v2 @@ -24,8 +20,4 @@ jobs: github-sha: ${{ github.sha }} image-name: "ngen" dockerfile-name: "Dockerfile.ngen" - on-failure: - runs-on: self-hosted - if: ${{ github.event.workflow_run.conclusion == 'failure' }} - steps: - - run: echo 'The triggering workflow failed' \ No newline at end of file + tag-name: ${{vars.TAG_NAME}} \ No newline at end of file diff --git a/.github/workflows/docker_troute_image.yml b/.github/workflows/docker_troute_image.yml index acc0f945..57e00eae 100644 --- a/.github/workflows/docker_troute_image.yml +++ b/.github/workflows/docker_troute_image.yml @@ -4,16 +4,12 @@ on: branches: [ main ] paths: - docker/** - workflow_run: - workflows: [Build and push deps image] - types: - - completed workflow_dispatch: + workflow_call: jobs: - on-success: + build-and-push: runs-on: self-hosted - if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: deploy uses: actions/checkout@v2 @@ -24,8 +20,4 @@ jobs: github-sha: ${{ github.sha }} image-name: "t-route" dockerfile-name: "Dockerfile.t-route" - on-failure: - runs-on: self-hosted - if: ${{ github.event.workflow_run.conclusion == 'failure' }} - steps: - - run: echo 'The triggering workflow failed' \ No newline at end of file + tag-name: ${{vars.TAG_NAME}} \ No newline at end of file