Skip to content

Commit fc6b534

Browse files
committed
Add test for winget
1 parent 598d9bc commit fc6b534

2 files changed

Lines changed: 119 additions & 54 deletions

File tree

.github/workflows/winget-publish.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.github/workflows/winget.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: WinGet
2+
3+
on:
4+
release:
5+
types: [published]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
workflow_dispatch:
9+
inputs:
10+
release-tag:
11+
description: 'Release tag to validate (e.g. 0.14.0) — the release must already exist with the MSI asset uploaded'
12+
required: true
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
validate:
19+
name: Validate WinGet manifest (no PR submitted)
20+
# On release events, skip the rolling 'latest' tag
21+
if: github.event_name != 'release' || github.event.release.tag_name != 'latest'
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: "Harden the runner (Block egress traffic: Only allow calls to allowed endpoints)"
26+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
27+
with:
28+
egress-policy: block
29+
allowed-endpoints: >+
30+
github.com:443
31+
api.github.com:443
32+
release-assets.githubusercontent.com:443
33+
uploads.github.com:443
34+
35+
- name: Determine release tag
36+
id: tag
37+
env:
38+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
run: |
40+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
41+
echo "value=${{ inputs.release-tag }}" >> "$GITHUB_OUTPUT"
42+
elif [[ "${{ github.event_name }}" == "release" ]]; then
43+
echo "value=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
44+
else
45+
# PR: validate against the latest published release so there is a real installer to hash
46+
TAG=$(gh api "repos/${{ github.repository }}/releases/latest" --jq '.tag_name')
47+
echo "value=$TAG" >> "$GITHUB_OUTPUT"
48+
fi
49+
50+
- name: Install komac
51+
env:
52+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
run: |
54+
KOMAC_VERSION=$(gh api repos/russellbanks/Komac/releases/latest --jq '.tag_name')
55+
gh release download "$KOMAC_VERSION" \
56+
--repo russellbanks/Komac \
57+
--pattern '*-x86_64-unknown-linux-gnu.tar.gz' \
58+
--dir /tmp/komac-install
59+
mkdir -p /tmp/komac-extract
60+
tar -xzf /tmp/komac-install/*.tar.gz -C /tmp/komac-extract
61+
find /tmp/komac-extract -name komac -type f -exec install -m 755 {} /usr/local/bin/komac \;
62+
63+
- name: Generate manifest (no PR submitted)
64+
run: |
65+
komac update DFetch-org.DFetch \
66+
--version ${{ steps.tag.outputs.value }} \
67+
--urls https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.value }}/dfetch-${{ steps.tag.outputs.value }}-win.msi \
68+
--token ${{ secrets.GITHUB_TOKEN }} \
69+
--no-confirm
70+
71+
- name: Upload generated manifests
72+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
73+
with:
74+
name: winget-manifests-${{ steps.tag.outputs.value }}
75+
path: manifests/
76+
77+
publish:
78+
name: Publish to WinGet
79+
needs: [validate]
80+
if: github.event_name == 'release' && github.event.release.tag_name != 'latest'
81+
runs-on: ubuntu-latest
82+
concurrency:
83+
group: winget-publish-${{ github.event.release.tag_name }}
84+
cancel-in-progress: true
85+
86+
environment:
87+
name: winget
88+
url: https://github.com/microsoft/winget-pkgs
89+
90+
steps:
91+
- name: "Harden the runner (Block egress traffic: Only allow calls to allowed endpoints)"
92+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
93+
with:
94+
egress-policy: block
95+
allowed-endpoints: >+
96+
github.com:443
97+
api.github.com:443
98+
release-assets.githubusercontent.com:443
99+
index.crates.io:443
100+
101+
- name: Publish to WinGet
102+
# Requires WINGET_TOKEN secret in the 'winget' environment.
103+
#
104+
# Setup — create a fine-grained PAT:
105+
# 1. GitHub → Settings → Developer settings → Personal access tokens
106+
# → Fine-grained tokens → Generate new token
107+
# 2. Resource owner: DFetch-org (or your user)
108+
# 3. Repository access: All repositories
109+
# (needed to fork microsoft/winget-pkgs and push the manifest branch)
110+
# 4. Permissions:
111+
# Contents → Read and write
112+
# Pull requests → Read and write
113+
# 5. Store the token as secret WINGET_TOKEN in:
114+
# Repo → Settings → Environments → winget → Environment secrets
115+
uses: vedantmgoyal9/winget-releaser@4ffc7888bffd451b357355dc214d43bb9f23917e # v2
116+
with:
117+
identifier: DFetch-org.DFetch
118+
release-tag: ${{ github.event.release.tag_name }}
119+
token: ${{ secrets.WINGET_TOKEN }}

0 commit comments

Comments
 (0)