Skip to content

Commit a813d15

Browse files
author
linyuan.yang
committed
release
1 parent f770dd3 commit a813d15

4 files changed

Lines changed: 38 additions & 67 deletions

File tree

‎.github/workflows/release-app.yml‎

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,13 @@ jobs:
2929
needs: check
3030
runs-on: ubuntu-latest
3131
steps:
32-
- name: Create or refresh GitHub Release
33-
env:
34-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
REPO: ${{ github.repository }}
36-
TAG: ${{ needs.check.outputs.tag }}
37-
VERSION: ${{ needs.check.outputs.version }}
38-
RELEASE_NOTES: ${{ needs.check.outputs.notes }}
39-
shell: bash
40-
run: |
41-
set -euo pipefail
42-
if gh release view "$TAG" -R "$REPO" >/dev/null 2>&1; then
43-
gh release edit "$TAG" -R "$REPO" \
44-
--title "app v${VERSION}" \
45-
--notes "$RELEASE_NOTES"
46-
else
47-
gh release create "$TAG" -R "$REPO" \
48-
--target "$GITHUB_SHA" \
49-
--title "app v${VERSION}" \
50-
--notes "$RELEASE_NOTES"
51-
fi
52-
53-
gh api "/repos/$REPO/releases/tags/$TAG" --jq '.assets[] | "\(.id)\t\(.name)"' |
54-
while IFS=$'\t' read -r id name; do
55-
case "$name" in
56-
"sbot_${VERSION}_android.apk"|"sbot_${VERSION}_android.aab"|"sbot_${VERSION}_ios_unsigned.ipa"|sbot-vscode-*.vsix)
57-
continue
58-
;;
59-
"latest.json"|"latest-app.json"|"sbot.app.tar.gz"|"sbot.app.tar.gz.sig"|sbot_*.app.tar.gz|sbot_*.app.tar.gz.sig|sbot_${VERSION}_*)
60-
echo "delete stale release asset: $name"
61-
gh api -X DELETE "/repos/$REPO/releases/assets/$id" >/dev/null
62-
;;
63-
esac
64-
done
32+
- name: Recreate GitHub Release
33+
uses: while-coder/workflows/.github/actions/recreate-github-release@main
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
tag: ${{ needs.check.outputs.tag }}
37+
title: app v${{ needs.check.outputs.version }}
38+
notes: ${{ needs.check.outputs.notes }}
6539

6640
release-desktop:
6741
needs: [check, prepare-release]

‎.github/workflows/release-cli.yml‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,32 @@ jobs:
6161
echo "RELEASE_NOTES_EOF"
6262
} >> "$GITHUB_OUTPUT"
6363
64-
- name: Publish to npm
64+
- name: Check npm package version
65+
id: npm
6566
if: github.event_name == 'push'
67+
shell: bash
68+
run: |
69+
if npm view "sbot-cli@${{ steps.version.outputs.version }}" version >/dev/null 2>&1; then
70+
echo "published=true" >> "$GITHUB_OUTPUT"
71+
echo "sbot-cli@${{ steps.version.outputs.version }} is already published; skipping npm publish."
72+
else
73+
echo "published=false" >> "$GITHUB_OUTPUT"
74+
fi
75+
76+
- name: Publish to npm
77+
if: github.event_name == 'push' && steps.npm.outputs.published != 'true'
6678
env:
6779
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6880
run: pnpm --filter sbot-cli publish --no-git-checks
6981

82+
- name: Delete existing GitHub Release
83+
if: github.event_name == 'push'
84+
uses: while-coder/workflows/.github/actions/recreate-github-release@main
85+
with:
86+
github-token: ${{ secrets.GITHUB_TOKEN }}
87+
tag: ${{ github.ref_name }}
88+
create: 'false'
89+
7090
- name: Create GitHub Release
7191
if: github.event_name == 'push'
7292
uses: softprops/action-gh-release@v2

‎.github/workflows/release-sbot.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ jobs:
7878
# - name: Push Docker image
7979
# run: node packages/sbot/scripts/docker.js publish
8080

81+
- name: Delete existing GitHub Release
82+
if: github.event_name == 'push'
83+
uses: while-coder/workflows/.github/actions/recreate-github-release@main
84+
with:
85+
github-token: ${{ secrets.GITHUB_TOKEN }}
86+
tag: ${{ github.ref_name }}
87+
create: 'false'
88+
8189
- name: Create GitHub Release
8290
if: github.event_name == 'push'
8391
uses: softprops/action-gh-release@v2

‎scripts/release.js‎

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,7 @@ function remoteTagExists(tag) {
8181
return commandSucceeds(`git ls-remote --exit-code origin "refs/tags/${tag}"`);
8282
}
8383

84-
function githubReleaseExists(tag) {
85-
return commandSucceeds(`gh release view "${tag}"`);
86-
}
87-
88-
function assertGithubCliReady() {
89-
if (!commandSucceeds('gh --version')) {
90-
console.error('error: GitHub CLI (gh) is required to delete an existing GitHub release');
91-
process.exit(1);
92-
}
93-
if (!commandSucceeds('gh auth status')) {
94-
console.error('error: GitHub CLI is not authenticated; run "gh auth login" before overwriting a release');
95-
process.exit(1);
96-
}
97-
}
98-
99-
function deleteExistingRelease(tag) {
100-
const hasLocalTag = tagExists(tag);
101-
const hasRemoteTag = remoteTagExists(tag);
102-
103-
if (hasLocalTag || hasRemoteTag) {
104-
assertGithubCliReady();
105-
if (githubReleaseExists(tag)) {
106-
run(`gh release delete "${tag}" --yes --cleanup-tag`);
107-
} else {
108-
console.log(`GitHub release "${tag}" not found`);
109-
}
110-
} else if (commandSucceeds('gh --version') && commandSucceeds('gh auth status') && githubReleaseExists(tag)) {
111-
run(`gh release delete "${tag}" --yes --cleanup-tag`);
112-
} else {
113-
return;
114-
}
115-
84+
function deleteExistingTag(tag) {
11685
if (remoteTagExists(tag)) {
11786
run(`git push origin --delete "${tag}"`);
11887
}
@@ -244,7 +213,7 @@ function main() {
244213
}
245214

246215
if (cfg.overwriteExistingRelease) {
247-
deleteExistingRelease(tag);
216+
deleteExistingTag(tag);
248217
}
249218

250219
run(`git tag -a "${tag}" -m "${target} v${nextVersion}"`);

0 commit comments

Comments
 (0)