Skip to content

Commit 1ccce09

Browse files
committed
Flesh out release.yml workflow
1 parent 5c72046 commit 1ccce09

File tree

8 files changed

+268
-26
lines changed

8 files changed

+268
-26
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
function getFirstLine(message) {
2+
const index = message.indexOf('\n');
3+
if (index === -1) {
4+
return message;
5+
}
6+
7+
return message.slice(0, index);
8+
}
9+
10+
async function getBody({ github, core, context, target }) {
11+
const res = await github.repos.getLatestRelease({
12+
owner: context.repo.owner,
13+
repo: context.repo.repo,
14+
});
15+
16+
const latestRelease = res.data;
17+
const diff = await github.repos.compareCommits({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
base: latestRelease.tag_name,
21+
head: target,
22+
});
23+
24+
const commits = diff.data.commits;
25+
if (!commits.length) {
26+
return 'No changes';
27+
}
28+
29+
const format = (log) => `* ${log.title} (${log.hash}) ${log.name} <${log.email}>`;
30+
const lines = commits.map((c) => {
31+
const payload = {
32+
title: getFirstLine(c.commit.message),
33+
hash: c.sha.slice(0, 7),
34+
name: c.commit.author.name,
35+
email: c.commit.author.email,
36+
};
37+
return format(payload);
38+
});
39+
40+
return lines.join('\n');
41+
}
42+
43+
/**
44+
* Create Github Release given the version (provided by a tag)
45+
*/
46+
async function createRelease({ context, core, github, sha, version }) {
47+
const title = `### Release Note (${version})`;
48+
const body = await getBody({ github, core, context, target: sha });
49+
const releaseBody = `${title}\n\n${body}`;
50+
51+
const release = {
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
tag_name: version,
55+
target_commitish: sha,
56+
name: version,
57+
body: releaseBody,
58+
draft: false,
59+
prelease: false,
60+
};
61+
62+
await github.repos.createRelease(release);
63+
}
64+
65+
module.exports = createRelease;

.github/workflows/release.yml

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,72 @@
11
name: Tag & Release
22

3-
# -----
4-
# TODO: Define this workflow.
5-
# -----
6-
73
# Manually triggered
8-
# $ gh workflow run integration-tests.yml
4+
# $ gh workflow run -f version=1.40.0 release.yml
95
on: workflow_dispatch
6+
inputs:
7+
version:
8+
description: The version number to use for this release.
9+
required: true
1010

