-
-
Notifications
You must be signed in to change notification settings - Fork 91
253 lines (221 loc) · 10.1 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
name: '[👷] Build Project'
run-name: '[👷] Build Project on `${{ inputs.ref }}`'
on:
workflow_call:
inputs:
ref:
description: 'The ref to build on'
required: false
type: string
default: github.ref
label:
description: 'A label for branch chooser'
required: false
type: string
default: ${{ inputs.ref }}
outputs:
branch:
description: 'The branch to build on and deploy to'
value: ${{ jobs.build.outputs.branch }}
version:
description: 'Version of build'
value: ${{ jobs.build.outputs.version }}
jobs:
build:
runs-on: ubuntu-latest
name: '[👷] Build'
outputs:
branch: ${{ steps.output.outputs.branch }}
version: ${{ steps.output.outputs.version }}
env:
BranchLabel: ${{ inputs.label || github.ref }}
steps:
# - name: Generate Token
# id: generate_token
# uses: tibdex/github-app-token@v1
# with:
# app_id: ${{ secrets.APP_ID }}
# private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: '[📥] checkout'
id: checkout
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.SSH_DEPLOY_KEY }}
ref: ${{ inputs.ref }}
fetch-depth: 0
# token: ${{ steps.generate_token.outputs.token }}
- name: '[🔎] get Node and yarn versions'
id: get_node_yarn_versions
run: |
echo "NODE_VERSION=$(grep '"node":' ./package.json | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed 's/\^v//g' | tr -d '[:space:]')" >> $GITHUB_ENV
echo "YARN_VERSION=$(grep '"packageManager":' ./package.json | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed 's/yarn@//g' | tr -d '[:space:]')" >> $GITHUB_ENV
- name: '[⬆] setup Node.js'
id: node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: '[⬆] setup yarn'
id: yarn_setup
run: |
corepack enable
yarn set version "${{ env.YARN_VERSION }}"
- name: '[🔗] symlink yarn executable'
id: yarn_symlink
run: |
ln -sf "$(find ./.yarn/releases/ -name 'yarn-*.cjs')" ./yarn
- name: '[ℹ] print versions (node, yarn, git)'
id: versions
run: |
echo "node: $(node -v) – yarn: $(yarn -v) – git: $(git --version)"
- name: '[🔎] get yarn cache directory'
id: yarn_cache_dir
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: '[💽] restore cache'
if: github.ref != 'refs/heads/master'
uses: actions/cache@v4
id: yarn_cache
with:
path: |
${{ steps.yarn_cache_dir.outputs.dir }}
**/node_modules
**/.eslintcache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: '[🍱] yarn install'
id: yarn_install
run: yarn install --immutable
- name: '[⬆] update browserslist'
id: browserslist
run: npx -y update-browserslist-db
- name: '[🌳] set env variables'
id: env
run: |
echo "MODE=$(if ${{ inputs.ref == 'refs/heads/master' }}; then echo "production"; else echo "development"; fi)" >> $GITHUB_ENV
echo "TYPE=$(if ${{ inputs.ref == 'refs/heads/master' }}; then echo "stable"; else echo "beta"; fi)" >> $GITHUB_ENV
# ===BEGIN $BRANCH===
ref="${{ inputs.ref }}"
BRANCH="dummy"
if [[ $ref == "refs/heads/master" ]]; then
BRANCH="stable"
elif [[ $ref == "refs/heads/dev" ]]; then
BRANCH="beta";
elif [[ $ref == "refs/heads/"* ]]; then
BRANCH="${ref/"refs/heads/"/}";
BRANCH="${BRANCH/"/"/"-"}"
elif [[ $ref == "refs/pull/"* ]]; then
BRANCH="${ref/"refs/pull/"/"pr"}";
BRANCH="${BRANCH/"/merge"/}";
BRANCH="${BRANCH//"/"/"-"}"
fi
# ===END $BRANCH===
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: '[⬆] update emojis'
id: update_emojis
run: yarn ts-node scripts/utils/fetchEmojis.ts
- name: '[🎨] format files not covered by ESLint'
id: format
run: yarn ts-node scripts/format.ts || exit 1
- name: '[🚨] run ESLint'
id: eslint
run: |
yarn eslint \
./docs/.vuepress/ \
./static/ \
./prebuild/ \
./build/ \
./src/ \
./scripts/ \
./typings/ \
--ext .js,.ts,.vue,.md \
--no-error-on-unmatched-pattern \
--exit-on-fatal-error \
--report-unused-disable-directives \
--cache --cache-strategy content \
--fix \
|| exit 1
- name: '[🚨] check TypeScript'
id: tsc
run: yarn tsc -b --pretty "./" || exit 1
- name: '[📜] build userscript'
id: userscript
run: |
yarn tsc --pretty --project "src/tsconfig.userscript.json" || exit 1
yarn ts-node scripts/buildUserscript.ts || exit 1
- name: '[📜] build buildscript'
id: buildscript
run: yarn ts-node scripts/createBuildScript.ts || exit 1
- name: '[🚧] run prebuild'
id: prebuild
run: yarn ts-node prebuild/index.ts "${{ env.MODE }}" "${{ env.BRANCH }}" "$BranchLabel" || exit 1
- name: '[👷] webpack'
id: webpack
run: yarn ts-node build/index.ts --esModuleInterop "${{ env.MODE }}" "${{ env.BRANCH }}" "$BranchLabel" || exit 1
- name: '[📝] build docs'
id: docs
run: |
"$(yarn workspace lss-manager-v4-docs bin vuepress)" build docs || exit 1
mkdir -p ./dist/docs
rm -rdf ./dist/docs/*
cp -r ./docs/.vuepress/dist/* ./dist/docs
env:
GITHUB_TOKEN: ${{ github.token }}
- name: '[ℹ️] git diff'
id: git_diff
run: git --no-pager diff --color-words
- name: '[💬] set output'
id: output
run: |
echo "branch=${{ env.BRANCH }}" >> $GITHUB_OUTPUT
VERSION=$(grep '"version":' ./package.json | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[:space:]')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "CHANGED_FILES=$(git status -s | wc -l)" >> $GITHUB_ENV
- name: '[📦] zip files'
id: zip
run: |
sudo apt-get install zip
zip -r dist.zip dist
- name: '[☁️] upload artifact'
id: artifact
if: ${{ success() || failure() }}
uses: actions/upload-artifact@v4
with:
name: LSSM_V4-${{ github.sha }}
path: dist.zip
if-no-files-found: error
retention-days: 1
- name: Prepare Git Push (add ssh-key etc.)
id: git_prepare
if: ${{ success() && github.repository_owner == 'LSS-Manager' && (inputs.ref == 'refs/heads/master' || (inputs.ref == 'refs/heads/dev' && env.CHANGED_FILES > 1)) }}
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p /home/runner/.ssh
echo "${{ secrets.SSH_DEPLOY_KEY }}" > /home/runner/.ssh/github_actions
chmod 600 /home/runner/.ssh/github_actions
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add /home/runner/.ssh/github_actions
git remote set-url origin [email protected]:LSS-Manager/LSSM-V.4.git
- name: Import GPG key
id: import_gpg
if: ${{ success() && github.repository_owner == 'LSS-Manager' && (inputs.ref == 'refs/heads/master' || (inputs.ref == 'refs/heads/dev' && env.CHANGED_FILES > 1)) }}
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: '[📤] push to git'
id: git_push
if: ${{ success() && github.repository_owner == 'LSS-Manager' && (inputs.ref == 'refs/heads/master' || (inputs.ref == 'refs/heads/dev' && env.CHANGED_FILES > 1)) }}
uses: stefanzweifel/git-auto-commit-action@v5
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
with:
commit_user_name: ${{ secrets.GIT_USERNAME }}
commit_user_email: ${{ secrets.GIT_EMAIL }}
commit_author: Build Server <[email protected]>
commit_message: '📦 Version ${{ env.VERSION }} [skip ci]'
commit_options: '-S'
push_options: '--force'