forked from cobrinhas/github-bookmark
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (76 loc) · 2.7 KB
/
publish-github.yaml
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
name: Publish to GitHub
on:
push:
branches:
- 'master'
jobs:
publish:
runs-on: ubuntu-latest
env:
release-asset-name: dist.zip
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up npm
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'npm'
- name: Install npm
run: npm install --frozen-lockfile
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
publish: bash scripts/release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build project
if: steps.changesets.outputs.published == 'true'
id: build-project
run: npm run build
- name: Zip dist folder
id: zip-folder
if: steps.build-project.outcome == 'success'
uses: vimtor/action-zip@v1
with:
files: dist
dest: ${{ env.release-asset-name }}
- name: Upload Release Asset
if: steps.zip-folder.outcome == 'success'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
async function getReleaseId() {
try {
const response = await github.rest.repos.getLatestRelease({
owner: '${{ github.repository_owner }}',
repo: '${{ github.event.repository.name }}'
});
console.log(`Id of the latest release is ${response.data.id} was found.`);
return response.data.id
} catch (error) {
console.error('Failed to get Id of the latest release', error);
throw error;
}
}
async function uploadReleaseAsset(release_id) {
try {
const response = await github.rest.repos.uploadReleaseAsset({
owner: '${{ github.repository_owner }}',
repo: '${{ github.event.repository.name }}',
release_id: release_id,
name: '${{ env.release-asset-name }}',
data: await fs.readFileSync('${{ github.workspace }}/${{ env.release-asset-name }}')
});
console.log(`Uploaded asset to release ${release_id}.`);
} catch (error) {
console.error(`Failed to upload asset to release ${release_id}`, error);
throw error;
}
}
let release_id = await getReleaseId();
console.log(`Release id: ${release_id}`)
await uploadReleaseAsset(release_id);