-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Adding workflows for automated releases #68
Open
ruisebas
wants to merge
4
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
506b032
chore: Adding worflows for automated releases
ruisebas 9f0cd72
chore: Updating setup-ruby version
ruisebas 345a018
chore: Adding unstable releases. Removing need of a release branch an…
ruisebas a562e5f
chore: Unit tests are now run as part of release, no need to run them…
ruisebas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Release Authenticator | ||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
permissions: | ||
id-token: write | ||
contents: write | ||
|
||
jobs: | ||
determine-release-type: | ||
name: Determine the release type | ||
runs-on: ubuntu-latest | ||
outputs: | ||
release-type: ${{ steps.release-type.outputs.value }} | ||
steps: | ||
- id: release-type | ||
run: | | ||
if ${{ github.event.head_commit.author.username == 'github-actions[bot]' && startsWith(github.event.head_commit.message, 'chore: Release ') }}; then | ||
VALUE=stable | ||
else | ||
VALUE=unstable | ||
fi | ||
echo "value=$VALUE" >> $GITHUB_OUTPUT | ||
|
||
unit-tests: | ||
name: Run Unit Tests | ||
uses: ./.github/workflows/unit_tests.yml | ||
with: | ||
identifier: 'workflow-call-unit-test' | ||
|
||
release: | ||
environment: Release | ||
name: Release new Authenticator ${{ needs.determine-release-type.outputs.release-type }} version | ||
needs: [determine-release-type, unit-tests] | ||
runs-on: macos-latest | ||
env: | ||
GITHUB_EMAIL: [email protected] | ||
GITHUB_USER: aws-amplify-ops | ||
steps: | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | ||
role-session-name: ${{ format('{0}.release', github.run_id) }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
mask-aws-account-id: true | ||
|
||
- id: retrieve-token | ||
name: Retrieve Token | ||
env: | ||
DEPLOY_SECRET_ARN: ${{ secrets.DEPLOY_SECRET_ARN }} | ||
run: | | ||
PAT=$(aws secretsmanager get-secret-value \ | ||
--secret-id "$DEPLOY_SECRET_ARN" \ | ||
| jq -r ".SecretString | fromjson | .Credential") | ||
echo "token=$PAT" >> $GITHUB_OUTPUT | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
with: | ||
fetch-depth: 10 | ||
token: ${{steps.retrieve-token.outputs.token}} | ||
|
||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@22fdc77bf4148f810455b226c90fb81b5cbc00a7 # v1.171.0 | ||
with: | ||
ruby-version: '3.2.1' | ||
bundler-cache: true | ||
|
||
- name: Release unstable version | ||
if: needs.determine-release-type.outputs.release-type == 'unstable' | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: bundle exec fastlane unstable_release | ||
|
||
- name: Determine stable release version | ||
id: determine-release-version | ||
if: needs.determine-release-type.outputs.release-type == 'stable' | ||
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 | ||
with: | ||
result-encoding: string | ||
script: | | ||
const matches = `${{ github.event.head_commit.message }}`.match(/[0-9]+\.[0-9]+\.[0-9]+/) ?? [] | ||
return matches.length > 0 ? matches[0] : "" | ||
|
||
- name: Release stable version | ||
if: steps.determine-release-version.outputs.result != '' | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: bundle exec fastlane stable_release version:${{ steps.determine-release-version.outputs.result }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Release - Kick-off | ||
on: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
id-token: write | ||
pull-requests: write | ||
|
||
jobs: | ||
release: | ||
environment: Release | ||
name: Kick off new Authenticator release | ||
runs-on: macos-latest | ||
env: | ||
GITHUB_EMAIL: [email protected] | ||
GITHUB_USER: aws-amplify-ops | ||
steps: | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | ||
role-session-name: ${{ format('{0}.release', github.run_id) }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
mask-aws-account-id: true | ||
|
||
- id: retrieve-token | ||
name: Retrieve Token | ||
env: | ||
DEPLOY_SECRET_ARN: ${{ secrets.DEPLOY_SECRET_ARN }} | ||
run: | | ||
PAT=$(aws secretsmanager get-secret-value \ | ||
--secret-id "$DEPLOY_SECRET_ARN" \ | ||
| jq -r ".SecretString | fromjson | .Credential") | ||
echo "token=$PAT" >> $GITHUB_OUTPUT | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
with: | ||
fetch-depth: 10 | ||
token: ${{steps.retrieve-token.outputs.token}} | ||
|
||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@22fdc77bf4148f810455b226c90fb81b5cbc00a7 # v1.171.0 | ||
with: | ||
ruby-version: '3.2.1' | ||
bundler-cache: true | ||
|
||
- name: Kick off Authenticator release | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: bundle exec fastlane kickoff_release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Gemfile | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'xcpretty', '0.3.0' | ||
gem 'fastlane', '2.205.1' | ||
eval_gemfile('fastlane/Pluginfile') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
opt_out_usage | ||
default_platform(:swift) | ||
|
||
platform :swift do | ||
before_all do | ||
# Perform a fetch before inferring the next version | ||
# to reduce race conditions with simultaneous pipelines attempting to create the same tag | ||
sh('git', 'fetch', '--tags', '-f') | ||
sh('git', 'fetch') | ||
end | ||
|
||
desc "Kickoff the next release by updating the changelog, updating the component version, and creating a PR to main" | ||
lane :kickoff_release do | ||
next_version, commits = calculate_next_release_version | ||
|
||
UI.message("Kicking off new release for version: #{next_version}") | ||
# Increment all specs and plists | ||
increment_versions(version: next_version) | ||
|
||
# Update Changelog | ||
changelog = build_changelog(version: next_version, commits: commits) | ||
write_changelog(changelog: changelog, path: 'CHANGELOG.md') | ||
|
||
# Update Package dependencies | ||
sh('bundle', 'exec', 'swift', 'package', 'update') | ||
|
||
# Create and push the new branch | ||
release_branch = "release/#{next_version}" | ||
sh('git', 'checkout', '-b', release_branch) | ||
sh('git', 'push', '--set-upstream', 'origin', release_branch) | ||
|
||
# Commit and push | ||
pr_title = release_commit(version: next_version).to_s | ||
|
||
# Open the PR to main | ||
sh('gh', 'pr', 'create', '--title', pr_title, '--body', 'Kicking off new release', '--base', 'main', '--head', release_branch) | ||
end | ||
|
||
desc "Increment versions" | ||
private_lane :increment_versions do |options| | ||
version = options[:version].to_s | ||
set_key_value(file: "Sources/Authenticator/Constants/ComponentInformation.swift", key: "version", value: version) | ||
end | ||
|
||
desc "Commit and push" | ||
private_lane :release_commit do |options| | ||
next_version = options[:version] | ||
|
||
sh('git', 'config', '--global', 'user.email', ENV['GITHUB_EMAIL']) | ||
sh('git', 'config', '--global', 'user.name', ENV['GITHUB_USER']) | ||
|
||
commit_message = "chore: Release #{next_version}" | ||
sh('git', 'commit', '-am', commit_message) | ||
sh('git', 'push') | ||
commit_message | ||
end | ||
|
||
desc "Create a pre-release version by pushing a new tag to GitHub" | ||
lane :unstable_release do | ||
next_version = calculate_next_canary_version | ||
|
||
UI.message("Releasing Authenticator unstable version: #{next_version}") | ||
|
||
# Create tag and push to origin | ||
add_tag(version: next_version) | ||
end | ||
|
||
desc "Create a release version by pushing a new tag to GitHub and creating a new draft release" | ||
lane :stable_release do |options| | ||
next_version = options[:version] | ||
|
||
UI.message("Releasing Authenticator version: #{next_version}") | ||
|
||
# Create and push the new tag | ||
add_tag(version: next_version) | ||
|
||
# Create draft release | ||
release_date = sh("echo $(date +%F)") | ||
release_title = "#{next_version} (#{release_date})" | ||
sh('gh', 'release', 'create', next_version, '--draft', '--title', release_title) | ||
end | ||
|
||
|
||
desc "Tag in git and push to GitHub" | ||
private_lane :add_tag do |options| | ||
next_tag = options[:version].to_s | ||
|
||
add_git_tag(tag: next_tag) | ||
push_git_tags(tag: next_tag) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Autogenerated by fastlane | ||
# | ||
# Ensure this file is checked in to source control! | ||
|
||
gem 'fastlane-plugin-release_actions', git: 'https://github.com/aws-amplify/amplify-ci-support', branch: 'main', glob: 'src/fastlane/release_actions/*.gemspec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
fastlane documentation | ||
---- | ||
|
||
# Installation | ||
|
||
Make sure you have the latest version of the Xcode command line tools installed: | ||
|
||
```sh | ||
xcode-select --install | ||
``` | ||
|
||
For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane) | ||
|
||
# Available Actions | ||
|
||
## Swift | ||
|
||
### swift release | ||
|
||
```sh | ||
[bundle exec] fastlane swift release | ||
``` | ||
|
||
Create a release version by building and committing a changelog, pushing a tag to GitHub |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an action instead of an inline script (recommended). For more information visit https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#good-practices-for-mitigating-script-injection-attacks
Event context data that are user controlled must be treated as potentially untrusted input. For more information visit https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#understanding-the-risk-of-script-injections