-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (153 loc) · 4.98 KB
/
publish-new-build.yml
File metadata and controls
170 lines (153 loc) · 4.98 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Publish new build
run-name: "Publish new images for ${{ github.ref_name }} triggered by ${{ github.actor }}; version: ${{ inputs.version || 'N/A'}}"
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: "Enter the version number"
required: true
default: "latest"
deploy:
description: "Deploy the new version?"
required: false
type: boolean
default: false
environment:
required: false
description: "Select the environment to deploy to"
type: choice
options:
- staging
# TODO: uncomment this when we want to deploy to production
# - production
default: staging
permissions:
contents: write
jobs:
code-check:
uses: ./.github/workflows/code-check.yml
bump-version:
runs-on: ubuntu-latest
needs: code-check
if: ${{ github.ref_name == 'main' && inputs.version != '' }}
outputs:
commit_sha: ${{ steps.commit-version.outputs.commit_sha }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install semver
run: npm install semver
- name: Get current version
run: echo "current_version=$(jq -r '.version' package.json)" >> $GITHUB_ENV
- name: Validate and set new version
run: |
new_version="${{ inputs.version }}"
current_version="${{ env.current_version }}"
if npx semver $new_version -r "<=$current_version"; then
echo "Error: New version ($new_version) is lowest or the same as current ($current_version)"
exit 1
fi
- name: Bump version
run: |
npm version ${{ inputs.version }} --no-git-tag-version
- name: Git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Commit version change
id: commit-version
run: |
git commit -am "Update version to ${{ inputs.version }}"
git push origin main
echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
staging-publish:
uses: ./.github/workflows/build-docker-image.yml
needs:
- code-check
- bump-version
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
with:
environment: production-fidl # staging the same as production
version: ${{ inputs.version }}
commit_sha: ${{ github.ref_name == 'main' && inputs.version != '' && needs.bump-version.outputs.commit_sha || '' }}
secrets: inherit
production-publish:
needs:
- code-check
- bump-version
uses: ./.github/workflows/build-docker-image.yml
if: |
${{ github.ref_name == 'main' && inputs.version != '' }} &&
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
with:
environment: production-fidl
version: ${{ inputs.version }}
commit_sha: ${{ needs.bump-version.outputs.commit_sha }}
secrets: inherit
git-tag:
runs-on: ubuntu-latest
needs:
- bump-version
- production-publish
if: |
${{ github.ref_name == 'main' && inputs.version != '' }} &&
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.commit_sha }}
- name: Create and push tag
run: |
TAG_NAME="v${{ inputs.version }}"
git tag $TAG_NAME
git push origin $TAG_NAME
trigger-staging-deploy:
needs:
- code-check
- bump-version
- git-tag
- staging-publish
uses: ./.github/workflows/put-ssm-version-deploy.yml
if: |
${{ inputs.version != '' && inputs.deploy == true && inputs.environment == 'staging' }} &&
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
with:
version: ${{ inputs.version }}
environment: staging
secrets-environment: staging-fidl
ecr-repository: provider-sample-url-finder-frontend
secrets: inherit
# TODO: uncomment this when we want to deploy to production
# trigger-production-deploy:
# needs:
# - code-check
# - bump-version
# - git-tag
# - production-publish
# uses: ./.github/workflows/trigger-auto-deploy.yml
# if: |
# ${{ inputs.version != '' && inputs.deploy == true && inputs.environment == 'production' }} &&
# always() &&
# !contains(needs.*.result, 'failure') &&
# !contains(needs.*.result, 'cancelled')
# with:
# version: ${{ inputs.version }}
# environment: ${{ inputs.environment }}
# secrets-environment: production-fidl
# ecr-repository: provider-sample-url-finder-frontend
# secrets: inherit