generated from remal-github-actions/template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (106 loc) · 3.83 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
name: build
on:
push:
branches:
- main
pull_request: { }
defaults:
run:
shell: bash
jobs:
build:
if: ${{
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
|| (github.event_name == 'push' && !startsWith(github.event.head_commit.message, '[push-back]'))
|| github.event_name != 'push'
}}
name: build
runs-on: ubuntu-latest
timeout-minutes: 15
concurrency: build-${{github.ref}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
lfs: true
fetch-depth: 1
- name: Read action's Node.js version
id: readNodeVersion
run: |
USING=$( yq .runs.using ./action.yml )
if ! [[ "$USING" =~ ^node[0-9]+$ ]]; then
echo "::error::action.yml: .runs.using doesn't start with 'node': '$USING'"
exit 1
fi
VERSION=${USING:4}
echo "Action's Node.js version: $VERSION"
echo "result=$VERSION" >> $GITHUB_OUTPUT
- name: Setup Node.js ${{steps.readNodeVersion.outputs.result}}
uses: actions/setup-node@v4
with:
node-version: '${{steps.readNodeVersion.outputs.result}}'
- name: Update Node.js version in project files
run: |
node update-node-version-in-files "${{steps.readNodeVersion.outputs.result}}"
- name: Restore node_modules cache
id: restore-node_modules-cache
uses: actions/cache/restore@v4
with:
key: ${{runner.os}}-node_modules-${{steps.readNodeVersion.outputs.result}}-${{hashFiles('package.json', '.yarnrc.yml', 'yarn.lock' , '.pnp.*', '.yarn/patches/**', '.yarn/plugins/**', '.yarn/releases/**', '.yarn/versions/**')}}
path: |
node_modules
.yarn/cache
- name: Install dependencies
if: steps.restore-node_modules-cache.outputs.cache-hit != 'true'
run: |
yarn install --no-immutable
- name: Save node_modules cache
if: steps.restore-node_modules-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: ${{runner.os}}-node_modules-${{steps.readNodeVersion.outputs.result}}-${{hashFiles('package.json', '.yarnrc.yml', 'yarn.lock' , '.pnp.*', '.yarn/patches/**', '.yarn/plugins/**', '.yarn/releases/**', '.yarn/versions/**')}}
path: |
node_modules
.yarn/cache
- name: Build
run: |
npm run build
- name: Upload dist to artifacts
if: ${{always()}}
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
if-no-files-found: error
overwrite: true
retention-days: 30
# $$$sync-with-template-modifiable: validation $$$
- name: Run current action
uses: ./
with:
dryRun: 'true'
githubToken: ${{github.token}}
commitMessage: '[push-back] Bump repository activity'
# $$$sync-with-template-modifiable-end$$$
- name: Push back
env:
PUSH_BACK_TOKEN: ${{secrets.PUSH_BACK_TOKEN}}
if: ${{github.event_name == 'push' && startsWith(github.ref, 'refs/heads/') && env.PUSH_BACK_TOKEN}}
uses: remal-github-actions/push-back@v1
with:
githubToken: ${{env.PUSH_BACK_TOKEN}}
message: '[push-back] Push-back updated files during build'
- name: Read version
id: readVersion
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
uses: remal-github-actions/read-nodejs-package-version@v1
- name: Create tag
env:
PUSH_BACK_TOKEN: ${{secrets.PUSH_BACK_TOKEN}}
if: ${{github.event_name == 'push' && github.ref == 'refs/heads/main' && env.PUSH_BACK_TOKEN}}
uses: remal-github-actions/create-tag@v1
with:
githubToken: ${{env.PUSH_BACK_TOKEN}}
tagName: 'v${{steps.readVersion.outputs.majorVersion}}'
forcePush: 'true'