Skip to content

Commit b5d64e3

Browse files
committed
refactor: Replace PAT with GitHub App for WinGet publishing
Signed-off-by: Snowiee <xenonoxidee@gmail.com>
1 parent 8253b13 commit b5d64e3

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

.dagger/README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,27 @@ dagger call publish-image \
7474

7575
Automates the submission of Harbor CLI updates to the Windows Package Manager (WinGet) repository. This function uses `wingetcreate` to update the package manifest and automatically submit a pull request to `microsoft/winget-pkgs`.
7676

77-
Before running the command, export your GitHub Personal Access Token (with `public_repo` scope):
77+
#### GitHub App Setup
78+
79+
For automated workflows, we use a GitHub App instead of Personal Access Tokens for better security and maintainability:
80+
81+
1. **Create a GitHub App** for your organization with permissions:
82+
- `Contents: write`
83+
- `Pull requests: write`
84+
85+
2. **Fork `microsoft/winget-pkgs`** to your organization
86+
87+
3. **Install the GitHub App** on the fork
88+
89+
4. **Configure secrets/variables:**
90+
- `vars.WINGET_APP_ID` - GitHub App ID
91+
- `secrets.WINGET_APP_PRIVATE_KEY` - GitHub App private key
92+
93+
The workflow uses `actions/create-github-app-token@v2` to generate short-lived tokens (1 hour) at runtime.
94+
95+
#### Local Development
96+
97+
For local testing, export a GitHub token with `public_repo` scope:
7898

7999
```shell
80100
export GITHUB_TOKEN=ghp_yourTokenHere
@@ -106,7 +126,7 @@ This will:
106126
3. Automatically submit a PR to the `microsoft/winget-pkgs` repository
107127

108128
**Requirements:**
109-
- GitHub Personal Access Token with `public_repo` scope
129+
- GitHub App (for CI/CD) or Personal Access Token with `public_repo` scope (for local dev)
110130
- Valid installer URLs (must be publicly accessible)
111131
- Existing package in the WinGet repository
112132
- **Windows Docker host** or Windows container support (for CI/CD, use `runs-on: windows-latest` in GitHub Actions)

.github/workflows/default.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ jobs:
265265
with:
266266
fetch-depth: 0
267267

268+
- name: Generate GitHub App Token
269+
id: app-token
270+
uses: actions/create-github-app-token@v2
271+
with:
272+
app-id: ${{ vars.WINGET_APP_ID }}
273+
private-key: ${{ secrets.WINGET_APP_PRIVATE_KEY }}
274+
owner: goharbor
275+
repositories: winget-pkgs
276+
268277
- name: Extract version from tag
269278
id: extract_version
270279
shell: bash
@@ -276,7 +285,7 @@ jobs:
276285
- name: Publish to WinGet
277286
uses: dagger/dagger-for-github@v7
278287
env:
279-
GITHUB_TOKEN: ${{ secrets.WINGET_GITHUB_TOKEN }}
288+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
280289
with:
281290
version: "latest"
282291
verb: call

0 commit comments

Comments
 (0)