-
-
Notifications
You must be signed in to change notification settings - Fork 6
129 lines (112 loc) · 3.92 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
name: Build IITC Button
# read-only repo token
# no access to secrets
on:
push:
branches:
- master
tags:
- '*'
pull_request:
paths-ignore:
- '!.github/**'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- build_script: build_mv2
- build_script: build_mv3_firefox
- build_script: build_mv3_chrome
- build_script: build_mv3_safari
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Linter
run: npm run lint
- name: Set BETA environment variables
if: startsWith(github.ref, 'refs/tags/v') != true
run: |
echo "BETA=true" >> $GITHUB_ENV
echo "GIT_REV_COUNT=`git rev-list --all --count`" >> $GITHUB_ENV
- name: Build
run: npm run ${{ matrix.build_script }}
- name: Get version from package.json
if: startsWith(github.ref, 'refs/tags/v')
uses: polyseam/[email protected]
id: get-version-key-from-json
with:
path-to-json: './package.json'
- name: Save metadata
run: |
mkdir -p ./build/.metadata
ORIGINAL_FILE_NAME=$(ls artifacts/*.zip)
FILE_NAME="${ORIGINAL_FILE_NAME##*/}"
FILE_NAME="${FILE_NAME%.zip}"
if [ "$GITHUB_EVENT_NAME" = "push" ]; then
if [[ "$GITHUB_REF" =~ ^refs/tags/ ]]; then
# Release build
echo "release" > ./build/.metadata/build_type
else
# Beta build from master branch
FILE_NAME="${FILE_NAME}-$(echo ${{ github.sha }} | cut -c 1-6)"
echo "beta" > ./build/.metadata/build_type
fi
echo ${{ github.sha }} > ./build/.metadata/commit
elif [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
# Build artifacts for PR
FILE_NAME="${FILE_NAME}-$(echo ${{ github.event.pull_request.head.sha }} | cut -c 1-6)"
echo "PR" > ./build/.metadata/build_type
echo ${{ github.event.pull_request.head.sha }} > ./build/.metadata/commit
echo ${{ github.event.number }} > ./build/.metadata/pr_number
fi
mv $ORIGINAL_FILE_NAME "./build/$FILE_NAME".zip
echo "GITHUB_SHA_SHORT=$(cat ./build/.metadata/commit | cut -c 1-6)" >> $GITHUB_ENV
echo "FILE_NAME=$FILE_NAME" >> $GITHUB_ENV
- uses: ncipollo/release-action@v1
if: startsWith(github.ref, 'refs/tags/v')
env:
FILE_PATH: ./build/${{ env.FILE_NAME }}.zip
with:
allowUpdates: true
artifactErrorsFailBuild: true
artifacts: ${{ env.FILE_PATH }}
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v4
with:
name: ${{ env.FILE_NAME }}
path: |
./build/
collect:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: collected_artifacts
- name: Move artifacts to final directory
run: |
mkdir -p final_artifacts
echo "Moving contents from artifact directories to final_artifacts directory:"
for dir in collected_artifacts/*; do
if [ -d "$dir" ]; then
cp -rf "$dir"/* "$dir"/.metadata final_artifacts/
fi
done
echo "Contents of final_artifacts directory:"
ls -la final_artifacts/
- name: Get metadata
run: echo "GITHUB_SHA_SHORT=$(cat ./final_artifacts/.metadata/commit | cut -c 1-6)" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
with:
name: iitc-button-${{ env.GITHUB_SHA_SHORT }}-artifacts
path: final_artifacts/*