Skip to content

Commit 04947b2

Browse files
author
sunzhongyi
committed
fix: 403 for action create tag for repo
1 parent 990236a commit 04947b2

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

.github/workflows/publish.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ on:
1919
jobs:
2020
publish:
2121
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
actions: read
2225

2326
steps:
2427
- name: Checkout code
@@ -64,11 +67,23 @@ jobs:
6467

6568
- name: Create Git Tag (for releases only)
6669
if: github.event.inputs.release_type == 'release'
67-
run: |
68-
git config --local user.email "[email protected]"
69-
git config --local user.name "GitHub Action"
70-
git tag "v${{ github.event.inputs.version }}"
71-
git push origin "v${{ github.event.inputs.version }}"
70+
uses: actions/github-script@v7
71+
with:
72+
script: |
73+
const tag = `v${{ github.event.inputs.version }}`;
74+
const ref = `refs/tags/${tag}`;
75+
76+
try {
77+
await github.rest.git.createRef({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
ref: ref,
81+
sha: context.sha
82+
});
83+
console.log(`Created tag: ${tag}`);
84+
} catch (error) {
85+
console.log(`Tag ${tag} might already exist: ${error.message}`);
86+
}
7287
7388
- name: Create GitHub Release (for releases only)
7489
if: github.event.inputs.release_type == 'release'
@@ -77,6 +92,7 @@ jobs:
7792
tag_name: "v${{ github.event.inputs.version }}"
7893
files: "*.vsix"
7994
generate_release_notes: true
95+
make_latest: true
8096
env:
8197
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8298

0 commit comments

Comments
 (0)