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