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
173 lines (160 loc) · 5.78 KB
/
main--lint-unit-build-and-publish-images.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
name: Main QA
on:
# push:
# branches:
# - master
# - main
workflow_dispatch: # Only run manually - not applicable to dluhc workflow
jobs:
calculate-version:
runs-on: ubuntu-latest
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
branches: main
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.7
with:
versionSpec: "5.x"
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9.7
with:
useConfigFile: true
assign-semver:
runs-on: ubuntu-latest
needs: [calculate-version]
env:
SEMVER: ${{ needs.calculate-version.outputs.semVer }}
MAJOR: ${{ needs.calculate-version.outputs.Major }}
outputs:
SEMVER: ${{ steps.calc-semver.outputs.semver }}
steps:
- run: echo $SEMVER
- name: Add 3 to calculated semver
run: |
echo SEMVER="$((3 + MAJOR))${SEMVER:1}" >> $GITHUB_ENV
- name: Set semver to output
id: calc-semver
run: echo "::set-output name=semver::$(echo $SEMVER)"
lint-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
app: [designer, runner, model]
env:
SEMVER: ${{ needs.assign-semver.outputs.SEMVER }}
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-publish-images:
runs-on: ubuntu-latest
needs: [calculate-version, assign-semver, lint-and-test]
env:
SEMVER: ${{ needs.assign-semver.outputs.SEMVER }}
strategy:
matrix:
app: [designer, runner]
name: build-and-publish-${{matrix.app}}-image
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: Docker compose pull
run: docker-compose pull
- name: Docker layer caching DAYOFYEAR key
# DAYOFYEAR key is used to rotate docker-layer-caching daily to avoid the layers dangle issues
# see https://github.com/satackey/action-docker-layer-caching/issues/55
# if you change this, please remember to apply the same changes to branch--lint-unit-and-smoke-test.yml
# so main branch cache can be shared with branches
run: echo "DAYOFYEAR=$(date +%j)" >> $GITHUB_ENV
- name: Create .env for ${{ matrix.app }} workspace
run: |
touch ./${{ matrix.app }}/.env
echo LAST_TAG_GH=${{ env.SEMVER }} >> ./${{ matrix.app }}/.env
echo LAST_COMMIT_GH=${{ github.sha }} >> ./${{ matrix.app }}/.env
cat ./${{ matrix.app }}/.env
- name: Docker compose build ${{ matrix.app }}
run: |
LAST_TAG='${{ env.SEMVER }}'
LAST_COMMIT='${{ github.sha }}'
docker-compose build ${{ matrix.app }}
- name: Check images
run: |
docker image ls
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- name: Tag image
run: |
docker tag digital-form-builder-${{matrix.app}} ghcr.io/xgovformbuilder/digital-form-builder-${{matrix.app}}:latest
docker tag digital-form-builder-${{matrix.app}} ghcr.io/xgovformbuilder/digital-form-builder-${{matrix.app}}:${{ env.SEMVER }}
- name: Push Docker images
run: |
docker push ghcr.io/xgovformbuilder/digital-form-builder-${{matrix.app}}:latest
docker push ghcr.io/xgovformbuilder/digital-form-builder-${{matrix.app}}:${{ env.SEMVER }}
- name: Trigger deploy development environment
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Deploy Development Environment
token: ${{ secrets.GHCR_PAT }}
inputs: '{ "app": "${{ matrix.app }}", "tag": "${{ env.SEMVER }}"}'
tag-branch:
runs-on: ubuntu-latest
needs: [calculate-version, assign-semver, build-and-publish-images]
env:
SEMVER: ${{ needs.assign-semver.outputs.SEMVER }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
token: ${{ secrets.GHCR_PAT }}
- name: Tag branch with run number
run: |
git tag ${{ env.SEMVER }}
git push --tags origin HEAD