Skip to content

Commit 49faea0

Browse files
authored
SDPLAT-26671: use GH_APP for GitHub REST API (#161)
* SDPLAT-26671: use GH_APP for GitHub REST API * adjust CodeQL for GH_APP * ensure CodeQL is also initialised with GH_APP * attempt directly uploading CodeQL results * send SARIF as JSON * adjust curl parameters for CodeQL upload * attempt directly uploading CodeQL results * debug: upload codeql results * debug: upload CodeQL results after gzip * use environment variable to pass SARIF to curl for CodeQL * remove pull_request trigger for CodeQL
1 parent c08efce commit 49faea0

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

.github/workflows/codeql.yml

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
22
name: CodeQL
33
on:
4-
pull_request:
54
schedule:
6-
- cron: '09 09 * * 1'
5+
- cron: "09 09 * * 1"
76

87
jobs:
98
codeql:
@@ -16,13 +15,46 @@ jobs:
1615
with:
1716
go-version: ^1.23
1817

18+
- uses: actions/create-github-app-token@v1
19+
id: app-token
20+
with:
21+
app-id: ${{ vars.GH_APP_ID }}
22+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
23+
1924
- name: Initialize CodeQL
2025
uses: github/codeql-action/init@v3
2126
with:
2227
languages: go
28+
token: ${{ steps.app-token.outputs.token }}
2329

2430
- name: Build
2531
run: make build
2632

2733
- name: Perform CodeQL Analysis
2834
uses: github/codeql-action/analyze@v3
35+
with:
36+
token: ${{ steps.app-token.outputs.token }}
37+
upload: never
38+
39+
# Workaround for parallel GitHub bugs
40+
# * Can't use GHA token with IP allowlisting
41+
# https://docs.github.com/en/enterprise-cloud@latest/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/managing-allowed-ip-addresses-for-your-organization#using-github-actions-with-an-ip-allow-list
42+
# * Can't use codeql-action/analyze with custom token
43+
# https://support.github.com/ticket/enterprise/3427/3214517
44+
- name: Prepare CodeQL Results
45+
run: |
46+
echo "SARIF_RESULTS=$(gzip -c ../results/go.sarif | base64 -w0)" >> $GITHUB_ENV
47+
48+
# Workaround for parallel GitHub bugs
49+
# * Can't use GHA token with IP allowlisting
50+
# https://docs.github.com/en/enterprise-cloud@latest/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/managing-allowed-ip-addresses-for-your-organization#using-github-actions-with-an-ip-allow-list
51+
# * Can't use codeql-action/analyze with custom token
52+
# https://support.github.com/ticket/enterprise/3427/3214517
53+
- name: Upload CodeQL Results
54+
run: |
55+
curl --fail-with-body \
56+
-X POST \
57+
-H "Authorization: token ${{ steps.app-token.outputs.token }}" \
58+
-H "Accept: application/vnd.github.v3+json" \
59+
-d '{"commit_sha": "${{ github.sha }}", "ref": "${{ github.ref }}", "sarif": "${{ env.SARIF_RESULTS }}"}' \
60+
https://api.github.com/repos/${{ github.repository }}/code-scanning/sarifs

.github/workflows/release-drafter.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ jobs:
1111
update_release_draft:
1212
runs-on: ubuntu-latest
1313
steps:
14+
- uses: actions/create-github-app-token@v1
15+
id: app-token
16+
with:
17+
app-id: ${{ vars.GH_APP_ID }}
18+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
19+
1420
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348 # v6.0.0
1521
env:
16-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}

.github/workflows/release.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ jobs:
1919
with:
2020
go-version: ^1.23
2121

22+
- uses: actions/create-github-app-token@v1
23+
id: app-token
24+
with:
25+
app-id: ${{ vars.GH_APP_ID }}
26+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
27+
2228
- name: Run GoReleaser
2329
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
2430
with:
2531
args: release --clean
2632
env:
27-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
2834
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}

0 commit comments

Comments
 (0)