forked from bitpay/insight
-
Notifications
You must be signed in to change notification settings - Fork 67
171 lines (144 loc) · 4.84 KB
/
test_and_release.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
name: Test and Release
on:
workflow_dispatch:
release:
types:
- published
pull_request:
branches:
- master
- v[0-9]+.[0-9]+-dev
jobs:
test:
name: Run Insight UI tests
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '20'
- name: Enable NPM cache
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Check NPM package lock version is updated
uses: dashevo/gh-action-check-package-lock@v1
- name: Install NPM dependencies
run: npm ci
- name: Run ESLinter
run: npm run lint
- name: Use https instead of git protocol fo git
run: git config --global url."https://".insteadOf git://
- name: Build project
run: npm run build
- name: Run tests
run: npm run test
release-npm:
name: Release NPM package
runs-on: ubuntu-20.04
needs: test
if: ${{ github.event_name == 'release' }}
steps:
- uses: actions/checkout@v2
- name: Check package version matches tag
uses: geritol/[email protected]
env:
TAG_PREFIX: refs/tags/v
- name: Enable NPM cache
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install NPM dependencies
run: npm ci
- name: Set release tag
uses: actions/github-script@v3
id: tag
with:
result-encoding: string
script: |
const tag = context.payload.release.tag_name;
const [, major, minor] = tag.match(/^v([0-9]+)\.([0-9]+)/);
return (tag.includes('dev') ? `${major}.${minor}-dev` : 'latest');
- name: Use https instead of git protocol fo git
run: git config --global url."https://".insteadOf git://
- name: Publish NPM package
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
tag: ${{ steps.tag.outputs.result }}
release-docker:
name: Release Docker image
runs-on: ubuntu-20.04
needs: release-npm
if: ${{ github.event_name == 'release' }}
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v1
with:
version: v0.7.0
install: true
driver-opts: image=moby/buildkit:buildx-stable-1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set suffix to Docker tags
uses: actions/github-script@v3
id: suffix
with:
result-encoding: string
script: "return (context.payload.release.tag_name.includes('-dev') ? '-dev' : '');"
- name: Set release tag
uses: actions/github-script@v3
id: tag
with:
result-encoding: string
script: |
const tag = context.payload.release.tag_name;
const [, major] = tag.match(/^v([0-9]+)/);
return major;
- name: Set Docker tags and labels
id: docker_meta
uses: docker/metadata-action@v3
with:
images: dashpay/insight
tags: |
type=match,pattern=v(\d+),group=1
type=match,pattern=v(\d+.\d+),group=1
type=match,pattern=v(\d+.\d+.\d+),group=1
type=match,pattern=v(.*),group=1,suffix=,enable=${{ contains(github.event.release.tag_name, '-dev') }}
flavor: |
latest=${{ !contains(github.event.release.tag_name, '-dev') }}
suffix=${{ steps.suffix.outputs.result }}
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: docker
file: docker/Dockerfile
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ github.event.release.tag_name }}
MAJOR_VERSION=${{ steps.tag.outputs.result }}
- name: Output Docker image digest
run: echo ${{ steps.docker_build.outputs.digest }}