-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (161 loc) · 8 KB
/
build.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
# This is a basic workflow to help you get started with Actions
name: BUILD
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [develop, release/**, rc/**, release]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
install_deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '2'
- name: Cache node modules
id: cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '20'
- name: NPM install
if: steps.cache.outputs.cache-hit != 'true'
run: npm install --force
- name: Get short hash
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Extract branch name
id: branch_name
shell: bash
run: echo "name=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_OUTPUT
- name: Extract build configuration
shell: bash
id: build_ext
run: |
if [[ ${{ steps.branch_name.outputs.name }} == "release" ]] || [[ ${{ steps.branch_name.outputs.name }} == "release"* ]] || [[ ${{ steps.branch_name.outputs.name }} == "main" ]]
then
echo "configuration=production" >> $GITHUB_OUTPUT
echo "deploy_branch=prod" >> $GITHUB_OUTPUT
elif [[ ${{ steps.branch_name.outputs.name }} == "rc"* ]]
then
echo "configuration=staging" >> $GITHUB_OUTPUT
echo "deploy_branch=uat" >> $GITHUB_OUTPUT
else
echo "configuration=staging" >> $GITHUB_OUTPUT
echo "deploy_branch=dev" >> $GITHUB_OUTPUT
fi
- name: List affected applications
id: affected_apps
run: |
echo "affected_apps=$(node ./tools/get-affected.js ${{ github.ref }})" >> $GITHUB_OUTPUT
echo "affected_units=$(node ./tools/get-affected.js ${{ github.ref }} test)" >> $GITHUB_OUTPUT
- name: Print affected applications
run: |
echo ${{ steps.affected_apps.outputs.affected_apps }}
outputs:
affected_apps: ${{ steps.affected_apps.outputs.affected_apps }}
affected_units: ${{ steps.affected_apps.outputs.affected_units }}
configuration: ${{ steps.build_ext.outputs.configuration }}
deploy_branch: ${{ steps.build_ext.outputs.deploy_branch }}
short_sha: ${{ steps.vars.outputs.short_sha }}
test:
runs-on: ubuntu-latest
needs: install_deps
if: ${{ fromJSON(needs.install_deps.outputs.affected_units)[0] != null }}
strategy:
matrix:
package: ${{ fromJSON(needs.install_deps.outputs.affected_units) }}
steps:
- uses: actions/checkout@v4
- name: Cache node modules
id: cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Cache nx build cache
id: cache-nx
uses: actions/cache@v4
with:
path: node_modules/.cache/nx
key: ${{ runner.os }}-nx-${{matrix.package}}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-nx-${{matrix.package}}-
${{ runner.os }}-nx-
- name: Setup version
run: npm run postinstall
- name: Test affected code units
run: |
npx nx test ${{ matrix.package }} --runInBand
build:
runs-on: ubuntu-latest
needs: install_deps
if: ${{ fromJSON(needs.install_deps.outputs.affected_apps)[0] != null }}
strategy:
matrix:
package: ${{ fromJSON(needs.install_deps.outputs.affected_apps) }}
env:
configuration: ${{ needs.install_deps.outputs.configuration }}
deploy_branch: ${{ needs.install_deps.outputs.deploy_branch }}
short_sha: ${{ needs.install_deps.outputs.short_sha }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v4
- name: Cache node modules
id: cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Cache nx build cache
id: cache-nx
uses: actions/cache@v4
with:
path: node_modules/.cache/nx
key: ${{ runner.os }}-nx-${{matrix.package}}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-nx-${{matrix.package}}-
${{ runner.os }}-nx-
- name: Setup version
run: npm run postinstall
- name: Initialise Pipeline Chat Status
uses: fjogeleit/http-request-action@master
continue-on-error: true
with:
url: ${{ secrets.STATUS_URL }}
data: '{ "chat_url": "${{ secrets.CHAT_URL }}", "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "${{ matrix.package }}", "branch": "${{ github.ref }}", "status": "processing", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'
- name: Build affected applications
run: |
npx nx build ${{ matrix.package }} --verbose --configuration=${{ env.configuration }}
- name: Deploy the application(${{ matrix.package }})
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: build/${{ env.deploy_branch }} # The branch name where you want to push the assets
FOLDER: dist/apps/${{ matrix.package }}/browser # The directory where your assets are generated
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub will automatically add this - you don't need to bother getting a token
MESSAGE: 'build(${{ matrix.package }}): CI build from {sha}' # The commit message
- name: Update Pipeline Chat Status
uses: fjogeleit/http-request-action@master
continue-on-error: true
with:
url: ${{ secrets.STATUS_URL }}
data: '{ "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "${{ matrix.package }}", "branch": "${{ github.ref }}", "status": "${{ job.status }}", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'
if: ${{ always() }}