Skip to content

Commit 8a6cc7d

Browse files
committed
Update release workflow
1 parent 6b2ae6b commit 8a6cc7d

File tree

5 files changed

+97
-59
lines changed

5 files changed

+97
-59
lines changed

.github/release.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,5 @@ jobs:
2222
ruby-version: ${{ matrix.ruby-version }}
2323
bundler-cache: true
2424

25-
- name: Run Standard (linting)
26-
run: bundle exec rake standard
27-
28-
- name: Run RSpec (tests)
29-
run: bundle exec rake spec
25+
- name: Run test suite
26+
run: ./bin/test

.github/workflows/release.yml

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,73 @@ name: Release
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
5+
branches:
6+
- "release/*"
77

88
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
ruby-version: ['3.1', '3.2', '3.3', '3.4']
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Ruby ${{ matrix.ruby-version }}
21+
uses: ruby/setup-ruby@v1
22+
with:
23+
ruby-version: ${{ matrix.ruby-version }}
24+
bundler-cache: true
25+
26+
- name: Run test suite
27+
run: ./bin/test
28+
929
release:
30+
needs: test
1031
runs-on: ubuntu-latest
1132
permissions:
1233
contents: write
34+
env:
35+
BUNDLE_WITHOUT: development
1336
steps:
14-
- uses: actions/checkout@v4
15-
16-
- name: Create Release with Auto-Generated Notes
17-
run: |
18-
gh release create ${{ github.ref_name }} \
19-
--title "Release ${{ github.ref_name }}" \
20-
--generate-notes
21-
env:
22-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
- uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
40+
41+
- uses: ruby/setup-ruby@v1
42+
with:
43+
ruby-version: "3.2"
44+
bundler-cache: true
45+
46+
- name: Determine version
47+
id: version
48+
run: |
49+
VERSION=$(bundle exec ruby -e "require_relative 'lib/ruby_llm/schema/version'; print RubyLlm::Schema::VERSION")
50+
echo "value=$VERSION" >> "$GITHUB_OUTPUT"
51+
52+
- name: Configure git
53+
run: |
54+
git config user.name "github-actions[bot]"
55+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
56+
57+
- name: Create and push tag
58+
run: |
59+
git tag "v${{ steps.version.outputs.value }}"
60+
git push origin "v${{ steps.version.outputs.value }}"
61+
62+
- name: Create GitHub release
63+
uses: softprops/action-gh-release@v2
64+
with:
65+
tag_name: "v${{ steps.version.outputs.value }}"
66+
generate_release_notes: true
67+
68+
- name: Build gem
69+
run: gem build ruby_llm-schema.gemspec
70+
71+
- name: Publish to RubyGems
72+
env:
73+
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
74+
run: gem push "ruby_llm-schema-${{ steps.version.outputs.value }}.gem"

bin/test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
bundle exec rake standard
5+
bundle exec rake spec

lib/tasks/release.rake

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
namespace :release do
2-
desc "Release a new version of the gem"
3-
task :version, [:message] do |t, args|
4-
# Load the current version from version.rb
5-
require_relative "../../lib/ruby_llm/schema/version"
6-
version = RubyLlm::Schema::VERSION
7-
8-
puts "Releasing version #{version}..."
9-
10-
# Create git tag with optional message
11-
# rake release:version["Fix critical bug in schema validation"]
12-
if args[:message]
13-
system "git tag -a v#{version} -m \"#{args[:message]}\""
14-
puts "Created annotated tag v#{version} with message: #{args[:message]}"
15-
else
16-
system "git tag v#{version}"
17-
puts "Created lightweight tag v#{version}"
2+
desc "Prepare and push the release branch to trigger the automated pipeline"
3+
task :prepare do
4+
abort "Git working directory not clean. Commit or stash changes first." unless `git status --porcelain`.strip.empty?
5+
abort "Not on main branch. Releases must be run from main branch" unless `git rev-parse --abbrev-ref HEAD`.strip == "main"
6+
7+
require_relative "../ruby_llm/schema/version"
8+
version = RubyLlm::Schema::VERSION or abort "Could not determine version"
9+
10+
branch = "release/#{version}"
11+
12+
if system("git rev-parse --quiet --verify refs/tags/v#{version} > /dev/null 2>&1")
13+
abort "Tag v#{version} already exists. Bump the version first."
14+
end
15+
16+
if system("git show-ref --verify --quiet refs/heads/#{branch}")
17+
abort "Local branch #{branch} already exists. Remove it or choose a new version."
18+
end
19+
20+
sh "git fetch origin"
21+
22+
if system("git ls-remote --exit-code --heads origin #{branch} > /dev/null 2>&1")
23+
abort "Release branch #{branch} already exists on origin. Remove it or choose a new version."
1824
end
1925

20-
system "git push origin main"
21-
system "git push origin v#{version}"
26+
sh "git checkout -b #{branch}"
27+
sh "git push -u origin #{branch}"
2228

23-
system "gem build ruby_llm-schema.gemspec"
24-
system "gem push ruby_llm-schema-#{version}.gem"
25-
system "rm ruby_llm-schema-#{version}.gem"
29+
puts "Release branch #{branch} pushed. GitHub Actions will run tests and publish if they pass."
30+
ensure
31+
system "git checkout main"
2632
end
2733
end

0 commit comments

Comments
 (0)