Skip to content

Commit 766d323

Browse files
committed
Publish on tag task
1 parent 5679b4f commit 766d323

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

.github/workflows/tag-publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish on Tag
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
github:
11+
name: GitHub Release
12+
runs-on: ubuntu-latest
13+
steps:
14+
-
15+
name: Checkout
16+
uses: actions/checkout@v3
17+
-
18+
name: Set up Ruby
19+
uses: ruby/setup-ruby@v1
20+
with:
21+
bundler-cache: true
22+
-
23+
name: Create release on GitHub
24+
run: bundle exec rake release:github
25+
env:
26+
DANGER_GITHUB_API_TOKEN: ${{ secrets.danger_github_api_token }}

rakelib/release.rake

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# frozen_string_literal: true
2+
3+
# Used constants:
4+
# - BUILD_DIR
5+
6+
def first_match_in_file(file, regexp)
7+
File.foreach(file) do |line|
8+
m = regexp.match(line)
9+
return m if m
10+
end
11+
end
12+
13+
## [ Release a new version ] ##################################################
14+
15+
namespace :release do
16+
desc 'Create a new release'
17+
task :new => [:check_versions, :confirm, 'spm:test_command', :github]
18+
19+
desc 'Check if all versions from the podspecs and CHANGELOG match'
20+
task :check_versions do
21+
results = []
22+
23+
# Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early)
24+
`which bundler`
25+
results << Utils.table_result(
26+
$CHILD_STATUS.success?,
27+
'Bundler installed',
28+
'Please install bundler using `gem install bundler` and run `bundle install` first.'
29+
)
30+
changelog_has_stable = system("grep -qi '^## Stable Branch' CHANGELOG.md")
31+
results << Utils.table_result(
32+
!changelog_has_stable,
33+
'CHANGELOG, No stable',
34+
'Please remove section for stable branch in CHANGELOG'
35+
)
36+
37+
exit 1 unless results.all?
38+
end
39+
40+
desc "Ask to release"
41+
task :confirm do
42+
print "Release version new version [Y/n]? "
43+
exit 2 unless STDIN.gets.chomp == 'Y'
44+
end
45+
46+
desc "Create a new GitHub release"
47+
task :github do
48+
require 'octokit'
49+
50+
client = Utils.octokit_client
51+
tag = Utils.top_changelog_version
52+
body = Utils.top_changelog_entry
53+
54+
raise 'Must be a valid version' if tag == 'Stable Branch'
55+
56+
repo_name = File.basename(`git remote get-url origin`.chomp, '.git').freeze
57+
puts "Pushing release notes for tag #{tag}"
58+
client.create_release("SwiftGen/#{repo_name}", tag, name: tag, body: body)
59+
end
60+
end

0 commit comments

Comments
 (0)