Skip to content

Commit ee54063

Browse files
authored
Merge pull request #6 from github/update-release
Use pull requests to trigger a new release
2 parents 37cab94 + 1c73e0b commit ee54063

File tree

2 files changed

+156
-62
lines changed

2 files changed

+156
-62
lines changed

.github/workflows/publish.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Release and publish extension
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- package.json
9+
10+
workflow_dispatch:
11+
inputs:
12+
version:
13+
description: "Version to release"
14+
required: true
15+
jobs:
16+
check-version-change:
17+
outputs:
18+
changed: ${{ steps.check-version.outputs.result }}
19+
20+
runs-on: ubuntu-latest
21+
22+
permissions:
23+
contents: read
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
- name: Check if version has changed
28+
id: check-version
29+
uses: actions/github-script@v6
30+
with:
31+
script: |
32+
const version = '${{ github.event.inputs.version }}' || require('./package.json').version;
33+
// Find a release for that version
34+
const release = await github.rest.repos.getReleaseByTag({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
tag: `release-v${version}`,
38+
}).catch(() => null);
39+
40+
// If the release exists, the version has not changed
41+
if (release) {
42+
console.log(`Version ${version} has an existing release`);
43+
console.log(release.data.html_url);
44+
core.summary.addLink(`Release v${version}`, release.data.html_url);
45+
await core.summary.write();
46+
return "false";
47+
}
48+
console.log(`Version ${version} does not have a release`);
49+
return true;
50+
51+
release:
52+
needs: check-version-change
53+
if: ${{ needs.check-version-change.outputs.changed == 'true' }}
54+
55+
runs-on: ubuntu-latest
56+
57+
permissions:
58+
contents: write
59+
60+
env:
61+
EXT_VERSION: "" # will be set in the workflow
62+
63+
outputs:
64+
version: ${{ env.EXT_VERSION }}
65+
66+
steps:
67+
- uses: actions/checkout@v3
68+
69+
- uses: actions/setup-node@v3
70+
with:
71+
node-version: "16"
72+
73+
- name: Parse version from package.json
74+
run: |
75+
echo "EXT_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
76+
77+
- run: npm ci
78+
79+
- run: npm run package
80+
81+
- uses: actions/upload-artifact@v3
82+
with:
83+
name: vscode-github-actions-${{ env.EXT_VERSION }}.vsix
84+
path: ./vscode-github-actions-${{ env.EXT_VERSION }}.vsix
85+
86+
- name: Create release and upload release asset
87+
uses: actions/github-script@v6
88+
with:
89+
script: |
90+
const fs = require("fs");
91+
92+
const release = await github.rest.repos.createRelease({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
tag_name: "release-v${{ env.EXT_VERSION }}",
96+
name: "v${{ env.EXT_VERSION }}",
97+
draft: false,
98+
prerelease: false
99+
});
100+
101+
const path = "./vscode-github-actions-${{ env.EXT_VERSION }}.vsix";
102+
await github.rest.repos.uploadReleaseAsset({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
release_id: release.data.id,
106+
data: fs.readFileSync(path).toString(),
107+
name: "vscode-github-actions-${{ env.EXT_VERSION }}.vsix",
108+
headers: {
109+
"content-type": "application/vsix",
110+
"content-length": fs.statSync(path).size
111+
}
112+
});
113+
114+
core.summary.addLink(`Release v${version}`, release.data.html_url);
115+
await core.summary.write();
116+
117+
publish:
118+
environment: publish
119+
120+
needs: release
121+
122+
runs-on: ubuntu-latest
123+
permissions: {}
124+
125+
steps:
126+
- uses: actions/download-artifact@v3
127+
with:
128+
name: vscode-github-actions-${{ needs.release.outputs.version }}.vsix
129+
130+
- name: Publish to marketplace
131+
# https://github.com/HaaLeo/publish-vscode-extension/releases/tag/v1.2.0
132+
uses: HaaLeo/publish-vscode-extension@c1a0486c5a3eed24e8c21d4e37889a7c4c60c443
133+
with:
134+
pat: ${{ secrets.PUBLISHER_KEY }}
135+
registryUrl: https://marketplace.visualstudio.com
136+
extensionFile: ./vscode-github-actions-${{ needs.release.outputs.version }}.vsix