11+
# Builds two frameworks in parallel, then commits checksums, releases
12+
# with the frameworks and checksums attached to the release.
1113
jobs:
14+
build:
15+
runs-on: macos-latest
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v2
19+
- name: Build xcframework
20+
working-directory: carthage-files
21+
run: |
22+
xcodebuild -scheme Branch-xcframework
23+
cd build
24+
zip -rqy Branch.zip Branch.xcframework/
25+
echo '#checksum for Branch.zip on Github' > checksum.txt
26+
shasum Branch.zip >> checksum
27+
- name: Upload build artifacts
28+
uses: actions/upload-artifact@v2
29+
with:
30+
name: Branch-xcframework
31+
paths:
32+
- carthage-build/Branch.zip
33+
- carthage-build/checksum
34+
35+
build-static:
36+
runs-on: macos-latest
37+
steps:
38+
- name: Check out code
39+
uses: actions/checkout@v2
40+
- name: Build static xcframework
41+
working-directory: carthage-files
42+
run: |
43+
xcodebuild -scheme Branch-static-xcframework
44+
cd build
45+
zip -rqy Branch-static.zip Branch.xcframework/
46+
echo '#checksum for Branch-static.zip on Github' > checksum.txt
47+
shasum Branch_static.zip >> checksum_static
48+
- name: Upload build artifacts
49+
uses: actions/upload-artifact@v2
50+
with:
51+
name: Branch-static-xcframework
52+
paths:
53+
- carthage-build/Branch_static.zip
54+
- carthage-build/checksum_static
55+
1256
release:
1357
runs-on: macos-latest
58+
needs: [build, build-static]
1459
steps:
1560
- name: Check out code
1661
uses: actions/checkout@v2
1762
- name: Set up Ruby 2.7
1863
uses: ruby/setup-ruby@v1
1964
with:
2065
ruby-version: '2.7'
66+
# The CocoaPods dependencies are only used by the
67+
# Branch-TestBed.xcworkspace (for unit tests).
68+
# Bring in the Ruby deps from the cache for quick availability of
69+
# pod command. Not using cached Pods folder.
2170
- name: Restore cache
2271
uses: actions/cache@v2
2372
with:
@@ -31,24 +80,48 @@ jobs:
3180
run: |
3281
bundle config set --local path vendor
3382
bundle check || bundle install
34-
# This happens automatically with the unit_tests lane, but adding it here
35-
# makes it easier to keep track of installation time via GHA without
36-
# adding execution time to the next step.
37-
- name: Install CocoaPods dependencies
38-
run: bundle exec fastlane prepare_pods
39-
40-
# 1. Publish to CocoaPods.
83+
- name: Download build artifacts
84+
uses: actions/download-artifact@v2
85+
- name: Verify build artifacts
86+
working-directory: carthage-files
87+
run: |
88+
ls -R
89+
# The sha output from this step is the commit to be tagged.
90+
- name: Commit checksums
91+
id: commit-checksums
92+
run: |
93+
git config user.name "Branch SDK Team"
94+
git config user.email [email protected]
95+
git commit carthage-files/checksum carthage-files/checksum_static -m'Updated checksums'
96+
echo "::set-output name=sha::$(git rev-parse HEAD)"
97+
# TODO: Version bump along the way, probably here.
98+
- name: Push changes
99+
run: |
100+
git push
41101
- name: Publish to CocoaPods
42102
run: |
103+
# TODO: Authenticate
104+
# bundle exec pod trunk push Branch.podspec
43105
echo "TODO: This 👆"
44-
# 2. Create GitHub release. Also creates a tag.
45-
# Remember to build and attach binaries.
106+
# 3. Create GitHub release. Also creates a tag.
46107
- name: Create GitHub Release
47108
uses: actions/github-script@v4
48109
with:
49110
script: |
50-
console.log('TODO: This 👆');
51-
# 3. Trigger import workflow in ios-spm repo.
111+
const createRelease = require('./.github/custom-scripts/create-release');
112+
const tagName = '${{ github.event.inputs.version }}';
113+
const sha = '${{ steps.commit-checksums.outputs.sha }}';
114+
const release = await createRelease({
115+
core,
116+
context,
117+
github,
118+
sha,
119+
tagName,
120+
});
121+
122+
console.log(`Created release ${tagName}:`);
123+
console.log(` ${JSON.stringify(release)}`);
124+
# 4. Trigger import workflow in ios-spm repo.
52125
- name: Export to ios-spm repository
53126
uses: actions/github-script@v4
54127
with:

.github/workflows/verify.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
pull_request:
55
branches:
66
- master
7-
- production
87

98
jobs:
109
verify:

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
22

33
gem 'cocoapods', '~> 1.9'
44
gem 'fastlane', '~> 2.69'
5+
gem 'pattern_patch', '~> 0.5'
56

67
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
78
eval_gemfile(plugins_path) if File.exist?(plugins_path)

