Skip to content

Commit 3894378

Browse files
committed
Fix GitHub Actions token authentication for release verification
- Add id-token: write permission to verify-assets job - Update token validation to use repository endpoint instead of user endpoint for GitHub Actions - Fixes 403 'Resource not accessible by integration' error
1 parent a8567ba commit 3894378

File tree

2 files changed

+35
-46
lines changed

2 files changed

+35
-46
lines changed

β€Ž.github/workflows/release.ymlβ€Ž

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@ name: Release app
99
on:
1010
workflow_dispatch:
1111
push:
12-
branches: [ main, release/** ]
12+
branches: [main, release/**]
1313
jobs:
1414
build:
1515
environment: release
16+
permissions:
17+
contents: write
1618
strategy:
1719
# Uncomment max-parallel to prevent race condition (where multiple releases are
1820
# created concurrently). Typically though, we'll create a release manually ahead of time
1921
# which prevents the race.
2022
# max-parallel: 1
2123
matrix:
2224
# See https://github.com/SFARPak/dyad/issues/96
23-
os: [
25+
os:
26+
[
2427
{ name: "windows", image: "windows-latest" },
2528
{ name: "linux", image: "ubuntu-22.04" },
2629
{ name: "macos-intel", image: "macos-13" },
2730
{ name: "macos", image: "macos-latest" },
2831
]
2932
runs-on: ${{ matrix.os.image }}
3033
# env:
31-
# CSC_LINK: ${{ secrets.CSC_LINK }}
32-
# CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
34+
# CSC_LINK: ${{ secrets.CSC_LINK }}
35+
# CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
3336
steps:
3437
- name: Github checkout
3538
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
@@ -81,7 +84,7 @@ jobs:
8184
# run: |
8285
# smctl windows certsync --keypair-alias=${{ secrets.DIGICERT_KEYPAIR_ALIAS }}
8386
# shell: bash
84-
# Publish (all platforms)
87+
# Publish (all platforms)
8588
- name: Publish app
8689
env:
8790
NODE_OPTIONS: "--max-old-space-size=4096"
@@ -102,47 +105,8 @@ jobs:
102105
contents: read
103106
packages: read
104107
actions: read
108+
id-token: write
105109
steps:
106-
- name: Check token permissions
107-
run: |
108-
echo "πŸ” Checking GITHUB_TOKEN permissions..."
109-
echo "πŸ“‘ Making API call to: https://api.github.com/user"
110-
111-
# Capture full response for detailed logging
112-
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}\n" \
113-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
114-
-H "Accept: application/vnd.github.v3+json" \
115-
-H "User-Agent: dyad-release-workflow" \
116-
https://api.github.com/user)
117-
118-
# Extract status code
119-
HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d: -f2)
120-
JSON_RESPONSE=$(echo "$RESPONSE" | sed '/HTTP_STATUS:/d')
121-
122-
echo "πŸ“‘ API Response Status: $HTTP_STATUS"
123-
124-
# Log token scopes and permissions from headers (if available)
125-
echo "πŸ”‘ Token scopes: $(curl -s -I \
126-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
127-
-H "Accept: application/vnd.github.v3+json" \
128-
https://api.github.com/user | grep -i "x-oauth-scopes:" | sed 's/.*: //' || echo "Not available")"
129-
130-
echo "πŸ“‹ Accepted permissions: $(curl -s -I \
131-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
132-
-H "Accept: application/vnd.github.v3+json" \
133-
https://api.github.com/user | grep -i "x-accepted-github-permissions:" | sed 's/.*: //' || echo "Not available")"
134-
135-
if [ "$HTTP_STATUS" -eq 200 ]; then
136-
echo "βœ… Token authentication successful"
137-
echo "πŸ‘€ User data:"
138-
echo "$JSON_RESPONSE" | jq '.login // "Not available"'
139-
echo "πŸ“‹ Permissions:"
140-
echo "$JSON_RESPONSE" | jq '.permissions // empty'
141-
else
142-
echo "❌ Token authentication failed with status: $HTTP_STATUS"
143-
echo "πŸ” Response body: $JSON_RESPONSE"
144-
exit 1
145-
fi
146110
- name: Github checkout
147111
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
148112
- name: Use Node.js

β€Žscripts/verify-release-assets.jsβ€Ž

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,32 @@ async function verifyReleaseAssets() {
5151
const userData = await userCheck.json();
5252
console.log(`βœ… Authenticated as: ${userData.login}`);
5353
} else {
54-
console.log("πŸƒ Running inside GitHub Actions β€” skipping token permission check");
54+
console.log("πŸƒ Running inside GitHub Actions β€” no user authentication check needed");
55+
56+
// Test API access by fetching org/user info
57+
try {
58+
const appCheck = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
59+
headers: {
60+
Authorization: `token ${token}`,
61+
Accept: "application/vnd.github.v3+json",
62+
"User-Agent": "dyad-release-verifier",
63+
},
64+
});
65+
66+
if (!appCheck.ok) {
67+
const body = await appCheck.text();
68+
console.error("❌ Token authentication failed!");
69+
console.error(`Status: ${appCheck.status} ${appCheck.statusText}`);
70+
console.error(`Response body: ${body}`);
71+
process.exit(1);
72+
}
73+
74+
const repoData = await appCheck.json();
75+
console.log(`βœ… Token authenticated for repository: ${repoData.full_name}`);
76+
} catch (error) {
77+
console.error("❌ Error testing token authentication:", error.message);
78+
process.exit(1);
79+
}
5580
}
5681

5782
// --- Fetch releases with retry logic ---

0 commit comments

Comments
Β (0)