.github/workflows/release.yml

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: Release and publish extension
1+
name: Create release PR
22

3-
run-name: Release v${{ github.event.inputs.version }}
3+
run-name: Create release PR for v${{ github.event.inputs.version }}
44

55
on:
66
workflow_dispatch:
@@ -10,11 +10,14 @@ on:
1010
description: "Version to bump `package.json` to (format: x.y.z)"
1111

1212
jobs:
13-
release:
13+
create-release-pr:
14+
name: Create release PR
15+
1416
runs-on: ubuntu-latest
1517

1618
permissions:
1719
contents: write
20+
pull-requests: write
1821

1922
steps:
2023
- uses: actions/checkout@v3
@@ -28,65 +31,20 @@ jobs:
2831
git config --global user.email "github-actions@github.com"
2932
git config --global user.name "GitHub Actions"
3033
31-
npm version ${{ github.event.inputs.version }} --no-git-tag-version
32-
git add package.json package-lock.json
33-
git commit -m "Release extension version ${{ github.event.inputs.version }}"
34-
35-
git push
36-
37-
- run: npm ci
38-
- run: npm run package
39-
40-
- uses: actions/upload-artifact@v3
41-
with:
42-
name: vscode-github-actions-${{ github.event.inputs.version }}.vsix
43-
path: ./vscode-github-actions-${{ github.event.inputs.version }}.vsix
44-
45-
- name: Create release and upload release asset
46-
uses: actions/github-script@v6
47-
with:
48-
script: |
49-
const fs = require("fs");
50-
51-
const release = await github.rest.repos.createRelease({
52-
owner: context.repo.owner,
53-
repo: context.repo.repo,
54-
tag_name: "release-v${{ github.event.inputs.version }}",
55-
name: "v${{ github.event.inputs.version }}",
56-
draft: false,
57-
prerelease: false
58-
});
34+
git checkout -b release/${{ inputs.version }}
5935
60-
const path = "./vscode-github-actions-${{ github.event.inputs.version }}.vsix";
61-
await github.rest.repos.uploadReleaseAsset({
62-
owner: context.repo.owner,
63-
repo: context.repo.repo,
64-
release_id: release.data.id,
65-
data: fs.readFileSync(path).toString(),
66-
name: "vscode-github-actions-${{ github.event.inputs.version }}.vsix",
67-
headers: {
68-
"content-type": "application/vsix",
69-
"content-length": fs.statSync(path).size
70-
}
71-
});
72-
73-
publish:
74-
environment: publish
36+
npm version ${{ inputs.version }} --no-git-tag-version
37+
git add package.json package-lock.json
38+
git commit -m "Release extension version ${{ inputs.version }}"
7539
76-
needs: release
40+
git push --set-upstream origin release/${{ inputs.version }}
7741
78-
runs-on: ubuntu-latest
79-
permissions: {}
80-
81-
steps:
82-
- uses: actions/download-artifact@v3
83-
with:
84-
name: vscode-github-actions-${{ github.event.inputs.version }}.vsix
85-
86-
- name: Publish to marketplace
87-
# https://github.com/HaaLeo/publish-vscode-extension/releases/tag/v1.2.0
88-
uses: HaaLeo/publish-vscode-extension@c1a0486c5a3eed24e8c21d4e37889a7c4c60c443
89-
with:
90-
pat: ${{ secrets.PUBLISHER_KEY }}
91-
registryUrl: https://marketplace.visualstudio.com
92-
extensionFile: ./vscode-github-actions-${{ github.event.inputs.version }}.vsix
42+
- name: Create PR
43+
run: |
44+
gh pr create \
45+
--title "Release version ${{ inputs.version }}" \
46+
--body "Release version ${{ inputs.version }}" \
47+
--base main \
48+
--head release/${{ inputs.version }}
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)