forked from terser/terser
203 lines (165 loc) 路 6.79 KB
/
ci-cd.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
name: CI/CD pipeline
on: [ push, pull_request, workflow_dispatch ]
jobs:
build:
name: "Build ${{ matrix.os }} node${{ matrix.node-version }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
node-version: [ 10.x, 12.x, 14.x, 16.x ]
outputs:
package_version: ${{ steps.proj_ver_determiner.outputs.package_version }}
package_version_tag: ${{ steps.proj_ver_determiner.outputs.package_version_tag }}
latest_github_tag: ${{ steps.proj_ver_determiner.outputs.latest_github_tag }}
should_deploy: ${{ steps.proj_ver_determiner.outputs.should_deploy }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Tooling setup
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
# Information setup
- name: Pipeline data gatherer
id: data_gatherer
shell: sh
run: |
# Get default branch
REPO="${{ github.repository }}"
DEFAULT_BRANCH=`(curl -X GET https://api.github.com/repos/$REPO) | jq '.default_branch'`
echo "::set-output name=default_branch::$(echo $DEFAULT_BRANCH)"
- name: Pipeline conditionals handler
id: conditionals_handler
shell: sh
run: |
DEFAULT_BRANCH="${{ steps.data_gatherer.outputs.default_branch }}"
GITHUB_REF="${{ github.ref }}"
CURRENT_BRANCH=`echo $GITHUB_REF | sed -e "s/^refs\/heads\///"`
GITHUB_EVENT_NAME="${{ github.event_name }}"
IS_DEFAULT_BRANCH='false'
IS_PUSH='false'
IS_PUSH_TO_DEFAULT_BRANCH='false'
if [ $CURRENT_BRANCH == $DEFAULT_BRANCH ]; then
IS_DEFAULT_BRANCH='true'
fi
if [ $GITHUB_EVENT_NAME == 'push' ]; then
IS_PUSH='true'
fi
if [ $CURRENT_BRANCH == $DEFAULT_BRANCH ] && [ $GITHUB_EVENT_NAME == 'push' ]; then
IS_PUSH_TO_DEFAULT_BRANCH='true'
fi
echo "::set-output name=is_default_branch::$(echo $IS_DEFAULT_BRANCH)"
echo "::set-output name=is_push::$(echo $IS_PUSH)"
echo "::set-output name=is_push_to_default_branch::$(echo $IS_PUSH_TO_DEFAULT_BRANCH)"
- if: steps.conditionals_handler.outputs.is_push_to_default_branch == 'true'
name: Project version/deploy determiner
id: proj_ver_determiner
shell: sh
run: |
git fetch --all --tags
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
PACKAGE_VERSION_TAG=`echo v$PACKAGE_VERSION | sed -e 's/[[:space:]]//'`
LATEST_GITHUB_TAG=`echo $(git tag | sort --version-sort | tail -n1)`
SHOULD_DEPLOY="false"
# download semver compare tool
curl https://raw.githubusercontent.com/Ariel-Rodriguez/sh-semversion-2/main/semver2.sh -o semver2.sh
chmod +x semver2.sh
if [ `echo $(./semver2.sh $PACKAGE_VERSION_TAG $LATEST_GITHUB_TAG)` = 1 ]; then
SHOULD_DEPLOY="true"
fi
echo "::set-output name=package_version::$(echo $PACKAGE_VERSION)"
echo "::set-output name=package_version_tag::$(echo $PACKAGE_VERSION_TAG)"
echo "::set-output name=latest_github_tag::$(echo $LATEST_GITHUB_TAG)"
echo "::set-output name=should_deploy::$(echo $SHOULD_DEPLOY)"
# Build and test validation
- name: Create logs directory
shell: sh
run: |
mkdir -p logs
- name: Install dependencies
shell: sh
run: |
npm ci --loglevel verbose 2>&1 | tee logs/install.log
- name: Build the app
shell: sh
run: |
npm run build --if-present --loglevel verbose 2>&1 | tee logs/build.log
env:
TEST_NO_SANDBOX: 1
TERSER_TEST_ALL: 1
- if: matrix.node-version != '10.x'
name: Run compress tests
shell: sh
run: |
npm run test:compress --loglevel verbose 2>&1 | tee logs/compress_test.log
- if: matrix.node-version != '10.x'
name: Run mocha tests
shell: sh
run: |
npm run test:mocha --loglevel verbose 2>&1 | tee logs/mocha_test.log
- if: matrix.node-version == '10.x'
name: Run all tests with Node 10.x
shell: sh
run: |
node --require esm test/compress.js --loglevel verbose 2>&1 | tee logs/compress_test.log
npm run test:mocha -- --require esm --loglevel verbose 2>&1 | tee logs/mocha_test.log
env:
TEST_NO_SANDBOX: 1
- if: matrix.os == 'ubuntu-latest' && matrix.node-version == '12.x'
name: Run functional tests on ${{ matrix.os }} with Node 12.x
run: |
./test/functional.sh 2>&1 | tee logs/functional_tests.log
# Artifact publish to pipeline
- name: Upload logs as artifact
uses: actions/upload-artifact@v2
with:
name: "Logs ${{ matrix.os }} - nodejs ${{ matrix.node-version }}"
path: logs/
deploy:
if: needs.build.outputs.should_deploy == 'true'
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Tooling setup
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
# Package deploy
- name: Deploy to npm
run: |
echo $'registry=https://registry.npmjs.org/\n' //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
npm ci
npm publish --access public
rm -f .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# GitHub deploy
- name: Push GitHub tag
run: |
GITHUB_TAG="${{ needs.build.outputs.package_version_tag }}"
git config --global user.email ${{ secrets.GH_USER_EMAIL }}
git config --global user.name ${{ secrets.GH_USER_NAME }}
git tag $GITHUB_TAG
git push origin --tags
- name: Create and publish release
run: |
RELEASE_TAG="${{ needs.build.outputs.package_version_tag }}"
PREVIOUS_TAG="${{ needs.build.outputs.latest_github_tag }}"
RELEASE_TITLE="$RELEASE_TAG"
START_LINE=$(( $( grep -n "## $RELEASE_TAG" CHANGELOG.md | grep -Eo '^[^:]+' ) + 2 ))
END_LINE=$(( $( grep -n "## $PREVIOUS_TAG" CHANGELOG.md | grep -Eo '^[^:]+' ) - 2 ))
RELEASE_NOTES=$(echo $'### Changelog:\n\n' "$( sed -n "$START_LINE,$END_LINE"p CHANGELOG.md )")
gh release create $RELEASE_TAG --title $RELEASE_TITLE --notes "$RELEASE_NOTES"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}