This repository has been archived by the owner on Jan 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
76 lines (70 loc) · 3.13 KB
/
create_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
name: Create Release on PR Trigger
on:
pull_request:
types: [closed]
jobs:
create_release:
name: Windows Release
runs-on: windows-latest
env:
IMJS_ELECTRON_CLIENT_ID: imodeljs-electron-samples
if: ${{ startsWith(github.event.pull_request.title, '[Bump Version] ') && github.event.pull_request.merged }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: |
git config --global user.email "[email protected]"
git config --global user.name "imodeljs-admin[bot]"
name: git config
- run: npm ci
- run: npx run-s lint build build:backend:webpack
- run: ([Regex]'REPLACE_WITH_CLIENT_ID').Replace((Get-Content -path ./build/app/main.js -Raw), ${env:IMJS_ELECTRON_CLIENT_ID}, 1) | Set-Content -Path ./build/app/main.js
shell: powershell
name: set client id
- run: npm run build:dist
- uses: actions/github-script@v2
name: create release
with:
script: |
const prKeyword = '[Bump Version] ';
const newVersion = context.payload.pull_request.title.slice(prKeyword.length);
console.log(`Attempting a release for version '${newVersion}' (PR title='${context.payload.pull_request.title}')`);
const fs = require('fs');
const proc = require('child_process');
const git = (args) => { console.log(`$ git ${args}`); proc.spawnSync('git', args, { stdio: 'inherit' }); };
const runWithOpts = async (funcName, opts) => {
console.log(`${funcName} opts: ${JSON.stringify(opts)}`);
const res = await eval(funcName)(opts);
console.log(`${funcName} response: ${JSON.stringify(res)}`);
return res;
};
git(['tag', '-a', newVersion, '-m', newVersion]);
git(['push', 'origin', newVersion]);
const release = await runWithOpts('github.repos.createRelease', {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: newVersion,
name: newVersion,
draft: true
});
const plainVersion = newVersion.slice(1); // remove the leading 'v'
const artifactName = `Desktop Starter-${plainVersion}-win.zip`;
const artifactPath = `./dist/${artifactName}`;
await runWithOpts('github.repos.uploadReleaseAsset', {
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: artifactName,
headers: {
'content-length': fs.statSync(artifactPath).size
},
data: fs.createReadStream(artifactPath)
});
await runWithOpts('github.repos.updateRelease', {
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
draft: false
});