Skip to content

Commit f77dc52

Browse files
authored
👷 CI: 修复 Release 权限错误 (#2381)
1 parent 0d84bf3 commit f77dc52

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

.github/workflows/release-drafter.yml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ jobs:
5959
release:
6060
if: startsWith(github.ref, 'refs/tags/')
6161
runs-on: ubuntu-latest
62+
permissions:
63+
id-token: write
64+
contents: write
6265
steps:
6366
- name: Generate token
6467
id: generate-token
@@ -78,39 +81,53 @@ jobs:
7881
- name: Build API Doc
7982
uses: ./.github/actions/build-api-doc
8083

81-
- run: |
82-
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
84+
- name: Get Version
85+
id: version
86+
run: |
87+
echo "VERSION=$(poetry version -s)" >> $GITHUB_OUTPUT
88+
echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
89+
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
90+
91+
- name: Check Version
92+
if: steps.version.outputs.VERSION != steps.version.outputs.TAG_VERSION
93+
run: exit 1
8394

8495
- uses: release-drafter/release-drafter@v5
8596
with:
86-
name: Release ${{ env.TAG_NAME }} 🌈
87-
tag: ${{ env.TAG_NAME }}
97+
name: Release ${{ steps.version.outputs.TAG_NAME }} 🌈
98+
tag: ${{ steps.version.outputs.TAG_NAME }}
8899
publish: true
89100
env:
90101
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
91102

92-
- name: Build and Publish Package
103+
- name: Build Package
93104
run: |
94105
poetry build
95-
gh release upload --clobber ${{ env.TAG_NAME }} dist/*.tar.gz dist/*.whl
96-
env:
97-
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
98106
99107
- name: Publish package to PyPI
100108
uses: pypa/gh-action-pypi-publish@release/v1
101109

110+
- name: Publish package to GitHub
111+
run: |
112+
gh release upload --clobber ${{ steps.version.outputs.TAG_NAME }} dist/*.tar.gz dist/*.whl
113+
env:
114+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
115+
102116
- name: Build and Publish Doc Package
103117
run: |
104118
yarn build:plugin --out-dir ../packages/nonebot-plugin-docs/nonebot_plugin_docs/dist
105-
export NONEBOT_VERSION=`poetry version -s`
106119
cd packages/nonebot-plugin-docs/
107-
poetry version $NONEBOT_VERSION
120+
poetry version ${{ steps.version.outputs.VERSION }}
108121
poetry build
109-
gh release upload --clobber ${{ env.TAG_NAME }} dist/*.tar.gz dist/*.whl
110-
env:
111-
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
112122
113123
- name: Publish Doc Package to PyPI
114124
uses: pypa/gh-action-pypi-publish@release/v1
115125
with:
116126
packages-dir: packages/nonebot-plugin-docs/
127+
128+
- name: Publish Doc Package to GitHub
129+
run: |
130+
cd packages/nonebot-plugin-docs/
131+
gh release upload --clobber ${{ steps.version.outputs.TAG_NAME }} dist/*.tar.gz dist/*.whl
132+
env:
133+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

0 commit comments

Comments
 (0)