Skip to content

Commit ce96fd4

Browse files
committed
Split PR creation and publishing
1 parent 37cab94 commit ce96fd4

File tree

2 files changed

+105
-60
lines changed

2 files changed

+105
-60
lines changed

.github/workflows/publish.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Release and publish extension
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- package.json
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
contents: write
16+
17+
env:
18+
EXT_VERSION: "" # will be set in the workflow
19+
20+
outputs:
21+
version: ${{ env.EXT_VERSION }}
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
26+
- uses: actions/setup-node@v3
27+
with:
28+
node-version: "16"
29+
30+
- name: Parse version from package.json
31+
run: |
32+
echo "EXT_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
33+
34+
- run: npm ci
35+
36+
- run: npm run package
37+
38+
- uses: actions/upload-artifact@v3
39+
with:
40+
name: vscode-github-actions-${{ env.EXT_VERSION }}.vsix
41+
path: ./vscode-github-actions-${{ env.EXT_VERSION }}.vsix
42+
43+
- name: Create release and upload release asset
44+
uses: actions/github-script@v6
45+
with:
46+
script: |
47+
const fs = require("fs");
48+
49+
const release = await github.rest.repos.createRelease({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
tag_name: "release-v${{ env.EXT_VERSION }}",
53+
name: "v${{ env.EXT_VERSION }}",
54+
draft: false,
55+
prerelease: false
56+
});
57+
58+
const path = "./vscode-github-actions-${{ env.EXT_VERSION }}.vsix";
59+
await github.rest.repos.uploadReleaseAsset({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
release_id: release.data.id,
63+
data: fs.readFileSync(path).toString(),
64+
name: "vscode-github-actions-${{ env.EXT_VERSION }}.vsix",
65+
headers: {
66+
"content-type": "application/vsix",
67+
"content-length": fs.statSync(path).size
68+
}
69+
});
70+
71+
publish:
72+
environment: publish
73+
74+
needs: release
75+
76+
runs-on: ubuntu-latest
77+
permissions: {}
78+
79+
steps:
80+
- uses: actions/download-artifact@v3
81+
with:
82+
name: vscode-github-actions-${{ needs.release.outputs.version }}.vsix
83+
84+
- name: Publish to marketplace
85+
# https://github.com/HaaLeo/publish-vscode-extension/releases/tag/v1.2.0
86+
uses: HaaLeo/publish-vscode-extension@c1a0486c5a3eed24e8c21d4e37889a7c4c60c443
87+
with:
88+
pat: ${{ secrets.PUBLISHER_KEY }}
89+
registryUrl: https://marketplace.visualstudio.com
90+
extensionFile: ./vscode-github-actions-${{ needs.release.outputs.version }}.vsix

.github/workflows/release.yml

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Release and publish extension
22

3-
run-name: Release v${{ github.event.inputs.version }}
3+
run-name: Release new version
44

55
on:
66
workflow_dispatch:
@@ -10,7 +10,9 @@ 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:
@@ -28,65 +30,18 @@ jobs:
2830
git config --global user.email "github-actions@github.com"
2931
git config --global user.name "GitHub Actions"
3032
31-
npm version ${{ github.event.inputs.version }} --no-git-tag-version
33+
git checkout -b release/${{ inputs.version }}
34+
35+
npm version ${{ inputs.version }} --no-git-tag-version
3236
git add package.json package-lock.json
33-
git commit -m "Release extension version ${{ github.event.inputs.version }}"
37+
git commit -m "Release extension version ${{ inputs.version }}"
3438
3539
git push
3640
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-
});
59-
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
75-
76-
needs: release
77-
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
41+
- name: Create PR
42+
run: |
43+
gh pr create \
44+
--title "Release version ${{ inputs.version }}" \
45+
--body "Release version ${{ inputs.version }}" \
46+
--base main \
47+
--head release/${{ inputs.version }}

0 commit comments

Comments
 (0)