Skip to content

Commit fa834b9

Browse files
authored
fix: check_golang_profiler_changes github token (#149)
1 parent ef476d6 commit fa834b9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

.github/workflows/check_golang_profiler_changes.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
permissions:
99
contents: read
10+
id-token: write
1011

1112
jobs:
1213
check_golang_profiler_changes:
@@ -20,9 +21,21 @@ jobs:
2021
- uses: actions/setup-go@v5
2122
with:
2223
go-version: '1.20'
24+
- id: get-secrets
25+
uses: grafana/shared-workflows/actions/get-vault-secrets@28361cdb22223e5f1e34358c86c20908e7248760
26+
with:
27+
repo_secrets: |
28+
GRAFANA_PYROSCOPE_BOT_APP_APP_ID=grafana-pyroscope-bot:app-id
29+
GRAFANA_PYROSCOPE_BOT_APP_PRIVATE_KEY=grafana-pyroscope-bot:app-private-key
30+
- name: Generate token
31+
id: generate_token
32+
uses: actions/create-github-app-token@3ff1caaa28b64c9cc276ce0a02e2ff584f3900c5 # v2.0.2
33+
with:
34+
app-id: ${{ env.GRAFANA_PYROSCOPE_BOT_APP_APP_ID }}
35+
private-key: ${{ env.GRAFANA_PYROSCOPE_BOT_APP_PRIVATE_KEY }}
2336
- name: Check golang runtime profiler changes
2437
env:
25-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
2639
run: |
2740
cd godeltaprof/compat/cmd/check_golang_profiler_changes && go run main.go \
2841
-git.user.name="github-actions[bot]" \

godeltaprof/compat/cmd/check_golang_profiler_changes/main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ var gitUserEmail = flag.String("git.user.email", "", "git user email")
1919

2020
const goRepoURL = "https://github.com/golang/go.git"
2121

22-
const myRemote = "origin"
23-
2422
const mprof = "src/runtime/mprof.go"
2523
const pprof = "src/runtime/pprof"
2624
const repoDir = "go_repo"
@@ -120,7 +118,7 @@ func updatePR(prBodyFile string, request PullRequest) {
120118
shMy.sh(fmt.Sprintf("git config user.email '%s'", *gitUserEmail))
121119
}
122120
shMy.sh(fmt.Sprintf("git commit -am '%s'", commitMessage))
123-
shMy.sh(fmt.Sprintf("git push -f %s %s:%s", myRemote, branchName, request.HeadRefName))
121+
shMy.sh(fmt.Sprintf("git push -f %s %s:%s", remote(), branchName, request.HeadRefName))
124122

125123
shMy.sh(fmt.Sprintf("gh pr edit %d --body-file '%s'", request.Number, prBodyFile))
126124

@@ -136,12 +134,17 @@ func createPR(prBodyFile string) {
136134
shMy.sh(fmt.Sprintf("git config user.email '%s'", *gitUserEmail))
137135
}
138136
shMy.sh(fmt.Sprintf("git commit -am '%s'", commitMessage))
139-
shMy.sh(fmt.Sprintf("git push %s %s", myRemote, branchName))
137+
shMy.sh(fmt.Sprintf("git push %s %s", remote(), branchName))
140138

141139
shMy.sh(fmt.Sprintf("gh pr create --title '%s' --body-file '%s' --label '%s' ", commitMessage, prBodyFile, label))
142140

143141
}
144142

143+
func remote() string {
144+
token := strings.TrimSpace(os.Getenv("GITHUB_TOKEN"))
145+
return fmt.Sprintf("https://x-access-token:%[email protected]/grafana/pyroscope-go.git", token)
146+
}
147+
145148
func createCommitMessage() string {
146149
return fmt.Sprintf("chore(check_golang_profiler_changes): acknowledge new golang profiler changes")
147150
}

0 commit comments

Comments
 (0)