Skip to content

Commit 5679b4f

Browse files
committed
Rake tweaks
1 parent 047ed96 commit 5679b4f

File tree

7 files changed

+68
-22
lines changed

7 files changed

+68
-22
lines changed

.github/workflows/danger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ jobs:
2020
bundler-cache: true
2121
-
2222
name: Run Danger
23-
run: bundle exec danger --verbose
23+
run: bundle exec danger --verbose --dangerfile=rakelib/Dangerfile
2424
env:
2525
DANGER_GITHUB_API_TOKEN: ${{ secrets.danger_github_api_token }}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
---
44

5-
## Stable
5+
## Stable Branch
66

77
### Breaking Changes
88

Dangerfile renamed to rakelib/Dangerfile

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# frozen_string_literal: true
22

3-
require_relative 'rakelib/check_changelog'
3+
require_relative 'check_changelog'
4+
5+
is_release = github.branch_for_head.start_with?('release/')
6+
is_hotfix = github.branch_for_head.start_with?('hotfix/')
47

58
################################################
69
# Welcome message
@@ -19,6 +22,34 @@ warn('PR is classed as Work in Progress') if github.pr_title.include? '[WIP]'
1922
# Warn when there is a big PR
2023
warn('Big PR') if git.lines_of_code > 500 && !is_release
2124

25+
################################################
26+
# Check for correct base branch
27+
if is_release
28+
message('This is a Release PR')
29+
30+
require 'open3'
31+
32+
stdout, _, status = Open3.capture3('bundle', 'exec', 'rake', 'changelog:check')
33+
markdown [
34+
'',
35+
'### ChangeLog check',
36+
'',
37+
stdout
38+
]
39+
need_fixes << fail('Please fix the CHANGELOG errors') unless status.success?
40+
41+
stdout, _, status = Open3.capture3('bundle', 'exec', 'rake', 'release:check_versions')
42+
markdown [
43+
'',
44+
'### Release version check',
45+
'',
46+
stdout
47+
]
48+
need_fixes << fail('Please fix the versions inconsistencies') unless status.success?
49+
elsif is_hotfix
50+
message('This is a Hotfix PR')
51+
end
52+
2253
################################################
2354
# Check for a CHANGELOG entry
2455
declared_trivial = github.pr_title.include? '#trivial'

rakelib/changelog.rake

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace :changelog do
99
desc 'Add the empty CHANGELOG entries after a new release'
1010
task :reset do
1111
changelog = File.read('CHANGELOG.md')
12-
abort('A Develop entry already exists') if changelog =~ /^##\s*Develop$/
12+
abort('A Stable entry already exists') if changelog =~ /^##\s*Stable Branch$/
1313
changelog.sub!(/^##[^#]/, "#{header}\\0")
1414
File.write('CHANGELOG.md', changelog)
1515
end
1616

1717
def header
1818
<<-HEADER.gsub(/^\s*\|/, '')
19-
|## Stable
19+
|## Stable Branch
2020
|
2121
|### Breaking Changes
2222
|
@@ -70,18 +70,4 @@ namespace :changelog do
7070
|* [SwiftGen #{swiftgen}](https://github.com/SwiftGen/SwiftGen/blob/#{swiftgen}/CHANGELOG.md)
7171
LINKS
7272
end
73-
74-
desc "Push the CHANGELOG's top section as a GitHub release"
75-
task :push_github_release do
76-
require 'octokit'
77-
78-
client = Utils.octokit_client
79-
tag = Utils.top_changelog_version
80-
body = Utils.top_changelog_entry
81-
82-
repo_name = File.basename(`git remote get-url origin`.chomp, '.git').freeze
83-
puts "Pushing release notes for tag #{tag}:"
84-
puts body
85-
client.create_release("SwiftGen/#{repo_name}", tag, name: tag, body: body)
86-
end
8773
end

rakelib/lint.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# - BUILD_DIR
55

66
namespace :lint do
7-
SWIFTLINT = 'Scripts/SwiftLint.sh'
7+
SWIFTLINT = 'rakelib/lint.sh'
88
SWIFTLINT_VERSION = '0.47.1'
99

1010
task :install do |task|
File renamed without changes.

rakelib/utils.rake

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# - MIN_XCODE_VERSION
55

66
require 'json'
7-
require 'pathname'
87
require 'open3'
8+
require 'pathname'
99

1010
# Utility functions to run Xcode commands, extract versionning info and logs messages
1111
#
@@ -40,14 +40,43 @@ class Utils
4040
File.open('Package.swift').read()
4141
.match(/https:\/\/.*artifactbundle.zip/)[0]
4242
.match(/\d+\.\d+\.\d+/)[0]
43+
end
44+
45+
def self.podspec_as_json(file)
46+
file += '.podspec' unless file.include?('.podspec')
47+
json, _, _ = Open3.capture3('bundle', 'exec', 'pod', 'ipc', 'spec', file)
48+
JSON.parse(json)
49+
end
50+
51+
def self.podspec_version(file)
52+
podspec_as_json(file)['version']
53+
end
54+
55+
def self.pod_trunk_last_version(pod)
56+
require 'yaml'
57+
stdout, _, _ = Open3.capture3('bundle', 'exec', 'pod', 'trunk', 'info', pod)
58+
stdout.sub!("\n#{pod}\n", '')
59+
last_version_line = YAML.safe_load(stdout).first['Versions'].last
60+
/^[0-9.]*/.match(last_version_line)[0] # Just the 'x.y.z' part
61+
end
62+
63+
def self.spm_own_version(dep)
64+
dependencies = JSON.load(File.new('Package.resolved'))['object']['pins']
65+
dependencies.find { |d| d['package'] == dep }['state']['version']
4366
end
4467

68+
def self.spm_resolved_version(dep)
69+
dependencies = JSON.load(File.new('Package.resolved'))['object']['pins']
70+
dependencies.find { |d| d['package'] == dep }['state']['version']
71+
end
72+
4573
def self.last_git_tag_version
4674
`git describe --tags --abbrev=0`.strip
4775
end
4876

4977
def self.octokit_client
50-
token = File.exist?('.apitoken') && File.read('.apitoken')
78+
token = ENV['DANGER_GITHUB_API_TOKEN']
79+
token ||= File.exist?('.apitoken') && File.read('.apitoken')
5180
token ||= File.exist?('../.apitoken') && File.read('../.apitoken')
5281
Utils.print_error('No .apitoken file found') unless token
5382
require 'octokit'

0 commit comments

Comments
 (0)