|
| 1 | +name: Create Winget Manifest |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to create manifest for (e.g., v3.68.0). Leave empty to use latest release.' |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + release: |
| 11 | + types: [published] |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +env: |
| 17 | + PACKAGE_IDENTIFIER: ch.LosslessCut |
| 18 | + WINGET_PKGS_REPO: microsoft/winget-pkgs |
| 19 | + MANIFEST_REPO: chrishuan9/Lossless-winget-manifest |
| 20 | + WINGET_RLS_REPO: chrishuan9/LosslessCut-winget-rls |
| 21 | + GITHUB_USERNAME: chrishuan9 |
| 22 | + |
| 23 | +jobs: |
| 24 | + create_manifest: |
| 25 | + runs-on: windows-latest |
| 26 | + outputs: |
| 27 | + version: ${{ steps.version.outputs.version_without_v }} |
| 28 | + version_with_v: ${{ steps.version.outputs.version_with_v }} |
| 29 | + steps: |
| 30 | + - name: Checkout Repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Generate GitHub App Token |
| 34 | + id: app-token |
| 35 | + uses: actions/create-github-app-token@v1 |
| 36 | + with: |
| 37 | + app-id: ${{ secrets.APP_ID }} |
| 38 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 39 | + owner: ${{ env.GITHUB_USERNAME }} |
| 40 | + repositories: "LosslessCut-winget-rls,Lossless-winget-manifest,winget-pkgs" |
| 41 | + |
| 42 | + - name: Determine Version |
| 43 | + id: version |
| 44 | + shell: pwsh |
| 45 | + run: | |
| 46 | + if ("${{ github.event_name }}" -eq "release") { |
| 47 | + $version = "${{ github.event.release.tag_name }}" |
| 48 | + } elseif ("${{ github.event.inputs.version }}" -ne "") { |
| 49 | + $version = "${{ github.event.inputs.version }}" |
| 50 | + } else { |
| 51 | + # Get latest release tag from this repo |
| 52 | + $latestRelease = gh api repos/${{ env.WINGET_RLS_REPO }}/releases/latest --jq '.tag_name' |
| 53 | + $version = $latestRelease |
| 54 | + } |
| 55 | +
|
| 56 | + # Remove 'losslesscut-' prefix if present (releases are tagged as losslesscut-v3.68.0) |
| 57 | + $version = $version -replace '^losslesscut-', '' |
| 58 | +
|
| 59 | + # Store both with and without 'v' prefix |
| 60 | + $versionWithV = if ($version -match '^v') { $version } else { "v$version" } |
| 61 | + $versionWithoutV = $version -replace '^v', '' |
| 62 | +
|
| 63 | + Write-Host "Version with v: $versionWithV" |
| 64 | + Write-Host "Version without v: $versionWithoutV" |
| 65 | +
|
| 66 | + "version_with_v=$versionWithV" >> $env:GITHUB_OUTPUT |
| 67 | + "version_without_v=$versionWithoutV" >> $env:GITHUB_OUTPUT |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 70 | + |
| 71 | + - name: Construct Installer URL and Get SHA256 |
| 72 | + id: installer |
| 73 | + shell: pwsh |
| 74 | + run: | |
| 75 | + $version = "${{ steps.version.outputs.version_with_v }}" |
| 76 | + $installerUrl = "https://github.com/${{ env.WINGET_RLS_REPO }}/releases/download/losslesscut-$version/losslesscut-$version.zip" |
| 77 | +
|
| 78 | + Write-Host "Installer URL: $installerUrl" |
| 79 | +
|
| 80 | + # Download file to calculate SHA256 |
| 81 | + $tempFile = Join-Path $env:TEMP "losslesscut-$version.zip" |
| 82 | + Write-Host "Downloading to calculate SHA256..." |
| 83 | + Invoke-WebRequest -Uri $installerUrl -OutFile $tempFile |
| 84 | +
|
| 85 | + $sha256 = (Get-FileHash -Path $tempFile -Algorithm SHA256).Hash |
| 86 | + Write-Host "SHA256: $sha256" |
| 87 | +
|
| 88 | + Remove-Item $tempFile -Force |
| 89 | +
|
| 90 | + "installer_url=$installerUrl" >> $env:GITHUB_OUTPUT |
| 91 | + "sha256=$sha256" >> $env:GITHUB_OUTPUT |
| 92 | +
|
| 93 | + - name: Get Release Date |
| 94 | + id: release_date |
| 95 | + shell: pwsh |
| 96 | + run: | |
| 97 | + $version = "${{ steps.version.outputs.version_with_v }}" |
| 98 | + $releaseInfo = gh api repos/${{ env.WINGET_RLS_REPO }}/releases/tags/losslesscut-$version --jq '.published_at' |
| 99 | + $releaseDate = ([datetime]$releaseInfo).ToString("yyyy-MM-dd") |
| 100 | + Write-Host "Release Date: $releaseDate" |
| 101 | + "release_date=$releaseDate" >> $env:GITHUB_OUTPUT |
| 102 | + env: |
| 103 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 104 | + |
| 105 | + - name: Install wingetcreate |
| 106 | + shell: pwsh |
| 107 | + run: | |
| 108 | + Invoke-WebRequest -Uri https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe |
| 109 | +
|
| 110 | + - name: Create Manifest Directory |
| 111 | + id: manifest_dir |
| 112 | + shell: pwsh |
| 113 | + run: | |
| 114 | + $version = "${{ steps.version.outputs.version_without_v }}" |
| 115 | + $manifestDir = "manifests/c/ch/LosslessCut/$version" |
| 116 | + New-Item -ItemType Directory -Path $manifestDir -Force |
| 117 | + "manifest_dir=$manifestDir" >> $env:GITHUB_OUTPUT |
| 118 | +
|
| 119 | + - name: Generate Manifest with wingetcreate |
| 120 | + shell: pwsh |
| 121 | + run: | |
| 122 | + $version = "${{ steps.version.outputs.version_without_v }}" |
| 123 | + $installerUrl = "${{ steps.installer.outputs.installer_url }}" |
| 124 | + $manifestDir = "${{ steps.manifest_dir.outputs.manifest_dir }}" |
| 125 | +
|
| 126 | + Write-Host "Generating manifest for version $version" |
| 127 | + Write-Host "Installer URL: $installerUrl" |
| 128 | +
|
| 129 | + ./wingetcreate.exe update ${{ env.PACKAGE_IDENTIFIER }} ` |
| 130 | + --urls $installerUrl ` |
| 131 | + --version $version ` |
| 132 | + --out $manifestDir ` |
| 133 | + --token ${{ steps.app-token.outputs.token }} |
| 134 | +
|
| 135 | + Write-Host "Generated manifest files:" |
| 136 | + Get-ChildItem -Path $manifestDir -Recurse |
| 137 | + env: |
| 138 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 139 | + |
| 140 | + - name: Fix Release Date in Manifest |
| 141 | + shell: pwsh |
| 142 | + run: | |
| 143 | + $manifestDir = "${{ steps.manifest_dir.outputs.manifest_dir }}" |
| 144 | + $releaseDate = "${{ steps.release_date.outputs.release_date }}" |
| 145 | + $installerFile = Join-Path $manifestDir "${{ env.PACKAGE_IDENTIFIER }}.installer.yaml" |
| 146 | +
|
| 147 | + if (Test-Path $installerFile) { |
| 148 | + $content = Get-Content $installerFile -Raw |
| 149 | + if ($content -match 'ReleaseDate:') { |
| 150 | + $content = $content -replace 'ReleaseDate:.*', "ReleaseDate: $releaseDate" |
| 151 | + } else { |
| 152 | + $content = $content -replace '(ManifestType: installer)', "ReleaseDate: $releaseDate`n`$1" |
| 153 | + } |
| 154 | + Set-Content -Path $installerFile -Value $content -NoNewline |
| 155 | + Write-Host "Updated ReleaseDate in installer manifest" |
| 156 | + } |
| 157 | +
|
| 158 | + - name: Update Locale Manifest URLs |
| 159 | + shell: pwsh |
| 160 | + run: | |
| 161 | + $manifestDir = "${{ steps.manifest_dir.outputs.manifest_dir }}" |
| 162 | + $version = "${{ steps.version.outputs.version_with_v }}" |
| 163 | + $localeFile = Join-Path $manifestDir "${{ env.PACKAGE_IDENTIFIER }}.locale.en-US.yaml" |
| 164 | +
|
| 165 | + if (Test-Path $localeFile) { |
| 166 | + $content = Get-Content $localeFile -Raw |
| 167 | +
|
| 168 | + $releaseNotesUrl = "https://github.com/${{ env.WINGET_RLS_REPO }}/releases/tag/losslesscut-$version" |
| 169 | + $content = $content -replace 'ReleaseNotesUrl:.*', "ReleaseNotesUrl: $releaseNotesUrl" |
| 170 | + $content = $content -replace 'PackageUrl:.*', "PackageUrl: $releaseNotesUrl" |
| 171 | +
|
| 172 | + Set-Content -Path $localeFile -Value $content -NoNewline |
| 173 | + Write-Host "Updated URLs in locale manifest" |
| 174 | + } |
| 175 | +
|
| 176 | + - name: Display Generated Manifests |
| 177 | + shell: pwsh |
| 178 | + run: | |
| 179 | + $manifestDir = "${{ steps.manifest_dir.outputs.manifest_dir }}" |
| 180 | + Get-ChildItem -Path $manifestDir | ForEach-Object { |
| 181 | + Write-Host "=== $($_.Name) ===" |
| 182 | + Get-Content $_.FullName |
| 183 | + Write-Host "" |
| 184 | + } |
| 185 | +
|
| 186 | + - name: Upload Manifest Artifacts |
| 187 | + uses: actions/upload-artifact@v4 |
| 188 | + with: |
| 189 | + name: winget-manifest |
| 190 | + path: manifests/ |
| 191 | + |
| 192 | + push_to_manifest_repo: |
| 193 | + needs: create_manifest |
| 194 | + runs-on: ubuntu-latest |
| 195 | + steps: |
| 196 | + - name: Generate GitHub App Token |
| 197 | + id: app-token |
| 198 | + uses: actions/create-github-app-token@v1 |
| 199 | + with: |
| 200 | + app-id: ${{ secrets.APP_ID }} |
| 201 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 202 | + owner: chrishuan9 |
| 203 | + repositories: "Lossless-winget-manifest" |
| 204 | + |
| 205 | + - name: Download Manifest Artifacts |
| 206 | + uses: actions/download-artifact@v4 |
| 207 | + with: |
| 208 | + name: winget-manifest |
| 209 | + path: manifests/ |
| 210 | + |
| 211 | + - name: Get Version from Manifest |
| 212 | + id: get_version |
| 213 | + run: | |
| 214 | + VERSION=$(ls manifests/c/ch/LosslessCut/) |
| 215 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 216 | +
|
| 217 | + - name: Clone Manifest Repo |
| 218 | + run: | |
| 219 | + git clone https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/chrishuan9/Lossless-winget-manifest.git manifest-repo |
| 220 | +
|
| 221 | + - name: Copy Manifest Files |
| 222 | + run: | |
| 223 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 224 | + mkdir -p manifest-repo/manifests/c/ch/LosslessCut/$VERSION |
| 225 | + cp -r manifests/c/ch/LosslessCut/$VERSION/* manifest-repo/manifests/c/ch/LosslessCut/$VERSION/ |
| 226 | +
|
| 227 | + - name: Commit and Push to Manifest Repo |
| 228 | + run: | |
| 229 | + cd manifest-repo |
| 230 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 231 | +
|
| 232 | + git config user.name "github-actions[bot]" |
| 233 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 234 | +
|
| 235 | + git add . |
| 236 | + git diff --staged --quiet || git commit -m "Add manifest for LosslessCut $VERSION" |
| 237 | + git push |
| 238 | +
|
| 239 | + create_winget_pr: |
| 240 | + needs: [create_manifest, push_to_manifest_repo] |
| 241 | + runs-on: ubuntu-latest |
| 242 | + steps: |
| 243 | + - name: Generate GitHub App Token |
| 244 | + id: app-token |
| 245 | + uses: actions/create-github-app-token@v1 |
| 246 | + with: |
| 247 | + app-id: ${{ secrets.APP_ID }} |
| 248 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 249 | + owner: chrishuan9 |
| 250 | + repositories: "winget-pkgs" |
| 251 | + |
| 252 | + - name: Download Manifest Artifacts |
| 253 | + uses: actions/download-artifact@v4 |
| 254 | + with: |
| 255 | + name: winget-manifest |
| 256 | + path: manifests/ |
| 257 | + |
| 258 | + - name: Get Version from Manifest |
| 259 | + id: get_version |
| 260 | + run: | |
| 261 | + VERSION=$(ls manifests/c/ch/LosslessCut/) |
| 262 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 263 | +
|
| 264 | + - name: Ensure Fork Exists |
| 265 | + run: | |
| 266 | + # Check if fork exists, if not create it |
| 267 | + if ! gh repo view chrishuan9/winget-pkgs &>/dev/null; then |
| 268 | + echo "Forking microsoft/winget-pkgs..." |
| 269 | + gh repo fork microsoft/winget-pkgs --clone=false |
| 270 | + else |
| 271 | + echo "Fork already exists" |
| 272 | + fi |
| 273 | + env: |
| 274 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 275 | + |
| 276 | + - name: Clone Fork and Create Branch |
| 277 | + id: branch |
| 278 | + run: | |
| 279 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 280 | + BRANCH_NAME="ch.LosslessCut-$VERSION-$(uuidgen | cut -d'-' -f1-4)" |
| 281 | +
|
| 282 | + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 283 | +
|
| 284 | + git clone https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/chrishuan9/winget-pkgs.git winget-fork |
| 285 | + cd winget-fork |
| 286 | +
|
| 287 | + # Sync fork with upstream |
| 288 | + git remote add upstream https://github.com/microsoft/winget-pkgs.git |
| 289 | + git fetch upstream |
| 290 | + git checkout master |
| 291 | + git reset --hard upstream/master |
| 292 | + git push origin master --force |
| 293 | +
|
| 294 | + # Create new branch |
| 295 | + git checkout -b $BRANCH_NAME |
| 296 | +
|
| 297 | + - name: Copy Manifest to Fork |
| 298 | + run: | |
| 299 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 300 | + mkdir -p winget-fork/manifests/c/ch/LosslessCut/$VERSION |
| 301 | + cp -r manifests/c/ch/LosslessCut/$VERSION/* winget-fork/manifests/c/ch/LosslessCut/$VERSION/ |
| 302 | +
|
| 303 | + - name: Commit and Push to Fork |
| 304 | + run: | |
| 305 | + cd winget-fork |
| 306 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 307 | + BRANCH_NAME="${{ steps.branch.outputs.branch_name }}" |
| 308 | +
|
| 309 | + git config user.name "github-actions[bot]" |
| 310 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 311 | +
|
| 312 | + git add . |
| 313 | + git commit -m "New Version: ch.LosslessCut version $VERSION" |
| 314 | + git push origin $BRANCH_NAME |
| 315 | +
|
| 316 | + - name: Create Pull Request |
| 317 | + run: | |
| 318 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 319 | + BRANCH_NAME="${{ steps.branch.outputs.branch_name }}" |
| 320 | +
|
| 321 | + PR_TITLE="New Version: ch.LosslessCut version $VERSION" |
| 322 | +
|
| 323 | + PR_BODY=$(cat << 'EOF' |
| 324 | + Checklist for Pull Requests |
| 325 | + - [x] Have you signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs)? |
| 326 | + - [x] Is there a linked Issue? |
| 327 | +
|
| 328 | + Manifests |
| 329 | + - [x] Have you checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change? |
| 330 | + - [x] This PR only modifies one (1) manifest |
| 331 | + - [x] Have you [validated](https://github.com/microsoft/winget-pkgs/blob/master/doc/Authoring.md#validation) your manifest locally with `winget validate --manifest <path>`? |
| 332 | + - [x] Have you tested your manifest locally with `winget install --manifest <path>`? |
| 333 | + - [x] Does your manifest conform to the [1.10 schema](https://github.com/microsoft/winget-pkgs/tree/master/doc/manifest/schema/1.10.0)? |
| 334 | +
|
| 335 | + Note: `<path>` is the directory's name containing the manifest you're submitting. |
| 336 | +
|
| 337 | + --- |
| 338 | +
|
| 339 | + ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-pkgs/pull/) |
| 340 | + EOF |
| 341 | + ) |
| 342 | +
|
| 343 | + gh pr create \ |
| 344 | + --repo microsoft/winget-pkgs \ |
| 345 | + --head "chrishuan9:$BRANCH_NAME" \ |
| 346 | + --base master \ |
| 347 | + --title "$PR_TITLE" \ |
| 348 | + --body "$PR_BODY" |
| 349 | + env: |
| 350 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
0 commit comments