Skip to content

Commit f469ec2

Browse files
authored
fix: use PAT for OperatorHub upstream PR creation (#196)
GitHub App tokens only have permissions on repos where the app is installed (our org's fork). Creating PRs on k8s-operatorhub/community-operators requires a PAT with public_repo scope. Split token usage: GH_TOKEN (app token) for fork git operations, UPSTREAM_GH_TOKEN (PAT via OPERATORHUB_PAT secret) for upstream gh pr create/edit/list commands. Closes #195 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent 2dcce1e commit f469ec2

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

.github/workflows/release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ jobs:
399399
env:
400400
VERSION: ${{ needs.release.outputs.tag }}
401401
GH_TOKEN: ${{ steps.app-token.outputs.token }}
402+
UPSTREAM_GH_TOKEN: ${{ secrets.OPERATORHUB_PAT }}
402403
FORK_OWNER: attune-io
403404
run: |
404405
# Strip 'v' prefix from tag

hack/operatorhub-pr.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#!/usr/bin/env bash
22
# Create or update a PR to k8s-operatorhub/community-operators for a new Attune release.
33
#
4-
# Usage: VERSION=0.1.7 GH_TOKEN=<pat> hack/operatorhub-pr.sh
4+
# Usage: VERSION=0.1.7 GH_TOKEN=<token> hack/operatorhub-pr.sh
55
#
66
# Required env vars:
77
# VERSION - Release version without 'v' prefix (e.g., 0.1.7)
8-
# GH_TOKEN - GitHub token (App token from CI, or PAT for local use)
8+
# GH_TOKEN - GitHub App token for pushing to the fork repo
99
#
1010
# Optional env vars:
11+
# UPSTREAM_GH_TOKEN - PAT with public_repo scope for creating PRs on
12+
# k8s-operatorhub/community-operators. Required because
13+
# GitHub App tokens can only act on repos where the app
14+
# is installed (our fork), not the upstream repo.
15+
# Falls back to GH_TOKEN if not set.
1116
# FORK_OWNER - GitHub user owning the fork (default: SebTardif)
1217
# GIT_USER_NAME - Git commit author name (default: github-actions[bot])
1318
# GIT_USER_EMAIL - Git commit author email (default: 41898282+github-actions[bot]@users.noreply.github.com)
@@ -103,8 +108,13 @@ See [release notes](https://github.com/attune-io/attune/releases/tag/v${VERSION}
103108
---
104109
*This PR was automatically created by the Attune release workflow.*"
105110

111+
# Switch to a token that can create PRs on the upstream public repo.
112+
# GitHub App tokens only work on repos where the app is installed (our fork).
113+
# Creating cross-fork PRs requires a PAT with public_repo scope.
114+
PR_TOKEN="${UPSTREAM_GH_TOKEN:-${GH_TOKEN}}"
115+
106116
# Check if a PR already exists for this branch
107-
EXISTING_PR=$(gh pr list \
117+
EXISTING_PR=$(GH_TOKEN="${PR_TOKEN}" gh pr list \
108118
--repo "${UPSTREAM_REPO}" \
109119
--head "${FORK_OWNER}:${BRANCH}" \
110120
--state open \
@@ -113,14 +123,14 @@ EXISTING_PR=$(gh pr list \
113123

114124
if [ -n "${EXISTING_PR}" ]; then
115125
echo "Updating existing PR #${EXISTING_PR}"
116-
gh pr edit "${EXISTING_PR}" \
126+
GH_TOKEN="${PR_TOKEN}" gh pr edit "${EXISTING_PR}" \
117127
--repo "${UPSTREAM_REPO}" \
118128
--title "${PR_TITLE}" \
119129
--body "${PR_BODY}"
120130
echo "PR updated: https://github.com/${UPSTREAM_REPO}/pull/${EXISTING_PR}"
121131
else
122132
echo "Creating new PR..."
123-
PR_URL=$(gh pr create \
133+
PR_URL=$(GH_TOKEN="${PR_TOKEN}" gh pr create \
124134
--repo "${UPSTREAM_REPO}" \
125135
--head "${FORK_OWNER}:${BRANCH}" \
126136
--base main \

0 commit comments

Comments
 (0)