Skip to content

Commit

Permalink
refactor to support to run actions on pr
Browse files Browse the repository at this point in the history
  • Loading branch information
benlee0423 committed Jan 2, 2024
1 parent e49efeb commit c48cd10
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 47 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
12 changes: 7 additions & 5 deletions .github/workflows/docker_deps_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ on:
branches: [ main ]
paths:
- docker/**
pull_request:
branches: [ main ]
paths:
- docker/**
workflow_dispatch:
workflow_call:
inputs:
tag_name:
required: true
type: string

jobs:
build-and-push:
Expand All @@ -25,4 +26,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: ${{inputs.tag_name}}
76 changes: 57 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,39 @@ on:
branches: [ main ]
paths:
- docker/**
workflow_run:
workflows: [Build and push ngen image]
types:
- completed
pull_request:
branches: [ main ]
inputs:
tag_name:
description: 'Tag Name'
required: false
default: 'latest'
type: string
workflow_dispatch:

inputs:
tag_name:
description: 'Tag Name'
required: false
default: 'latest'
type: string

jobs:
on-success:
deps:
uses: ./.github/workflows/docker_deps_image.yml
with:
tag_name: ${{inputs.tag_name}}
troute:
needs: deps
uses: ./.github/workflows/docker_troute_image.yml
with:
tag_name: ${{inputs.tag_name}}
ngen:
needs: troute
uses: ./.github/workflows/docker_ngen_image.yml
with:
tag_name: ${{inputs.tag_name}}
final:
runs-on: self-hosted
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: deploy
uses: actions/checkout@v2
Expand All @@ -24,24 +47,39 @@ 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:
check_result:
needs: ngen
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 }}
18 changes: 7 additions & 11 deletions .github/workflows/docker_ngen_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ on:
branches: [ main ]
paths:
- docker/**
workflow_run:
workflows: [Build and push t-route image]
types:
- completed
workflow_dispatch:
workflow_call:
inputs:
tag_name:
required: true
type: string

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 +24,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: ${{inputs.tag_name}}
18 changes: 7 additions & 11 deletions .github/workflows/docker_troute_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ on:
branches: [ main ]
paths:
- docker/**
workflow_run:
workflows: [Build and push deps image]
types:
- completed
workflow_dispatch:
workflow_call:
inputs:
tag_name:
required: true
type: string

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 +24,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: ${{inputs.tag_name}}

0 comments on commit c48cd10

Please sign in to comment.