Skip to content

Commit 486741e

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

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: CI Pipeline
2+
run-name: ${{ github.actor }} is automatically publishing
23

34
on:
45
push:
@@ -53,6 +54,30 @@ jobs:
5354
pull-requests: write
5455
runs-on: ubuntu-latest
5556
steps:
57+
- name: Decode the GitHub App Private Key
58+
id: decode
59+
run: |
60+
private_key=$(echo "${{ secrets.BOT_PRIVATE_KEY }}" | base64 -d | awk 'BEGIN {ORS="\\n"} {print}' | head -c -2) &> /dev/null
61+
echo "::add-mask::$private_key"
62+
echo "private-key=$private_key" >> "$GITHUB_OUTPUT"
63+
- name: 'Generate token'
64+
id: GENERATE_TOKEN
65+
uses: actions/create-github-app-token@v2
66+
with:
67+
app-id: ${{ secrets.BOT_APP_ID }}
68+
private-key: ${{ steps.decode.outputs.private-key }}
69+
70+
- name: Get GitHub App User ID
71+
id: get-user-id
72+
run: echo "user-id=$(gh api "/users/${{ steps.GENERATE_TOKEN.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
73+
env:
74+
GH_TOKEN: ${{ steps.GENERATE_TOKEN.outputs.token }}
75+
76+
- name: Set global username and email
77+
run: |
78+
git config --global user.name '${{ steps.GENERATE_TOKEN.outputs.app-slug }}[bot]'
79+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.GENERATE_TOKEN.outputs.app-slug }}[bot]@users.noreply.github.com'
80+
5681
- name: Checkout
5782
uses: actions/checkout@v4
5883

@@ -78,8 +103,12 @@ jobs:
78103
with:
79104
inputs: "*.tgz"
80105

106+
- name: Debug auth
107+
run: |
108+
curl -s -H "Authorization: token ${{ steps.GENERATE_TOKEN.outputs.token }}" https://api.github.com/user
109+
81110
- name: Run Semantic Release
82111
env:
83-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
GITHUB_TOKEN: ${{ steps.GENERATE_TOKEN.outputs.token }}
84113
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
85114
run: npx semantic-release

0 commit comments

Comments
 (0)