Skip to content

Commit 40af73a

Browse files
authored
Merge pull request #91 from daiduo2/main
fix(ci): add workflow permissions for sync-upstream
2 parents 543f8af + bed51ab commit 40af73a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

.github/workflows/sync-upstream.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,35 @@ on:
77

88
permissions:
99
contents: write
10+
workflows: write
1011

1112
jobs:
1213
sync:
13-
# 仅在 fork 仓库执行;主仓库没有上游同步需求
14+
# 仅在 fork 仓库执行;主仓库没有"上游同步"需求
1415
if: github.repository != 'gqy20/IssueLab'
1516
runs-on: ubuntu-latest
1617
steps:
1718
- uses: actions/checkout@v4
1819
with:
1920
fetch-depth: 0
20-
token: ${{ secrets.PAT_TOKEN || github.token }}
21+
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
2122
- name: Add upstream
2223
run: |
2324
git remote add upstream https://github.com/gqy20/IssueLab.git || true
2425
git fetch upstream
26+
- name: Configure Git
27+
run: |
28+
git config user.name "github-actions[bot]"
29+
git config user.email "github-actions[bot]@users.noreply.github.com"
2530
- name: Merge upstream/main
2631
run: |
2732
git checkout main
28-
git merge upstream/main --ff-only || git merge upstream/main --no-edit
33+
git merge upstream/main --ff-only || git merge upstream/main --no-edit || echo "No changes to merge"
2934
- name: Push
3035
env:
3136
GH_PUSH_TOKEN: ${{ secrets.PAT_TOKEN }}
3237
run: |
33-
if [ -z "${GH_PUSH_TOKEN}" ]; then
34-
echo "PAT_TOKEN is required for push in sync-upstream workflow." >&2
35-
exit 1
38+
if [ -n "${GH_PUSH_TOKEN}" ]; then
39+
git remote set-url origin "https://x-access-token:${GH_PUSH_TOKEN}@github.com/${{ github.repository }}.git"
3640
fi
37-
git remote set-url origin "https://x-access-token:${GH_PUSH_TOKEN}@github.com/${{ github.repository }}.git"
38-
git push origin main
41+
git push origin main || echo "Nothing to push"

0 commit comments

Comments
 (0)