Skip to content

Commit

Permalink
Run actions when PR is created and updated. (#74)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
benlee0423 authored Jan 4, 2024
1 parent e49efeb commit 6eaacbb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 48 deletions.
5 changes: 4 additions & 1 deletion .github/action_templates/build-and-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/docker_deps_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
dockerfile-name: "Dockerfile.ngen-deps"
tag-name: ${{vars.TAG_NAME}}
63 changes: 44 additions & 19 deletions .github/workflows/docker_image_main_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
14 changes: 3 additions & 11 deletions .github/workflows/docker_ngen_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
tag-name: ${{vars.TAG_NAME}}
14 changes: 3 additions & 11 deletions .github/workflows/docker_troute_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
tag-name: ${{vars.TAG_NAME}}

0 comments on commit 6eaacbb

Please sign in to comment.