Skip to content

Commit f8da559

Browse files
committed
ci(steps): Handle push into protected branch
1 parent 3df8aec commit f8da559

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,34 @@ jobs:
5353
pull-requests: write
5454
runs-on: ubuntu-latest
5555
steps:
56+
- name: 'Generate token'
57+
id: GENERATE_TOKEN
58+
uses: actions/create-github-app-token@v2
59+
with:
60+
app-id: ${{ secrets.BOT_APP_ID }}
61+
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
62+
permission-issues: write
63+
permission-id-token: write
64+
permission-contents: write
65+
permission-pull-requests: write
66+
67+
- name: Get GitHub App User ID
68+
id: get-user-id
69+
run: |
70+
echo "user-id=$(gh api "/users/${{ steps.GENERATE_TOKEN.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
71+
echo ${{ steps.GENERATE_TOKEN.outputs.token }}
72+
env:
73+
GH_TOKEN: ${{ steps.GENERATE_TOKEN.outputs.token }}
74+
75+
- name: Set global username and email
76+
run: |
77+
git config --global user.name '${{ steps.GENERATE_TOKEN.outputs.app-slug }}[bot]'
78+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.GENERATE_TOKEN.outputs.app-slug }}[bot]@users.noreply.github.com'
79+
80+
- name: Debug auth
81+
run: |
82+
curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ steps.GENERATE_TOKEN.outputs.token }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/user
83+
5684
- name: Checkout
5785
uses: actions/checkout@v4
5886

@@ -80,6 +108,6 @@ jobs:
80108

81109
- name: Run Semantic Release
82110
env:
83-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
GITHUB_TOKEN: ${{ steps.GENERATE_TOKEN.outputs.token }}
84112
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
85113
run: npx semantic-release

0 commit comments

Comments
 (0)