-
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (121 loc) · 4.2 KB
/
draft_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
name: Release Version
on:
pull_request:
branches:
- main
types:
- opened
- closed
- synchronize
permissions:
contents: write
pull-requests: write
jobs:
prepare-release-assets:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.draft_release.outputs.upload_url }}
release_id: ${{ steps.draft_release.outputs.release_id }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '21'
- name: Install dependencies
run: cd src && yarn
- name: Extract tag name
id: extract_tag
run: |
echo "VERSION=${{ github.event.pull_request.title }}" >> $GITHUB_ENV
echo GOOGLE_ANALYTICS_API_SECRET=${{ secrets.GOOGLE_ANALYTICS_API_SECRET }} >> .env
- name: Build and zip the extension
run: |
mkdir dist
cd src
yarn run build-css
yarn run dist
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
VERSION: ${{ env.VERSION }}
SENTRY_RELEASE: "shortcut-assistant@${{ env.VERSION }}"
- name: Upload dist.zip as an artifact
uses: actions/upload-artifact@v3
with:
name: dist-zip
path: dist/dist.zip
- name: Create or update draft release
id: draft_release
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
const pr = context.payload.pull_request;
const releaseTag = pr.title;
const releaseNotes = pr.body;
const releases = await github.rest.repos.listReleases({
owner,
repo,
});
let draftRelease = releases.data.find(release => release.tag_name === releaseTag && release.draft === true);
if (!draftRelease) {
console.log(`Creating draft release`);
draftRelease = await github.rest.repos.createRelease({
owner,
repo,
tag_name: releaseTag,
name: releaseTag,
body: releaseNotes,
draft: true,
});
console.log(`Draft release created`);
}
console.log(draftRelease)
core.setOutput("upload_url", draftRelease.upload_url);
core.setOutput("release_id", draftRelease.id);
upload-release-asset:
needs: prepare-release-assets
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Download dist.zip artifact
uses: actions/[email protected]
with:
name: dist-zip
path: dist
- name: Upload release asset
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
const pr = context.payload.pull_request;
const releases = await github.rest.repos.listReleases({
owner,
repo,
});
const releaseTag = pr.title;
let draftRelease = releases.data.find(release => release.tag_name === releaseTag && release.draft === true);
const releaseId = draftRelease.id;
const assetPath = './dist/dist.zip';
const assetName = 'ChromeExtension.zip';
const assetContentType = 'application/zip';
const data = require('fs').readFileSync(assetPath);
console.log(`Uploading asset ${assetPath} to release ${releaseId}`);
console.log(`Release published: https://github.com/${owner}/${repo}/releases/tag/${releaseId}`);
release = await github.rest.repos.updateRelease({
owner,
repo,
release_id: releaseId,
draft: false,
});
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: releaseId,
name: assetName,
data,
});
console.log('Asset uploaded');