Skip to content

Commit 718891b

Browse files
authored
Merge pull request #21 from rubocop/trusted-publishing
Use Rubygems Trusted Publishers to publish
2 parents d3e5455 + 5e55cfe commit 718891b

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

.github/workflows/publish.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish
2+
on:
3+
push:
4+
branches: master
5+
paths: lib/rubocop/rspec/version.rb
6+
jobs:
7+
publish:
8+
name: Publish to RubyGems
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
id-token: write
13+
pull-requests: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Ruby
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
bundler-cache: true
20+
ruby-version: ruby
21+
- uses: rubygems/release-gem@v1
22+
- name: Create a GitHub release
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: |
26+
bundle exec rake create_release_notes
27+
gh release create $(git tag --points-at @) \
28+
--title "RuboCop RSpec $(git tag --points-at @)" \
29+
--notes-file relnotes.md
30+
- name: Replace version in Antora config
31+
run: |
32+
sed -i 's/version:.*$/version: ~/' docs/antora.yml
33+
if ! git diff --exit-code docs/antora.yml; then
34+
git config user.name "${GITHUB_ACTOR}"
35+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
36+
git checkout -b switch-docs-version
37+
git add docs/antora.yml
38+
git commit -m "Switch docs version back"
39+
git push -u origin switch-docs-version
40+
gh pr create --fill --head switch-docs-version
41+
fi

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ coverage
2323

2424
# vscode generated
2525
.vscode
26+
27+
/relnotes.md

tasks/create_release_notes.rake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
desc 'Create release notes for the most recent version.'
4+
task :create_release_notes do
5+
CreateReleaseNotes.call
6+
end
7+
8+
# Create release notes from the most recent version in the CHANGELOG.md file.
9+
module CreateReleaseNotes
10+
module_function
11+
12+
def call
13+
release_notes = new_version_changes.strip
14+
contributor_links = user_links(release_notes)
15+
16+
File.open('relnotes.md', 'w') do |file|
17+
file << release_notes
18+
file << "\n\n"
19+
file << contributor_links
20+
file << "\n"
21+
end
22+
end
23+
24+
def new_version_changes
25+
changelog = File.read('CHANGELOG.md')
26+
_, _, new_changes, _older_changes = changelog.split(/^## .*$/, 4)
27+
new_changes
28+
end
29+
30+
def user_links(text)
31+
names = text.scan(/\[@(\S+)\]/).map(&:first).uniq.sort
32+
names.map { |name| "[@#{name}]: https://github.com/#{name}" }.join("\n")
33+
end
34+
end

0 commit comments

Comments
 (0)