-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (111 loc) · 3.66 KB
/
cd-workflow.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: Auto-publish
on:
release:
# This specifies that the build will be triggered when we publish a release
types: [published]
jobs:
check_version:
name: Check version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: main
- name: Use Node.js 14.16.1
uses: actions/setup-node@v1
with:
node-version: 14.16.1
registry-url: https://registry.npmjs.org/
- name: Version Diff
id: version_diff
run: |
current_version=$(node -pe "require('./package.json').version")
latest_version=$(npm view happy-http@latest version)
[[ "$current_version" != "$latest_version" ]] && changed=true || changed=false
echo "current_version=$current_version" >> $GITHUB_ENV
echo "latest_version=$latest_version" >> $GITHUB_ENV
echo "changed=$changed" >> $GITHUB_ENV
- name: Echo version info
run: |
echo ${{ steps.version_diff.outputs.current_version }}
echo ${{ env.current_version }}
echo ${{ steps.version_diff.outputs.latest_version }}
version_changed=${{ steps.version_diff.outputs.changed }}
echo $version_changed
[ $version_changed == 'true' ] && echo 'New version' || echo 'No version change'
outputs:
version: ${{ env.current_version }}
version_changed: ${{ env.changed }}
build:
name: Build
needs: check_version
if: ${{ needs.check_version.outputs.version_changed == 'true' }}
runs-on: ubuntu-latest
env:
HUSKY: 0
steps:
- uses: actions/checkout@v2
with:
ref: main
- name: Use Node.js 14.16.1
uses: actions/setup-node@v1
with:
node-version: 14.16.1
registry-url: https://registry.npmjs.org/
- name: Cache pnpm modules
uses: actions/cache@v2
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: pnpm/[email protected]
with:
version: 6.0.2
run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
- name: run lint & test & build
run: |
pnpm run lint
pnpm run test
pnpm run build
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{secrets.CODECOV_TOKEN}}
- name: upload artifact
uses: actions/upload-artifact@main
with:
name: artifacts
path: dist/
retention-days: 5
if-no-files-found: error
publish:
needs: build
environment: npm-publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: main
- name: Use Node.js 14.16.1
uses: actions/setup-node@v1
with:
node-version: 14.16.1
- name: download artifact
uses: actions/download-artifact@main
with:
name: artifacts
path: dist
- name: publish to npm
run: |
cd dist
# upgrade npm version in package.json to the tag used in the release.
echo //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN > .npmrc
npm publish --access public
env:
# Use a token to publish to NPM. See below for how to set it up
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}