Skip to content

Commit dc0d7db

Browse files
author
Di Wu
authored
ci: read CocoaPods trunk token from AWS secret (#2921)
1 parent b304553 commit dc0d7db

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

.circleci/config.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ version: 2.1
44

55
orbs:
66
aws-cli: circleci/[email protected]
7+
78
# Using inline orb for now
89
getting-started-smoke-test:
910
orbs:
1011
macos: circleci/macos@2
1112
node: circleci/[email protected]
1213
ruby: circleci/[email protected]
1314
aws-cli: circleci/[email protected]
15+
1416
commands:
1517
send-metric-on-fail:
1618
description: Send failure datapoint to cloudwatch
@@ -321,6 +323,10 @@ jobs:
321323
- *restore_repo
322324
- restore_gems
323325
- check_bundle
326+
- aws-cli/setup:
327+
role-arn: $AWS_OIDC_ROLE_ARN
328+
role-session-name: "${CIRCLE_WORKFLOW_JOB_ID}.release"
329+
session-duration: '900'
324330
- run:
325331
name: Release pods
326332
command: bundle exec fastlane << parameters.lane >>
@@ -471,6 +477,7 @@ workflows:
471477
- deploy:
472478
name: deploy stable
473479
lane: release
480+
context: amplify-swift-aws-oidc
474481
<<: *deploy_requires
475482
filters:
476483
branches:
@@ -496,4 +503,4 @@ workflows:
496503
- cloudwatch-monitoring
497504
xcode-version: "12.5.1"
498505
simulator-os-version: "14.5"
499-
simulator-device: "iPhone 12"
506+
simulator-device: "iPhone 12"

fastlane/Fastfile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'json'
12
require_relative './amplify_pods.rb'
23

34
opt_out_usage
@@ -6,15 +7,15 @@ default_platform(:ios)
67
PLIST_KEY = "CFBundleShortVersionString"
78

89
platform :ios do
9-
before_all do
10-
# Perform a fetch before inferring the next version
10+
before_all do
11+
# Perform a fetch before inferring the next version
1112
# to reduce race conditions with simultaneous pipelines attempting to create the same tag
1213
sh('git', 'fetch', '--tags', '-f')
1314
sh('git', 'fetch')
1415
sh('git', 'status')
1516
end
1617
desc "Create a pre-release version by pushing a tag to GitHub, and pushing pods to CocoaPods"
17-
lane :unstable do
18+
lane :unstable do
1819
next_version = calculate_next_canary_version
1920
if next_version >= '2.0.0'
2021
UI.message("Received version: #{next_version}, exiting lane because version is larger than 2.0.0")
@@ -32,8 +33,17 @@ platform :ios do
3233
release_pods()
3334
end
3435

35-
desc "Create a release version by building and committing a changelog, pushing a tag to GitHub, and pushing pods to CocoaPods"
36+
desc "Create a release version by building and committing a changelog, pushing a tag to GitHub, and pushing pods to CocoaPods"
3637
lane :release do
38+
# Define `COCOAPODS_TRUNK_TOKEN` env var for trunk authentication
39+
# https://github.com/CocoaPods/cocoapods-trunk/commit/9e6ec1c1faf96fa837dc2ed70b5f54006b181ed6
40+
secret = sh(
41+
command: 'aws secretsmanager get-secret-value --secret-id ${COCOAPODS_SECRET_ARN}',
42+
log: false
43+
)
44+
45+
ENV['COCOAPODS_TRUNK_TOKEN'] = JSON.parse(secret)["SecretString"]
46+
3747
next_version, commits = calculate_next_release_version(version_limit:'v2.0.0')
3848
if next_version >= '2.0.0'
3949
UI.message("Received version: #{next_version}, exiting lane because version is larger than 2.0.0")
@@ -46,7 +56,7 @@ platform :ios do
4656

4757
changelog = build_changelog(version: next_version, commits: commits)
4858

49-
# Commit and push
59+
# Commit and push
5060
release_commit(version: next_version)
5161

5262
# Create tag and push to origin
@@ -80,7 +90,7 @@ platform :ios do
8090
set_key_value(file: "build-support/dependencies.rb", key: "AMPLIFY_VERSION", value: version)
8191
end
8292
end
83-
93+
8494
desc "Commit and push"
8595
private_lane :release_commit do |options|
8696
next_version = options[:version]
@@ -94,7 +104,7 @@ platform :ios do
94104
# push to origin
95105
sh('git', 'push', 'origin', 'release-v1')
96106
end
97-
107+
98108
desc "Tag in git and push to GitHub"
99109
private_lane :add_tag do |options|
100110
next_version = options[:version]
@@ -136,7 +146,7 @@ platform :ios do
136146
changelog = options[:changelog]
137147
tag = "#{version}"
138148
plugin_root = File.expand_path("#{ENV['CIRCLE_WORKING_DIRECTORY']}/AmplifyPlugins")
139-
149+
140150
sh('bundle', 'exec', 'swift', 'package', 'update')
141151

142152
sh('bundle', 'exec', 'pod', 'repo', 'update')

0 commit comments

Comments
 (0)