| 1 | name: winget Release |
| 2 | |
| 3 | # Dispatched by release-github.yml once the release and its checksums exist. |
| 4 | # |
| 5 | # winget manifests live in microsoft/winget-pkgs, and `wingetcreate update` |
| 6 | # only works on a package that is already there. So this workflow branches: |
| 7 | # |
| 8 | # - package already in winget-pkgs -> `wingetcreate update`, which rewrites |
| 9 | # the URLs and re-hashes the installers for us. |
| 10 | # - package not there yet -> render the manifests in packaging/winget/ and |
| 11 | # `wingetcreate submit` them as a new package. |
| 12 | # |
| 13 | # The second path only runs once, but keeping it here means a first release |
| 14 | # does not need someone to sit at a Windows box running `wingetcreate new` |
| 15 | # interactively. |
| 16 | on: |
| 17 | workflow_dispatch: |
| 18 | inputs: |
| 19 | tag: |
| 20 | description: "Release tag (e.g. v0.4.0)" |
| 21 | required: true |
| 22 | |
| 23 | concurrency: |
| 24 | # A re-pushed or re-dispatched tag fires this a second time. Queue the |
| 25 | # duplicate behind the original instead of cancelling it: cancelling a run |
| 26 | # mid-publish can leave a channel half-updated, whereas a queued duplicate |
| 27 | # just hits the "already published" check and exits clean. |
| 28 | group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }} |
| 29 | cancel-in-progress: false |
| 30 | |
| 31 | permissions: |
| 32 | contents: read |
| 33 | |
| 34 | env: |
| 35 | REPO: ondeinference/onde-cli |
| 36 | PACKAGE_IDENTIFIER: OndeInference.onde-cli |
| 37 | |
| 38 | jobs: |
| 39 | submit-winget-manifest: |
| 40 | name: Submit winget manifest |
| 41 | # wingetcreate is a Windows-only tool. |
| 42 | runs-on: windows-latest |
| 43 | |
| 44 | steps: |
| 45 | - name: Check out repository |
| 46 | uses: actions/checkout@v6 |
| 47 | |
| 48 | - name: Resolve tag, version and release date |
| 49 | id: release |
| 50 | shell: bash |
| 51 | env: |
| 52 | GH_TOKEN: ${{ github.token }} |
| 53 | run: | |
| 54 | TAG="${{ github.event.inputs.tag }}" |
| 55 | VERSION="${TAG#v}" |
| 56 | # wingetcreate wants ReleaseDate as YYYY-MM-DD. |
| 57 | DATE=$(gh release view "$TAG" --repo "$REPO" --json publishedAt --jq '.publishedAt[0:10]') |
| 58 | |
| 59 | echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 60 | echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 61 | echo "date=${DATE}" >> "$GITHUB_OUTPUT" |
| 62 | |
| 63 | # winget-pkgs convention: file the "please add/update this package" |
| 64 | # Package Request issue *first*, then open the manifest PR that fulfils |
| 65 | # it with "Resolves #N". Doing it the other way round (PR first, issue |
| 66 | # after) reads as "here's a request, and here's the PR that already did |
| 67 | # it", posted seconds apart. |
| 68 | # |
| 69 | # The issue and the PR are authored by two separate PATs, configured as |
| 70 | # the repo secrets WINGET_ISSUE_TOKEN (the Package Request issue) and |
| 71 | # WINGET_PR_TOKEN (the manifest PR). Both need public_repo scope on |
| 72 | # microsoft/winget-pkgs (fork + open issues/PRs). WINGET_PR_TOKEN also |
| 73 | # needs read:org and read:discussion: the "Set the winget PR body" step |
| 74 | # below calls `gh pr edit`, whose GraphQL query resolves org/team and |
| 75 | # discussion fields and fails with a scope error without them. |
| 76 | - name: File the winget Package Request issue |
| 77 | id: issue |
| 78 | shell: bash |
| 79 | env: |
| 80 | GH_TOKEN: ${{ secrets.WINGET_ISSUE_TOKEN }} |
| 81 | run: | |
| 82 | set -euo pipefail |
| 83 | |
| 84 | if [ -z "${GH_TOKEN:-}" ]; then |
| 85 | echo "WINGET_ISSUE_TOKEN is not set. It needs a PAT (public_repo) for the account that should author the Package Request issue." >&2 |
| 86 | exit 1 |
| 87 | fi |
| 88 | |
| 89 | VERSION="${{ steps.release.outputs.version }}" |
| 90 | TAG="${{ steps.release.outputs.tag }}" |
| 91 | |
| 92 | # The release assets, same URLs the update step feeds wingetcreate. |
| 93 | BASE="https://github.com/${REPO}/releases/download/${TAG}" |
| 94 | INSTALLER_AMD64="${BASE}/onde-win-amd64.exe" |
| 95 | INSTALLER_ARM64="${BASE}/onde-win-arm64.exe" |
| 96 | |
| 97 | # winget-pkgs' Package Request is an issue *form* |
| 98 | # (.github/ISSUE_TEMPLATE/package_request.yml): the title must be |
| 99 | # "[Package Request]: ..." and the body has to carry the labelled |
| 100 | # fields below (Installer Url especially — without it a maintainer |
| 101 | # just replies "please provide the installer link"). A free-text |
| 102 | # body lands as Needs-Triage and can't be acted on. |
| 103 | ISSUE_BODY=$(cat <<EOF |
| 104 | Download Page Url: https://github.com/${REPO}/releases/tag/${TAG} |
| 105 | Publisher: OndeInference |
| 106 | Package Name: Onde CLI |
| 107 | Description: Terminal UI to fine-tune models and manage your Onde Inference account. |
| 108 | Package Version: ${VERSION} |
| 109 | Installer Url: ${INSTALLER_AMD64} |
| 110 | Installer Url: ${INSTALLER_ARM64} |
| 111 | EOF |
| 112 | ) |
| 113 | |
| 114 | ISSUE_URL=$(gh issue create \ |
| 115 | --repo microsoft/winget-pkgs \ |
| 116 | --title "[Package Request]: ${PACKAGE_IDENTIFIER} ${VERSION}" \ |
| 117 | --body "$ISSUE_BODY") |
| 118 | |
| 119 | echo "Opened issue ${ISSUE_URL}" |
| 120 | echo "issue_url=${ISSUE_URL}" >> "$GITHUB_OUTPUT" |
| 121 | echo "issue_number=${ISSUE_URL##*/}" >> "$GITHUB_OUTPUT" |
| 122 | |
| 123 | # Leave a gap so the issue and the PR aren't posted seconds apart. |
| 124 | - name: Sebat dulu ... |
| 125 | if: steps.issue.outputs.issue_number != '' |
| 126 | shell: bash |
| 127 | run: sleep $(( RANDOM % 61 + 150 )) |
| 128 | |
| 129 | - name: Check whether the package is already in winget-pkgs |
| 130 | id: exists |
| 131 | shell: bash |
| 132 | env: |
| 133 | GH_TOKEN: ${{ github.token }} |
| 134 | run: | |
| 135 | # manifests are filed under the lowercased first letter of the |
| 136 | # publisher, e.g. manifests/o/OndeInference/onde-cli. |
| 137 | PUBLISHER="${PACKAGE_IDENTIFIER%%.*}" |
| 138 | NAME="${PACKAGE_IDENTIFIER#*.}" |
| 139 | FIRST=$(echo "${PUBLISHER:0:1}" | tr '[:upper:]' '[:lower:]') |
| 140 | PATH_IN_REPO="manifests/${FIRST}/${PUBLISHER}/${NAME}" |
| 141 | |
| 142 | if gh api "repos/microsoft/winget-pkgs/contents/${PATH_IN_REPO}" >/dev/null 2>&1; then |
| 143 | echo "Found ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}; submitting an update." |
| 144 | echo "found=true" >> "$GITHUB_OUTPUT" |
| 145 | else |
| 146 | echo "No ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}; submitting it as a new package." |
| 147 | echo "found=false" >> "$GITHUB_OUTPUT" |
| 148 | fi |
| 149 | |
| 150 | - name: Render manifests for a first submission |
| 151 | if: steps.exists.outputs.found == 'false' |
| 152 | shell: bash |
| 153 | env: |
| 154 | GH_TOKEN: ${{ github.token }} |
| 155 | run: | |
| 156 | TAG="${{ steps.release.outputs.tag }}" |
| 157 | VERSION="${{ steps.release.outputs.version }}" |
| 158 | |
| 159 | mkdir -p artifacts manifests |
| 160 | |
| 161 | gh release download "$TAG" \ |
| 162 | --repo "$REPO" \ |
| 163 | --pattern "onde-win-*.exe.sha256" \ |
| 164 | --dir artifacts/ |
| 165 | |
| 166 | # The schema wants 64 hex characters; the community validation |
| 167 | # pipeline writes them uppercase, so match that. |
| 168 | SHA_AMD64=$(tr -d '[:space:]' < artifacts/onde-win-amd64.exe.sha256 | tr '[:lower:]' '[:upper:]') |
| 169 | SHA_ARM64=$(tr -d '[:space:]' < artifacts/onde-win-arm64.exe.sha256 | tr '[:lower:]' '[:upper:]') |
| 170 | |
| 171 | RELEASE_DATE="${{ steps.release.outputs.date }}" |
| 172 | |
| 173 | for template in packaging/winget/*.yaml.in; do |
| 174 | out="manifests/$(basename "$template" .in)" |
| 175 | sed \ |
| 176 | -e "s|@VERSION@|${VERSION}|g" \ |
| 177 | -e "s|@TAG@|${TAG}|g" \ |
| 178 | -e "s|@REPO@|${REPO}|g" \ |
| 179 | -e "s|@SHA_AMD64@|${SHA_AMD64}|g" \ |
| 180 | -e "s|@SHA_ARM64@|${SHA_ARM64}|g" \ |
| 181 | -e "s|@RELEASE_DATE@|${RELEASE_DATE}|g" \ |
| 182 | "$template" > "$out" |
| 183 | |
| 184 | echo "--- ${out} ---" |
| 185 | cat "$out" |
| 186 | done |
| 187 | |
| 188 | - name: Download wingetcreate |
| 189 | shell: pwsh |
| 190 | run: Invoke-WebRequest -Uri "https://aka.ms/wingetcreate/latest" -OutFile wingetcreate.exe |
| 191 | |
| 192 | - name: Submit new package |
| 193 | id: submit_new |
| 194 | if: steps.exists.outputs.found == 'false' |
| 195 | shell: pwsh |
| 196 | env: |
| 197 | # wingetcreate reads the token from this variable. Passing it as |
| 198 | # --token instead makes the tool warn that the token can end up in |
| 199 | # logs, which on a shared runner is not a warning worth ignoring. |
| 200 | # This is the PR-author account for this repo (see mapping above). |
| 201 | WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }} |
| 202 | run: | |
| 203 | if (-not $env:WINGET_CREATE_GITHUB_TOKEN) { |
| 204 | Write-Error "WINGET_PR_TOKEN is not set. It needs a PAT with public_repo, read:org, and read:discussion scopes so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR, and gh can edit the PR body." |
| 205 | } |
| 206 | |
| 207 | $version = "${{ steps.release.outputs.version }}" |
| 208 | |
| 209 | # Tee stdout so we can scrape the PR URL afterwards. wingetcreate |
| 210 | # prints "Pull request can be found here: <url>" on success, and |
| 211 | # that line is the only handle we get on the PR it just opened. |
| 212 | # --no-open because the runner has no browser to open the PR in. |
| 213 | .\wingetcreate.exe submit manifests ` |
| 214 | --prtitle "New package: $env:PACKAGE_IDENTIFIER version $version" ` |
| 215 | --no-open 2>&1 | Tee-Object -Variable output |
| 216 | |
| 217 | if ($LASTEXITCODE -ne 0) { |
| 218 | Write-Error "wingetcreate submit failed with exit code $LASTEXITCODE" |
| 219 | } |
| 220 | |
| 221 | $match = [regex]::Match(($output -join "`n"), 'https://github\.com/microsoft/winget-pkgs/pull/(\d+)') |
| 222 | if ($match.Success) { |
| 223 | "pr_url=$($match.Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 224 | "pr_number=$($match.Groups[1].Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 225 | } else { |
| 226 | Write-Warning "Could not find the PR URL in wingetcreate output; skipping issue linking." |
| 227 | } |
| 228 | |
| 229 | - name: Submit manifest update |
| 230 | id: submit_update |
| 231 | if: steps.exists.outputs.found == 'true' |
| 232 | shell: pwsh |
| 233 | env: |
| 234 | # PR-author account for this repo (see mapping above). |
| 235 | WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }} |
| 236 | run: | |
| 237 | if (-not $env:WINGET_CREATE_GITHUB_TOKEN) { |
| 238 | Write-Error "WINGET_PR_TOKEN is not set. It needs a PAT with public_repo, read:org, and read:discussion scopes so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR, and gh can edit the PR body." |
| 239 | } |
| 240 | |
| 241 | $tag = "${{ steps.release.outputs.tag }}" |
| 242 | $version = "${{ steps.release.outputs.version }}" |
| 243 | $base = "https://github.com/${env:REPO}/releases/download/$tag" |
| 244 | |
| 245 | # The trailing |x64 and |arm64 tell wingetcreate which installer |
| 246 | # entry each URL replaces. Without them it guesses from the file |
| 247 | # name, and "onde-win-amd64.exe" is not a spelling it recognises. |
| 248 | .\wingetcreate.exe update $env:PACKAGE_IDENTIFIER ` |
| 249 | --version $version ` |
| 250 | --urls "$base/onde-win-amd64.exe|x64" "$base/onde-win-arm64.exe|arm64" ` |
| 251 | --release-notes-url "https://github.com/${env:REPO}/releases/tag/$tag" ` |
| 252 | --release-date "${{ steps.release.outputs.date }}" ` |
| 253 | --prtitle "Update $env:PACKAGE_IDENTIFIER to version $version" ` |
| 254 | --submit ` |
| 255 | --no-open 2>&1 | Tee-Object -Variable output |
| 256 | |
| 257 | if ($LASTEXITCODE -ne 0) { |
| 258 | Write-Error "wingetcreate failed with exit code $LASTEXITCODE" |
| 259 | } |
| 260 | |
| 261 | $match = [regex]::Match(($output -join "`n"), 'https://github\.com/microsoft/winget-pkgs/pull/(\d+)') |
| 262 | if ($match.Success) { |
| 263 | "pr_url=$($match.Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 264 | "pr_number=$($match.Groups[1].Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 265 | } else { |
| 266 | Write-Warning "Could not find the PR URL in wingetcreate output; skipping issue linking." |
| 267 | } |
| 268 | |
| 269 | # wingetcreate has no --prbody flag (only --prtitle), so it always opens |
| 270 | # the PR with the winget-pkgs template: an empty Description and an |
| 271 | # unticked "Linked to an issue" box next to a "Resolves #[Issue Number]" |
| 272 | # placeholder. The issue already exists (filed first, above), so this |
| 273 | # step just rewrites the body to point the PR at it with "Resolves #N". |
| 274 | # |
| 275 | # This must run as the PR author (WINGET_PR_TOKEN) — the account that |
| 276 | # opened the PR via wingetcreate — since only the author (or a repo |
| 277 | # maintainer) can edit it. |
| 278 | - name: Set the winget PR body and link the issue |
| 279 | id: link |
| 280 | if: >- |
| 281 | (steps.submit_new.outputs.pr_number != '') || |
| 282 | (steps.submit_update.outputs.pr_number != '') |
| 283 | shell: bash |
| 284 | env: |
| 285 | GH_TOKEN: ${{ secrets.WINGET_PR_TOKEN }} |
| 286 | run: | |
| 287 | set -euo pipefail |
| 288 | |
| 289 | PR_URL="${{ steps.submit_new.outputs.pr_url || steps.submit_update.outputs.pr_url }}" |
| 290 | ISSUE_NUMBER="${{ steps.issue.outputs.issue_number }}" |
| 291 | VERSION="${{ steps.release.outputs.version }}" |
| 292 | TAG="${{ steps.release.outputs.tag }}" |
| 293 | |
| 294 | if [ -n "$ISSUE_NUMBER" ]; then |
| 295 | CHECKBOX="- [x] Linked to an issue (if applicable)" |
| 296 | RESOLVES="- Resolves #${ISSUE_NUMBER}" |
| 297 | else |
| 298 | CHECKBOX="- [ ] Linked to an issue (if applicable)" |
| 299 | RESOLVES="" |
| 300 | fi |
| 301 | |
| 302 | if [ "${{ steps.exists.outputs.found }}" = "false" ]; then |
| 303 | DESC="Adds ${PACKAGE_IDENTIFIER} version ${VERSION} from ${TAG}." |
| 304 | else |
| 305 | DESC="Updates ${PACKAGE_IDENTIFIER} to version ${VERSION} from ${TAG}." |
| 306 | fi |
| 307 | |
| 308 | # Mirrors the current .github/PULL_REQUEST_TEMPLATE.md; keep the |
| 309 | # checklist items in sync with it (e.g. the 1.12 schema line). |
| 310 | BODY=$(cat <<EOF |
| 311 | ## 📖 Description |
| 312 | ${DESC} |
| 313 | ## ✅ Checklist |
| 314 | - [x] Signed the [Contributor License Agreement](https://cla.opensource.microsoft.com) |
| 315 | ${CHECKBOX} |
| 316 | ${RESOLVES} |
| 317 | ## 📦 Manifest Checklist |
| 318 | - [x] Checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change |
| 319 | - [x] This PR only modifies one (1) manifest |
| 320 | - [x] Validated manifest locally with \`winget validate --manifest <directory>\` |
| 321 | - [x] Tested manifest locally with \`winget install --manifest <directory>\` |
| 322 | - [x] Manifest conforms to the [1.12 schema](https://github.com/microsoft/winget-pkgs/tree/master/doc/manifest/schema/1.12.0) |
| 323 | EOF |
| 324 | ) |
| 325 | |
| 326 | gh pr edit "$PR_URL" --body "$BODY" |
| 327 | echo "Linked ${PR_URL} to issue #${ISSUE_NUMBER:-<none>}" |