This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
forked from XGovFormBuilder/digital-form-builder
-
Notifications
You must be signed in to change notification settings - Fork 1
186 lines (160 loc) · 5.26 KB
/
dluhc-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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: DLUHC Build and Publish
permissions:
packages: write
contents: write
on:
workflow_dispatch:
push:
paths-ignore:
[
"**/README.md",
"fsd_config/**",
".github/workflows/dluhc-build-and-deploy-with-forms.yml",
".github/workflows/increment-version.yml",
"version",
]
env:
IMAGE_NAME_STUB: "digital-form-builder-dluhc-"
DOCKER_REGISTRY: ghcr.io
IMAGE_REPO_PATH: "ghcr.io/${{github.repository_owner}}"
jobs:
check-tag-before-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Set version in env"
id: set-version
run: |
source version
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Check if tag exists
uses: mukunku/tag-exists-action@v1.0.0
id: check_tag
with:
tag: ${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail job if tag exists
if: ${{ steps.check_tag.outputs.exists == 'true' }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Tag already exists. Increment version file and retry')
lint-and-test:
needs: check-tag-before-build
runs-on: ubuntu-latest
strategy:
matrix:
app: [designer, runner, model]
name: lint-and-test-${{matrix.app}}
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- name: Configure yarn caching
uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install
- name: Build dependencies
run: yarn build:dependencies
- name: Lint
run: yarn ${{matrix.app}} lint
- name: Test
run: yarn ${{matrix.app}} test-cov
- name: Upload test results artifacts
uses: actions/upload-artifact@v2
if: ${{ success() || failure() }}
with:
name: test-results-${{matrix.app}}
path: ${{matrix.app}}/test-results
retention-days: 14
- name: Upload test coverage artifacts
uses: actions/upload-artifact@v2
if: ${{ success() || failure() }}
with:
name: test-coverage-${{matrix.app}}
path: ${{matrix.app}}/test-coverage
retention-days: 14
build-and-push-images:
needs: [lint-and-test]
runs-on: ubuntu-latest
strategy:
matrix:
app: [designer, runner]
name: build-and-push-${{matrix.app}}-image
steps:
- uses: actions/checkout@v2
- name: "Set version in env"
id: set-version
run: |
source version
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: Docker compose pull
run: docker-compose pull
- name: Create .env for ${{ matrix.app }} workspace
run: |
touch ./${{ matrix.app }}/.env
echo LAST_TAG_GH=${{env.VERSION}} >> ./${{ matrix.app }}/.env
echo LAST_COMMIT_GH=${{ github.sha }} >> ./${{ matrix.app }}/.env
cat ./${{ matrix.app }}/.env
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: ${{env.IMAGE_REPO_PATH}}/${{env.IMAGE_NAME_STUB}}${{ matrix.app }}
tags: |
type=sha,format=long
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{env.VERSION}},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=ref,event=branch
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker image
uses: docker/build-push-action@v3
with:
context: "{{defaultContext}}"
tags: ${{ steps.metadata.outputs.tags}}
labels: ${{ steps.metadata.outputs.labels }}
push: true
file: ${{matrix.app}}/Dockerfile
build-args: |
LAST_TAG='${{env.VERSION}}'
LAST_COMMIT='${{ github.sha }}'
tag-repo:
name: Tag repo (if main)
runs-on: ubuntu-latest
needs: [build-and-push-images]
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Set version in env"
id: set-version
run: |
source version
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Tag repo with version
run: |
git tag ${{env.VERSION}}
git push --tags origin HEAD