Skip to content

Commit 7f0ae1b

Browse files
authored
Merge branch 'main' into dependabot/docker/denoland/deno-alpine-2.5.0
2 parents 842225d + ea08ac2 commit 7f0ae1b

File tree

2 files changed

+152
-2
lines changed

2 files changed

+152
-2
lines changed

.github/workflows/publish.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,158 @@ jobs:
128128
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 }}
129129
platforms: linux/amd64
130130

131+
homebrew:
132+
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
133+
runs-on: ubuntu-latest
134+
needs:
135+
- version
136+
- assets
137+
permissions:
138+
contents: write
139+
pull-requests: write
140+
env:
141+
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
142+
steps:
143+
- uses: actions/checkout@v4
144+
145+
- name: Download Release Assets and Generate Formula
146+
env:
147+
VERSION: ${{ needs.version.outputs.version }}
148+
run: |
149+
mkdir -p assets Formula
150+
151+
# Download each asset using GitHub CLI and calculate SHA256
152+
declare -A urls
153+
declare -A shas
154+
155+
for target in "x86_64-unknown-linux-gnu" "x86_64-apple-darwin" "aarch64-apple-darwin"; do
156+
asset_name="semver.${target}.tar.gz"
157+
url="https://github.com/Optum/semver-cli/releases/download/${VERSION}/${asset_name}"
158+
echo "Downloading ${asset_name} using GitHub CLI"
159+
gh release download "${VERSION}" --pattern "${asset_name}" --dir assets --repo Optum/semver-cli
160+
sha=$(sha256sum "assets/${asset_name}" | cut -d " " -f1)
161+
urls[$target]=$url
162+
shas[$target]=$sha
163+
echo "Target: $target, URL: $url, SHA: $sha"
164+
done
165+
166+
# Generate the Homebrew formula
167+
cat > Formula/semver.rb << EOF
168+
# typed: false
169+
# frozen_string_literal: true
170+
171+
# This file was generated by GoReleaser. DO NOT EDIT.
172+
class Semver < Formula
173+
desc "A cli for common semantic versioning operations"
174+
homepage "https://github.com/Optum/semver-cli"
175+
version "${VERSION}"
176+
license "Apache2"
177+
178+
on_macos do
179+
if Hardware::CPU.intel?
180+
url "${urls[x86_64-apple-darwin]}"
181+
sha256 "${shas[x86_64-apple-darwin]}"
182+
183+
def install
184+
bin.install "semver"
185+
end
186+
end
187+
if Hardware::CPU.arm?
188+
url "${urls[aarch64-apple-darwin]}"
189+
sha256 "${shas[aarch64-apple-darwin]}"
190+
191+
def install
192+
bin.install "semver"
193+
end
194+
end
195+
end
196+
197+
on_linux do
198+
if Hardware::CPU.intel?
199+
url "${urls[x86_64-unknown-linux-gnu]}"
200+
sha256 "${shas[x86_64-unknown-linux-gnu]}"
201+
202+
def install
203+
bin.install "semver"
204+
end
205+
end
206+
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
207+
raise "Not yet supported"
208+
end
209+
end
210+
211+
test do
212+
system "#{bin}/semver --version"
213+
end
214+
end
215+
EOF
216+
217+
echo "Generated Formula/semver.rb:"
218+
cat Formula/semver.rb
219+
220+
# Output to GitHub Summary
221+
cat >> $GITHUB_STEP_SUMMARY << EOF
222+
## Homebrew Formula Generated
223+
224+
Successfully generated Homebrew formula for version **${VERSION}**.
225+
226+
### Formula Details
227+
- **Version**: ${VERSION}
228+
- **Platforms**: Linux x86_64, macOS x86_64, macOS ARM64
229+
- **License**: Apache2
230+
231+
### File Generated
232+
\`\`\`ruby
233+
$(cat Formula/semver.rb)
234+
\`\`\`
235+
EOF
236+
237+
- name: Create PR to Homebrew Tap
238+
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
239+
env:
240+
VERSION: ${{ needs.version.outputs.version }}
241+
run: |
242+
# Configure git
243+
git config --global user.name 'github-actions[bot]'
244+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
245+
246+
# Clone the homebrew-tap repository
247+
gh repo clone Optum/homebrew-tap homebrew-tap-repo
248+
cd homebrew-tap-repo
249+
250+
# Create a new branch
251+
branch_name="update-semver-${VERSION}"
252+
git checkout -b "${branch_name}"
253+
254+
# Copy the generated formula
255+
cp ../Formula/semver.rb Formula/semver.rb
256+
257+
# Commit and push the changes
258+
git add Formula/semver.rb
259+
git commit -m "Update semver formula to version ${VERSION}"
260+
git push origin "${branch_name}"
261+
262+
# Create the PR
263+
gh pr create \
264+
--title "Update semver formula to version ${VERSION}" \
265+
--body "This PR updates the semver formula to version ${VERSION}.
266+
267+
This PR was automatically generated by the semver-cli release workflow.
268+
269+
Changes:
270+
- Updated version to ${VERSION}
271+
- Updated download URLs and SHA256 hashes for all supported platforms" \
272+
--head "${branch_name}" \
273+
--base main
274+
131275
tags:
132276
if: ${{ github.event.release.prerelease == false }}
133277
runs-on: ubuntu-latest
134278
needs:
135279
- version
136280
- assets
137281
- docker
282+
- homebrew
138283
permissions:
139284
contents: write
140285
id-token: write

src/util/increment.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export function increment(options: IncrementOptions) {
4141
? {
4242
...inc(version, "pre", { prerelease, build }),
4343
prerelease: pre,
44-
} : {
44+
}
45+
: {
4546
...version,
4647
prerelease: version.prerelease ?? [],
4748
build: build ? build.split(".") : version.build ?? [],
@@ -105,7 +106,11 @@ function bumpPrerelease(
105106
const identifierValues = parsePrerelease(identifier);
106107
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
107108
// 1.2.0-beta.foobar or 1.2.0-beta bumps to 1.2.0-beta.0
108-
if (prereleaseValues[0] !== identifierValues[0] || isNaN(prereleaseValues[1] as number) || !isNaN(identifierValues[1] as number)) {
109+
if (
110+
prereleaseValues[0] !== identifierValues[0] ||
111+
isNaN(prereleaseValues[1] as number) ||
112+
!isNaN(identifierValues[1] as number)
113+
) {
109114
return [identifierValues[0], identifierValues[1] ?? 0];
110115
} else {
111116
return prereleaseValues;

0 commit comments

Comments
 (0)