Gemfile.lock

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ GEM
104104
faraday_middleware (1.0.0)
105105
faraday (~> 1.0)
106106
fastimage (2.2.4)
107-
fastlane (2.185.0)
107+
fastlane (2.185.1)
108108
CFPropertyList (>= 2.3, < 4.0.0)
109109
addressable (>= 2.3, < 3.0.0)
110110
artifactory (~> 3.0)
@@ -146,7 +146,7 @@ GEM
146146
fourflusher (2.3.1)
147147
fuzzy_match (2.0.4)
148148
gh_inspector (1.1.3)
149-
google-apis-androidpublisher_v3 (0.5.0)
149+
google-apis-androidpublisher_v3 (0.6.0)
150150
google-apis-core (~> 0.1)
151151
google-apis-core (0.3.0)
152152
addressable (~> 2.5, >= 2.5.1)
@@ -206,6 +206,8 @@ GEM
206206
naturally (2.2.1)
207207
netrc (0.11.0)
208208
os (1.1.1)
209+
pattern_patch (0.5.4)
210+
activesupport
209211
plist (3.6.0)
210212
public_suffix (4.0.6)
211213
rake (13.0.3)
@@ -265,6 +267,7 @@ PLATFORMS
265267
DEPENDENCIES
266268
cocoapods (~> 1.9)
267269
fastlane (~> 2.69)
270+
pattern_patch (~> 0.5)
268271

269272
BUNDLED WITH
270-
2.2.19
273+
2.2.20

fastlane/Fastfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
require_relative 'lib/helper/update_helper'
1+
require_relative 'lib/helper/cocoapods_helper'
2+
require_relative 'lib/helper/version_helper'
23

34
fastlane_version "2.69.0"
45

56
lane :prepare_pods do
67
# This helps optimize CI with caching by testing whether a pod install is necessary
8+
# from cocoapods_helper
79
pod_install_if_required '../Branch-TestBed'
810
# Can also turn on verbose output and disable repo update
911
# pod_install_if_required '../Branch-TestBed', verbose: true, repo_update: false
@@ -20,3 +22,13 @@ lane :integration_tests do
2022
# This testplan includes unit tests as well as integration tests.
2123
scan scheme: 'Branch-TestBed'
2224
end
25+
26+
# bundle exec fastlane version_bump version:patch # default
27+
# bundle exec fastlane version_bump version:minor
28+
# bundle exec fastlane version_bump version:major
29+
# bundle exec fastlane version_bump version:1.41.0
30+
lane :version_bump do |opts|
31+
# from version_helper
32+
next_version = update_sdk_version version: opts[:version]
33+
sh 'git', 'commit', '-a', '-m', "[release] #{next_version}"
34+
end

fastlane/lib/helper/update_helper.rb renamed to fastlane/lib/helper/cocoapods_helper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'cocoapods'
22
require 'pathname'
33

4-
module UpdateHelper
4+
module CocoapodsHelper
55
UI = FastlaneCore::UI
66

7-
class UpdateHelperException < RuntimeError; end
7+
class CocoapodsHelperException < RuntimeError; end
88

99
# Following the lead of npm ci (https://docs.npmjs.com/cli/v7/commands/npm-ci):
1010
# The Podfile.lock must exist.
@@ -31,7 +31,7 @@ def pod_install_required?(podfile_folder)
3131
manifest_path = File.join podfile_folder, 'Pods', 'Manifest.lock'
3232

3333
# Don't regenerate the lockfile
34-
raise UpdateHelperException, "#{lockfile_path} missing or not readable." unless File.readable?(lockfile_path)
34+
raise CocoapodsHelperException, "#{lockfile_path} missing or not readable." unless File.readable?(lockfile_path)
3535

3636
return true unless File.readable?(manifest_path)
3737

@@ -58,7 +58,7 @@ def pod_install_required?(podfile_folder)
5858
end
5959

6060
# Don't regenerate the lockfile.
61-
raise UpdateHelperException, "Podfile checksum #{podfile.checksum} does not match PODFILE CHECKSUM in Podfile.lock."
61+
raise CocoapodsHelperException, "Podfile checksum #{podfile.checksum} does not match PODFILE CHECKSUM in Podfile.lock."
6262
end
6363

6464
def pod_install_if_required(podfile_folder, verbose: false, repo_update: true)
@@ -75,4 +75,4 @@ def pod_install_if_required(podfile_folder, verbose: false, repo_update: true)
7575
end
7676
end
7777

78-
include UpdateHelper
78+
include CocoapodsHelper

0 commit comments

Comments
 (0)