Skip to content

Commit ea63cc1

Browse files
authored
chore: add usage clarification + revert deleted release changes (#8)
## what - Updates info about the tokens usage. - Reverts changes of the removed release (v0.1.1) ## why - Readme was confusing. - Release v0.1.1 was removed as it contained a workaround for permission issues. They were appropriately fixed by mitigating the root cause; no WA was needed. ## references - N/A
1 parent 5829528 commit ea63cc1

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

CHANGELOG.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# Changelog
22

3-
## [0.1.1](https://github.com/masterpointio/github-action-trunk-upgrade/compare/v0.1.0...v0.1.1) (2025-09-01)
4-
5-
6-
### Bug Fixes
7-
8-
* don't require GH PAT ([#5](https://github.com/masterpointio/github-action-trunk-upgrade/issues/5)) ([0b927a3](https://github.com/masterpointio/github-action-trunk-upgrade/commit/0b927a33380e33d406f8d68d4f746fa6447d1a01))
9-
103
## 0.1.0 (2025-08-18)
114

125

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
A reusable GitHub Action for automated [Trunk](https://trunk.io) upgrades with status check handling and auto-merge.
1212

13-
This action automates the process of keeping your Trunk configuration up-to-date by creating pull requests for upgrades and automatically merging them after status checks pass. It follows security best practices with dual-token authentication and only waits for required status checks, avoiding unnecessary delays from optional checks.
13+
This action automates the process of keeping your Trunk configuration up-to-date by creating pull requests for upgrades and automatically merging them after status checks pass. It follows security best practices with a two-token setup and only waits for required status checks, avoiding unnecessary delays from optional checks.
1414

1515
## Usage
1616

1717
### Prerequisites
1818

1919
- GitHub repository with Trunk configuration
20-
- Personal Access Token (required)
20+
- Personal Access Token from a code owner or team member (required)
2121
- GitHub App credentials (recommended for enhanced performance and security)
2222
- Repository permissions: `contents: write` and `pull-requests: write`
2323

@@ -26,7 +26,7 @@ This action automates the process of keeping your Trunk configuration up-to-date
2626
1. **Set up authentication secrets** in your repository:
2727
- `BOT_APP_ID` - GitHub App ID
2828
- `BOT_APP_PRIVATE_KEY` - GitHub App private key
29-
- `ORG_PAT` - Personal Access Token with admin permissions
29+
- `CODE_OWNER_PAT` - Personal Access Token from a code owner or team member
3030
2. **Create workflow file** `.github/workflows/trunk-upgrade.yml`:
3131

3232
```yaml
@@ -50,7 +50,7 @@ jobs:
5050
with:
5151
app-id: ${{ secrets.BOT_APP_ID }}
5252
app-private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
53-
github-token: ${{ secrets.ORG_PAT }}
53+
github-token: ${{ secrets.CODE_OWNER_PAT }}
5454
reviewers: "@org/engineering"
5555
```
5656
@@ -84,33 +84,41 @@ with:
8484
github-token: ${{ secrets.GITHUB_TOKEN }}
8585
```
8686

87-
**Dual-Token (Recommended):**
87+
**Two-Token Setup (Recommended):**
8888

8989
```yaml
9090
with:
9191
app-id: ${{ secrets.BOT_APP_ID }}
9292
app-private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
93-
github-token: ${{ secrets.TEAM_PAT }}
93+
github-token: ${{ secrets.CODE_OWNER_PAT }}
9494
```
9595

96-
**How the dual-token setup works:**
96+
**How the two-token setup works:**
9797

9898
1. **GitHub App Token (Primary)**: Generated from `app-id` + `app-private-key`
9999
- Used for PR creation via trunk-io action
100100
- Higher rate limits (5,000/hr vs 1,000/hr)
101101
- Clean bot attribution in commits
102102
- Scoped permissions (only what the app needs)
103103

104-
2. **Personal Access Token (Fallback/Admin)**: `github-token` input
105-
- Used for merge operations with `--admin` flag
106-
- Bypasses branch protection rules reliably
107-
- Required for repositories with strict protection settings
104+
2. **Personal Access Token (Code Reviewer)**: `github-token` input
105+
- Used for merge operations to satisfy code owner requirements
106+
- Should be from a user who is a code owner or team member
107+
- Required for repositories with code owner review requirements
108+
- Bypasses the "can't approve own PR" limitation
108109
- Falls back if no App credentials provided
109110

111+
**Why Two-Token Setup is Recommended:**
112+
113+
Many repositories have branch protection rules requiring code owner reviews. When a GitHub App creates a PR, it cannot approve its own PR due to GitHub's security model. The two-token approach solves this by:
114+
115+
- **App creates the PR** → Clean bot attribution
116+
- **Code owner PAT approves/merges** → Satisfies repository protection rules
117+
110118
**Token Selection Logic:**
111119

112-
- If App credentials provided → Use App token for PR creation, PAT for merge
113-
- If no App credentials → Use PAT for both operations
120+
- If App credentials provided → Use App token for PR creation, PAT for approval/merge
121+
- If no App credentials → Use PAT for both operations (**Note**: This won't work if the repository has rulesets or branch protection rules requiring code owner reviews, since the same user/token cannot create and approve their own PR)
114122

115123
## Built By
116124

action.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ author: [email protected]
44

55
inputs:
66
github-token:
7-
description: GitHub token for creating PRs and performing operations (required if app credentials not provided)
7+
description: GitHub token for creating PRs and performing operations
8+
required: true
89

910
app-id:
1011
description: GitHub App ID for bot authentication
@@ -51,9 +52,8 @@ runs:
5152
- name: Validate inputs
5253
shell: bash
5354
run: |
54-
# Ensure either github-token OR app credentials are provided
55-
if [[ -z "${{ inputs.github-token }}" && ( -z "${{ inputs.app-id }}" || -z "${{ inputs.app-private-key }}" ) ]]; then
56-
echo "::error::Either github-token must be provided, or both app-id and app-private-key must be provided"
55+
if [[ -z "${{ inputs.github-token }}" ]]; then
56+
echo "::error::github-token is required"
5757
exit 1
5858
fi
5959
@@ -93,7 +93,7 @@ runs:
9393
id: auto-merge
9494
shell: bash
9595
env:
96-
GH_TOKEN: ${{ steps.github-token.outputs.token }}
96+
GH_TOKEN: ${{ inputs.github-token }}
9797
PR_NUMBER: ${{ steps.trunk-upgrade.outputs.pull-request-number }}
9898
REPO_URL: https://github.com/${{ github.repository }}
9999
MERGE_METHOD: ${{ inputs.merge-method }}
@@ -124,8 +124,10 @@ runs:
124124
echo "$1" | jq '[.[] | select(.state!="SUCCESS" or .bucket!="pass")] | length'
125125
}
126126
127-
merge_pr() {
128-
echo "🤖 Auto-merging PR $REPO_URL/pull/$PR_NUMBER..."
127+
approve_and_merge_pr() {
128+
local approval_message="$1"
129+
echo "🤖 Auto-approving and merging PR $REPO_URL/pull/$PR_NUMBER..."
130+
gh pr review "$PR_NUMBER" --approve --body "$approval_message"
129131
130132
# Retry merge up to 3 times to handle base branch updates
131133
local max_retries=3
@@ -167,8 +169,8 @@ runs:
167169
# Handle case with no required checks - can merge immediately
168170
if [ "$REQUIRED_COUNT" -eq 0 ]; then
169171
echo "✅ No required status checks configured. PR is ready to merge."
170-
echo "Proceeding with auto-merge..."
171-
if merge_pr; then
172+
echo "Proceeding with auto-approval and merge..."
173+
if approve_and_merge_pr "Auto-approved by trunk upgrade action (no required status checks)"; then
172174
exit 0
173175
else
174176
echo "❌ Failed to merge PR. Exiting with error."
@@ -206,7 +208,7 @@ runs:
206208
# Check if all required checks have passed
207209
PENDING_COUNT=$(count_pending_checks "$CURRENT_CHECKS")
208210
if [ "$PENDING_COUNT" -eq 0 ]; then
209-
if merge_pr; then
211+
if approve_and_merge_pr "Auto-approved by trunk upgrade action (all required checks passed)"; then
210212
break
211213
else
212214
echo "❌ Failed to merge PR after all checks passed. Exiting with error."

0 commit comments

Comments
 (0)