-
Notifications
You must be signed in to change notification settings - Fork 120
179 lines (166 loc) · 5.36 KB
/
ci.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
name: Continuous Integration
on:
push:
branches: [master]
pull_request:
branches: [master]
release:
types:
- published
jobs:
prerequisites:
name: Prerequisites
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: "16"
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: npm ci
run: npm ci
- name: npm audit
run: npm audit --production
- name: npm run lint
run: npm run lint
- name: npm run docs
run: npm run docs
test:
name: Test ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v1
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: "16"
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: test
run: |
npm ci
npm run test
- name: codecov.io
if: contains(runner.os, 'Linux')
uses: codecov/codecov-action@v1
with:
file: coverage/lcov.info
verbose: true
build:
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v1
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: "16"
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: prepare build
run: |
npm ci
npm run build
- name: build linux
if: contains(runner.os, 'Linux')
run: |
node ./build.js -o linux -p deb -a x64
node ./build.js -o linux -p AppImage -a x64
- name: build macOS
if: contains(runner.os, 'macOS')
run: |
node ./build.js -o darwin -p dmg -a x64
- name: build windows
if: contains(runner.os, 'Windows')
run: |
node ./build.js -o win32 -p portable -a x64
- name: archive artifacts
uses: actions/upload-artifact@v2
with:
name: ubports-installer
path: |
dist/*.deb
dist/*.AppImage
dist/*.dmg
dist/*.exe
- name: upload release assets
if: github.event_name == 'release'
uses: actions/github-script@v2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const { repo: { owner, repo }} = context;
const tag = context.ref.replace("refs/tags/", "");
console.log("trying to upload to", owner, repo, tag);
const crypto = require('crypto');
const sha256sum = path => new Promise((resolve, reject) => {
const hash = crypto.createHash('sha256');
const stream = fs.createReadStream(path);
stream.on('error', reject);
stream.on('data', chunk => hash.update(chunk));
stream.on('end', () => resolve(hash.digest('hex')));
});
github.repos.getReleaseByTag({ owner, repo, tag })
.then(({data: {id: release_id}}) =>
Promise.all(
fs.readdirSync('./dist/').filter(f =>
f.match(/ubports-installer_*.*/) &&
!f.includes("snap") &&
!f.includes("blockmap")
)
.map(file =>
github.repos.uploadReleaseAsset({
owner, repo, release_id,
name: file,
data: fs.readFileSync(`./dist/${file}`)
})
.then(() => console.log("uploaded", file))
.then(() => sha256sum(`./dist/${file}`))
.then(data =>
github.repos.uploadReleaseAsset({
owner, repo, release_id, data,
name: `${file}.sha256`
})
)
.then(() => console.log("uploaded checksum for", file))
)
)
)