Skip to content

Commit 0eeb090

Browse files
committed
Release using RubyGems Trusted Publishing
1 parent 5459abb commit 0eeb090

4 files changed

Lines changed: 23 additions & 24 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ jobs:
2424
steps:
2525
- name: Checkout code
2626
if: github.event_name == 'push'
27-
uses: actions/checkout@v4
27+
uses: actions/checkout@v5
28+
with:
29+
persist-credentials: false
2830

2931
- name: Checkout PR code
3032
if: github.event_name == 'pull_request_target'
@@ -50,7 +52,9 @@ jobs:
5052
steps:
5153
- name: Checkout code
5254
if: github.event_name == 'push'
53-
uses: actions/checkout@v4
55+
uses: actions/checkout@v5
56+
with:
57+
persist-credentials: false
5458

5559
- name: Checkout PR code
5660
if: github.event_name == 'pull_request_target'
@@ -69,4 +73,4 @@ jobs:
6973
run: bundle exec standardrb
7074

7175
- name: Build gem
72-
run: gem build daemon_controller.gemspec
76+
run: bundle exec rake gem

.github/workflows/release.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ jobs:
1616
attestations: write
1717
steps:
1818
- name: Checkout code
19-
uses: actions/checkout@v4
19+
uses: actions/checkout@v5
20+
with:
21+
persist-credentials: false
2022

2123
- name: Set up Ruby
2224
uses: ruby/setup-ruby@v1
@@ -37,20 +39,14 @@ jobs:
3739
exit 1
3840
fi
3941
40-
- name: Build gem
41-
run: gem build daemon_controller.gemspec
42+
- uses: rubygems/release-gem@v1
4243

4344
- name: Create attestation
4445
uses: actions/attest-build-provenance@v2
4546
with:
46-
subject-path: "daemon_controller-*.gem"
47-
48-
- name: Push gem to RubyGems
49-
run: gem push daemon_controller-*.gem
50-
env:
51-
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
47+
subject-path: "pkg/daemon_controller-*.gem"
5248

5349
- name: Create GitHub release
54-
run: gh release create "$GITHUB_REF_NAME" *.gem --title "$GITHUB_REF_NAME" --notes-from-tag
50+
run: gh release create "$GITHUB_REF_NAME" pkg/*.gem --title "$GITHUB_REF_NAME" --notes-from-tag
5551
env:
5652
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.vscode
33
*.gem
4+
/pkg
45
spec/echo_server.log
56
spec/echo_server.pid
67
spec/echo_server.pid.lock

Rakefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ task :test do
88
ruby "-S rspec spec/*_spec.rb"
99
end
1010

11-
desc "Build & upload gem"
12-
task "package:release" do
13-
sh "git tag -s release-#{PACKAGE_VERSION}"
14-
sh "gem build #{PACKAGE_NAME}.gemspec"
15-
puts "Proceed with pushing tag to Github and uploading the gem? [y/n]"
16-
if $stdin.readline == "y\n"
17-
sh "git push origin release-#{PACKAGE_VERSION}"
18-
sh "gem push #{PACKAGE_NAME}-#{PACKAGE_VERSION}.gem"
19-
else
20-
puts "Did not upload the gem."
21-
end
11+
desc "Build gem"
12+
task :gem do
13+
mkdir_p "pkg"
14+
sh "gem build daemon_controller.gemspec -o pkg/#{PACKAGE_NAME}-#{PACKAGE_VERSION}.gem"
15+
end
16+
17+
desc "Build release artifacts"
18+
task release: :gem do
19+
sh "gem push pkg/#{PACKAGE_NAME}-#{PACKAGE_VERSION}.gem"
2220
end

0 commit comments

Comments
 (0)