-
Notifications
You must be signed in to change notification settings - Fork 16
83 lines (74 loc) · 2.88 KB
/
build-and-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Build and publish
run-name: Build and publish ${{ inputs.app_name }}:${{ inputs.ref }}
on:
workflow_call:
inputs:
app_name:
description: "name of application folder under infra directory"
required: true
type: string
ref:
description: The branch, tag or SHA to checkout. When checking out the repository that triggered a workflow, this defaults to the reference or SHA for that event. Otherwise, use branch or tag that triggered the workflow run.
required: true
type: string
outputs:
commit_hash:
description: The SHA that was built
value: ${{ jobs.get-commit-hash.outputs.commit_hash }}
workflow_dispatch:
inputs:
app_name:
description: "name of application folder under infra directory"
required: true
type: string
ref:
description: The branch, tag or SHA to checkout. When checking out the repository that triggered a workflow, this defaults to the reference or SHA for that event. Otherwise, use branch or tag that triggered the workflow run.
required: true
type: string
jobs:
get-commit-hash:
name: Get commit hash
runs-on: ubuntu-22.04
outputs:
commit_hash: ${{ steps.get-commit-hash.outputs.commit_hash }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Get commit hash
id: get-commit-hash
run: |
COMMIT_HASH=$(git rev-parse ${{ inputs.ref }})
echo "Commit hash: $COMMIT_HASH"
echo "commit_hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT"
build-and-publish:
name: Build and publish
runs-on: ubuntu-22.04
needs: get-commit-hash
concurrency: ${{ github.workflow }}-${{ needs.get-commit-hash.outputs.commit_hash }}
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Set up Terraform
uses: ./.github/actions/setup-terraform
- name: Configure AWS credentials
uses: ./.github/actions/configure-aws-credentials
with:
app_name: ${{ inputs.app_name }}
environment: shared
- name: Check if image is already published
id: check-image-published
run: |
is_image_published=$(./bin/is-image-published "${{ inputs.app_name }}" "${{ needs.get-commit-hash.outputs.commit_hash }}")
echo "Is image published: $is_image_published"
echo "is_image_published=$is_image_published" >> "$GITHUB_OUTPUT"
- name: Build release
if: steps.check-image-published.outputs.is_image_published == 'false'
run: make APP_NAME=${{ inputs.app_name }} release-build
- name: Publish release
if: steps.check-image-published.outputs.is_image_published == 'false'
run: make APP_NAME=${{ inputs.app_name }} release-publish