Skip to content

Commit 1c73e0b

Browse files
committed
Get publish and release workflows working
1 parent f6c322e commit 1c73e0b

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,51 @@ on:
77
paths:
88
- package.json
99

10+
workflow_dispatch:
11+
inputs:
12+
version:
13+
description: "Version to release"
14+
required: true
1015
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+
1151
release:
52+
needs: check-version-change
53+
if: ${{ needs.check-version-change.outputs.changed == 'true' }}
54+
1255
runs-on: ubuntu-latest
1356

1457
permissions:
@@ -68,6 +111,9 @@ jobs:
68111
}
69112
});
70113
114+
core.summary.addLink(`Release v${version}`, release.data.html_url);
115+
await core.summary.write();
116+
71117
publish:
72118
environment: publish
73119

.github/workflows/release.yml

Lines changed: 5 additions & 3 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 new version
3+
run-name: Create release PR for v${{ github.event.inputs.version }}
44

55
on:
66
workflow_dispatch:
@@ -37,7 +37,7 @@ jobs:
3737
git add package.json package-lock.json
3838
git commit -m "Release extension version ${{ inputs.version }}"
3939
40-
git push
40+
git push --set-upstream origin release/${{ inputs.version }}
4141
4242
- name: Create PR
4343
run: |
@@ -46,3 +46,5 @@ jobs:
4646
--body "Release version ${{ inputs.version }}" \
4747
--base main \
4848
--head release/${{ inputs.version }}
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)