-
Notifications
You must be signed in to change notification settings - Fork 1
534 lines (458 loc) · 17.9 KB
/
Copy pathpublish.yml
File metadata and controls
534 lines (458 loc) · 17.9 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
name: Publish
on:
workflow_dispatch:
release:
types: [published]
env:
APP_NAME: semver
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.parse_version.outputs.version }}
major: ${{ steps.parse_version.outputs.major }}
minor: ${{ steps.parse_version.outputs.minor }}
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- id: parse_version
name: Parse the Version
run: |
rm deno.lock
deno install
deno run -A main.ts get
assets:
runs-on: ubuntu-latest
needs: version
permissions:
contents: write
strategy:
matrix:
target:
- name: "x86_64-unknown-linux-gnu"
extension: ""
- name: "x86_64-pc-windows-msvc"
extension: ".exe"
- name: "x86_64-apple-darwin"
extension: ""
- name: "aarch64-apple-darwin"
extension: ""
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Setup
run: |
rm deno.lock
deno install --no-lock
# Binaries are compiled on full Release
- name: Compile
if: github.event_name == 'release'
env:
TARGET: ${{ matrix.target.name }}
EXT: ${{ matrix.target.extension }}
run: |
deno compile --allow-run --allow-env --allow-read --allow-write -o bin/$APP_NAME --target $TARGET main.ts
cd bin && tar -czf $APP_NAME.$TARGET.tar.gz ${APP_NAME}${EXT}
ls -la
# Create ZIP file for Windows (required for winget)
- name: Create Windows ZIP
if: github.event_name == 'release' && matrix.target.name == 'x86_64-pc-windows-msvc'
run: |
cd bin
zip $APP_NAME.${{ matrix.target.name }}.zip ${APP_NAME}.exe
ls -la
- name: Upload Release Asset (tar.gz)
uses: actions/upload-release-asset@v1
if: github.event_name == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./bin/${{ env.APP_NAME }}.${{ matrix.target.name }}.tar.gz
asset_name: ${{ env.APP_NAME }}.${{ matrix.target.name }}.tar.gz
asset_content_type: application/tar+gzip
- name: Upload Release Asset (zip for Windows)
uses: actions/upload-release-asset@v1
if: github.event_name == 'release' && matrix.target.name == 'x86_64-pc-windows-msvc'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./bin/${{ env.APP_NAME }}.${{ matrix.target.name }}.zip
asset_name: ${{ env.APP_NAME }}.${{ matrix.target.name }}.zip
asset_content_type: application/zip
- name: Print Output
if: github.event_name == 'release'
env:
VERSION: ${{ needs.version.outputs.version }}
TARGET: ${{ matrix.target.name }}
DOWNLOAD_URL: ${{ github.event.release.download_url }}
ASSET_NAME: ${{ env.APP_NAME }}.${{ matrix.target.name }}.tar.gz
run: |
URL="https://github.com/Optum/semver-cli/releases/download/${VERSION}/${ASSET_NAME}"
SHA=$(cat ./bin/${{ env.APP_NAME}}.${{ matrix.target.name }}.tar.gz | sha256sum | cut -d " " -f1)
cat >> $GITHUB_STEP_SUMMARY<<EOF
| part | value |
| ---------- | ------------------ |
| name | \`${APP_NAME}\` |
| version | \`${VERSION}\` |
| target | \`${TARGET}\` |
| asset | [\`${ASSET_NAME}\`]($URL) |
#### formula
\`\`\`rb
url "$URL"
sha256 "$SHA"
\`\`\`
EOF
docker:
runs-on: ubuntu-latest
needs: version
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: optum/semver-cli:latest,optum/semver-cli:${{ needs.version.outputs.version }},optum/semver-cli:v${{ needs.version.outputs.major }}.${{ needs.version.outputs.minor }},optum/semver-cli:v${{ needs.version.outputs.major }}
platforms: linux/amd64
homebrew:
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
runs-on: ubuntu-latest
needs:
- version
- assets
permissions:
contents: write
pull-requests: write
env:
GH_TOKEN: ${{ secrets.SEMVER_PUBLISH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.SEMVER_PUBLISH_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Configure Git
run: |
# Configure git
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
gh auth setup-git
- name: Download Release Assets and Generate Formula
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
mkdir -p assets Formula
# Download each asset using GitHub CLI and calculate SHA256
declare -A urls
declare -A shas
for target in "x86_64-unknown-linux-gnu" "x86_64-apple-darwin" "aarch64-apple-darwin"; do
asset_name="semver.${target}.tar.gz"
url="https://github.com/Optum/semver-cli/releases/download/${VERSION}/${asset_name}"
echo "Downloading ${asset_name} using GitHub CLI"
gh release download "${VERSION}" --pattern "${asset_name}" --dir assets --repo Optum/semver-cli
sha=$(sha256sum "assets/${asset_name}" | cut -d " " -f1)
urls[$target]=$url
shas[$target]=$sha
echo "Target: $target, URL: $url, SHA: $sha"
done
# Generate the Homebrew formula
cat > Formula/semver.rb << EOF
# typed: false
# frozen_string_literal: true
# This file was generated by GoReleaser. DO NOT EDIT.
class Semver < Formula
desc "A cli for common semantic versioning operations"
homepage "https://github.com/Optum/semver-cli"
version "${VERSION}"
license "Apache2"
on_macos do
if Hardware::CPU.intel?
url "${urls[x86_64-apple-darwin]}"
sha256 "${shas[x86_64-apple-darwin]}"
def install
bin.install "semver"
end
end
if Hardware::CPU.arm?
url "${urls[aarch64-apple-darwin]}"
sha256 "${shas[aarch64-apple-darwin]}"
def install
bin.install "semver"
end
end
end
on_linux do
if Hardware::CPU.intel?
url "${urls[x86_64-unknown-linux-gnu]}"
sha256 "${shas[x86_64-unknown-linux-gnu]}"
def install
bin.install "semver"
end
end
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
raise "Not yet supported"
end
end
test do
system "#{bin}/semver --version"
end
end
EOF
echo "Generated Formula/semver.rb:"
cat Formula/semver.rb
# Output to GitHub Summary
cat >> $GITHUB_STEP_SUMMARY << EOF
## Homebrew Formula Generated
Successfully generated Homebrew formula for version **${VERSION}**.
### Formula Details
- **Version**: ${VERSION}
- **Platforms**: Linux x86_64, macOS x86_64, macOS ARM64
- **License**: Apache2
### File Generated
\`\`\`ruby
$(cat Formula/semver.rb)
\`\`\`
EOF
# touch 1
- name: Create PR to Homebrew Tap
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
# Clone the homebrew-tap repository
gh repo clone Optum/homebrew-tap homebrew-tap-repo
cd homebrew-tap-repo
# Create a new branch
branch_name="update-semver-${VERSION}"
git checkout -b "${branch_name}"
# Copy the generated formula
cp ../Formula/semver.rb Formula/semver.rb
# Commit and push the changes
git add Formula/semver.rb
git commit -m "Update semver formula to version ${VERSION}"
git push origin "${branch_name}"
# Create the PR
gh pr create \
--title "Update semver formula to version ${VERSION}" \
--body "This PR updates the semver formula to version ${VERSION}.
This PR was automatically generated by the semver-cli release workflow.
Changes:
- Updated version to ${VERSION}
- Updated download URLs and SHA256 hashes for all supported platforms" \
--head "${branch_name}" \
--base main
winget:
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
runs-on: windows-latest
needs:
- version
- assets
permissions:
contents: write
pull-requests: write
env:
GH_TOKEN: ${{ secrets.SEMVER_PUBLISH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.SEMVER_PUBLISH_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
gh auth setup-git
- name: Download Release Asset and Generate Winget Manifests
env:
VERSION: ${{ needs.version.outputs.version }}
shell: bash
run: |
mkdir -p assets manifests
# Download the Windows ZIP asset using GitHub CLI
asset_name="semver.x86_64-pc-windows-msvc.zip"
echo "Downloading ${asset_name} using GitHub CLI"
gh release download "${VERSION}" --pattern "${asset_name}" --dir assets --repo Optum/semver-cli
# Calculate SHA256 (PowerShell command via bash, convert to lowercase)
sha=$(powershell -Command "(Get-FileHash -Algorithm SHA256 assets/${asset_name}).Hash.ToLower()")
echo "SHA256: $sha"
url="https://github.com/Optum/semver-cli/releases/download/${VERSION}/${asset_name}"
echo "URL: $url"
# Get release date from GitHub event (fallback to current date if not available)
release_date="${{ github.event.release.published_at }}"
if [ -z "$release_date" ]; then
release_date=$(date -u +%Y-%m-%d)
else
# Extract just the date portion (YYYY-MM-DD) from the ISO timestamp
release_date=$(echo "$release_date" | cut -d'T' -f1)
fi
echo "Release Date: $release_date"
# Create manifest directory structure
# Winget uses: manifests/<first-letter-lowercase>/<Publisher>/<PackageName>/<Version>/
manifest_dir="manifests/o/Optum/semver/${VERSION}"
mkdir -p "$manifest_dir"
# Generate the installer manifest
cat > "${manifest_dir}/Optum.semver.installer.yaml" << EOF
# yaml-language-server: \$schema=https://aka.ms/winget-manifest.installer.1.6.0.schema.json
PackageIdentifier: Optum.semver
PackageVersion: ${VERSION}
InstallerType: zip
UpgradeBehavior: install
Commands:
- semver
ReleaseDate: ${release_date}
Installers:
- Architecture: x64
NestedInstallerType: portable
NestedInstallerFiles:
- RelativeFilePath: semver.exe
PortableCommandAlias: semver
InstallerUrl: ${url}
InstallerSha256: ${sha}
ManifestType: installer
ManifestVersion: 1.6.0
EOF
# Generate the locale manifest
cat > "${manifest_dir}/Optum.semver.locale.en-US.yaml" << EOF
# yaml-language-server: \$schema=https://aka.ms/winget-manifest.defaultLocale.1.6.0.schema.json
PackageIdentifier: Optum.semver
PackageVersion: ${VERSION}
PackageLocale: en-US
Publisher: Optum
PublisherUrl: https://github.com/Optum
PublisherSupportUrl: https://github.com/Optum/semver-cli/issues
Author: Optum
PackageName: semver
PackageUrl: https://github.com/Optum/semver-cli
License: Apache-2.0
LicenseUrl: https://github.com/Optum/semver-cli/blob/HEAD/LICENSE
Copyright: Copyright (c) Optum
ShortDescription: A technology agnostic cli for common semantic versioning operations
Description: A technology agnostic cli for common semantic versioning operations. Built with Deno.
Moniker: semver
Tags:
- cli
- semver
- semantic-version
- versioning
- deno
ReleaseNotesUrl: https://github.com/Optum/semver-cli/releases/tag/${VERSION}
ManifestType: defaultLocale
ManifestVersion: 1.6.0
EOF
# Generate the version manifest
cat > "${manifest_dir}/Optum.semver.yaml" << EOF
# yaml-language-server: \$schema=https://aka.ms/winget-manifest.version.1.6.0.schema.json
PackageIdentifier: Optum.semver
PackageVersion: ${VERSION}
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.6.0
EOF
echo "Generated manifests:"
ls -la "${manifest_dir}"
cat "${manifest_dir}/Optum.semver.installer.yaml"
cat "${manifest_dir}/Optum.semver.locale.en-US.yaml"
cat "${manifest_dir}/Optum.semver.yaml"
- name: Validate Winget Manifests
env:
VERSION: ${{ needs.version.outputs.version }}
shell: bash
run: |
manifest_dir="manifests/o/Optum/semver/${VERSION}"
# Install winget (if not already available on Windows runner)
# Windows runners typically have winget pre-installed
# Validate manifests using winget
echo "Validating manifests with winget..."
if ! winget validate "${manifest_dir}"; then
echo "::error::Winget manifest validation failed"
exit 1
fi
echo "Validation successful!"
# Output to GitHub Summary
cat >> $GITHUB_STEP_SUMMARY << EOF
## Winget Manifests Generated
Successfully generated Winget manifests for version **${VERSION}**.
### Manifest Details
- **Package Identifier**: Optum.semver
- **Version**: ${VERSION}
- **Architecture**: x64
- **Installer Type**: zip (portable)
### Files Generated
- Optum.semver.installer.yaml
- Optum.semver.locale.en-US.yaml
- Optum.semver.yaml
EOF
- name: Create PR to Winget Repository
env:
VERSION: ${{ needs.version.outputs.version }}
shell: bash
run: |
# Clone the winget-pkgs repository
gh repo clone microsoft/winget-pkgs winget-pkgs-repo
cd winget-pkgs-repo
# Create a new branch
branch_name="Optum.semver-${VERSION}"
git checkout -b "${branch_name}"
# Copy the generated manifests
manifest_dir="../manifests/o/Optum/semver/${VERSION}"
target_dir="manifests/o/Optum/semver/${VERSION}"
mkdir -p "${target_dir}"
cp "${manifest_dir}"/* "${target_dir}/"
# Commit and push the changes
git add "manifests/o/Optum/semver/${VERSION}"
git commit -m "New version: Optum.semver version ${VERSION}"
git push origin "${branch_name}"
# Create the PR
gh pr create \
--repo microsoft/winget-pkgs \
--title "New version: Optum.semver version ${VERSION}" \
--body "This PR adds Optum.semver version ${VERSION} to the Windows Package Manager repository.
**Package Information:**
- **Package Identifier**: Optum.semver
- **Version**: ${VERSION}
- **Publisher**: Optum
- **License**: Apache-2.0
**Changes:**
- Added new package version ${VERSION}
- Installer type: zip (portable)
- Architecture: x64
This PR was automatically generated by the semver-cli release workflow.
**Release Notes**: https://github.com/Optum/semver-cli/releases/tag/${VERSION}" \
--head "${branch_name}" \
--base master
tags:
if: ${{ github.event.release.prerelease == false }}
runs-on: ubuntu-latest
needs:
- version
- assets
- docker
- homebrew
- winget
permissions:
contents: write
id-token: write
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
steps:
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
gh auth setup-git
- uses: actions/checkout@v4
- name: Create Tags
run: |
git tag "v${{ needs.version.outputs.version }}"
git push origin --tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}