-
Notifications
You must be signed in to change notification settings - Fork 17
159 lines (131 loc) · 4.52 KB
/
build-release.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
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
on:
push:
branches:
- main
paths:
- "CHANGELOG.md"
workflow_dispatch:
jobs:
check-version-change:
outputs:
changed: ${{ steps.check-version.outputs.result }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Check if version has changed
id: check-version
uses: actions/github-script@v7
with:
script: |
const version = '${{ github.event.inputs.version }}' || require('./package.json').version;
// Find a release for that version
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: `v${version}`,
}).catch(() => null);
// If the release exists, the version has not changed
if (release) {
console.log(`Version ${version} has an existing release`);
console.log(release.data.html_url);
core.summary.addLink(`Release v${version}`, release.data.html_url);
await core.summary.write();
return "false";
}
console.log(`Version ${version} does not have a release`);
return true;
release:
needs: check-version-change
if: ${{ needs.check-version-change.outputs.changed == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
packages: read
env:
EXT_VERSION: "" # will be set in the workflow
outputs:
version: ${{ env.EXT_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: npm
- name: Install Node.js dependencies
run: npm ci
- name: Build
run: npm run compile
- name: Package
run: npm run package
- name: Parse version from package.json
run: |
echo "EXT_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
with:
name: templ-${{ env.EXT_VERSION }}.vsix
path: ./templ-${{ env.EXT_VERSION }}.vsix
- name: Create release and upload release asset
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "v${{ env.EXT_VERSION }}",
name: "v${{ env.EXT_VERSION }}",
draft: false,
prerelease: false,
generate_release_notes: true
});
const path = "./templ-${{ env.EXT_VERSION }}.vsix";
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
data: fs.readFileSync(path),
name: "templ-${{ env.EXT_VERSION }}.vsix",
headers: {
"content-type": "application/vsix",
"content-length": fs.statSync(path).size
}
});
core.summary.addLink(`Release v${{ env.EXT_VERSION }}`, release.data.html_url);
await core.summary.write();
publish:
environment: publish
needs: release
runs-on: ubuntu-latest
permissions: {}
steps:
- uses: actions/download-artifact@v4
with:
name: templ-${{ needs.release.outputs.version }}.vsix
- name: Publish to marketplace
# https://github.com/HaaLeo/publish-vscode-extension/releases/tag/v1.4.0
uses: HaaLeo/publish-vscode-extension@dfe4f6ad46624424fe24cb5bca79839183399045
with:
pat: ${{ secrets.PUBLISHER_KEY }}
registryUrl: https://marketplace.visualstudio.com
extensionFile: ./templ-${{ needs.release.outputs.version }}.vsix
open-vsx-publish:
name: Publish to Open VSX Registry
needs: release
environment: publish-open-vsx
runs-on: ubuntu-latest
env:
OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: templ-${{ needs.release.outputs.version }}.vsix
- name: Publish to Registry
run: |
npx ovsx publish -p $OPEN_VSX_TOKEN *.vsix