-
Notifications
You must be signed in to change notification settings - Fork 13
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
TBE-138 Deployment process automation #5447
Open
mpidcock
wants to merge
24
commits into
main
Choose a base branch
from
update-circleci-slack-alerts
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
24 commits
Select commit
Hold shift + click to select a range
e1ac201
log headers
mrotondo c310ba2
add aws ip ranges as trusted proxies
mrotondo fa42747
Update circleci slack notifications:
mpidcock af67b15
Merge branch 'refs/heads/main' into update-circleci-slack-alerts
mpidcock 845ade1
Breaking a test to trigger tax bot
mpidcock 7174f31
Add staging alerts, primarily for testing
mpidcock 991f0c2
Merge branch 'refs/heads/main' into staging
mpidcock b957afd
Merge branch 'refs/heads/update-circleci-slack-alerts' into staging
mpidcock 7b7da59
Create github action for tagging and merging releases
mpidcock c11da6a
Revert "Breaking a test to trigger tax bot"
mpidcock b73ce63
Merge branch 'refs/heads/update-circleci-slack-alerts' into fake-main…
mpidcock 86d4afe
minor edits
mpidcock 9c60e58
only allow manual dispatch, draft release notes
mpidcock cf4cde3
add back "on push", but with draft notes
mpidcock b71c3e1
Merge branch 'refs/heads/main' into fake-main-for-testing
mpidcock e6c6a39
updates
mpidcock 351ce00
Merge branch 'refs/heads/staging' into fake-main-for-testing
mpidcock 39ef91c
updates
mpidcock ea460e1
updates
mpidcock fd9d340
fixing version
mpidcock 3e37810
fetch new tag
mpidcock f91e7ab
don't merge tag
mpidcock e949668
Cleanup
mpidcock 6555ebb
Action to publish the latest release notes
mpidcock 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
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,14 @@ | ||
# Configuration to autogenerate release notes | ||
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes | ||
|
||
changelog: | ||
categories: | ||
- title: 🏕 Features | ||
labels: | ||
- '*' | ||
exclude: | ||
labels: | ||
- dependencies | ||
- title: 👒 Dependencies | ||
labels: | ||
- dependencies |
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,20 @@ | ||
name: Publish Latest Release | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish-release: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Publish github release notes | ||
run: | | ||
tagName=$(gh release list --json isDraft,tagName,publishedAt --jq '[.[] | select(.isDraft == true) | {tagName: (.tagName), timestamp: (.publishedAt | fromdateiso8601)}] | sort_by(.timestamp) | last | .tagName') | ||
if [ -z "$tagName" ]; then | ||
echo "All release are already published" | ||
exit 0 | ||
fi | ||
gh release edit $(tagName) --draft=false | ||
echo "https://github.com/codeforamerica/vita-min/releases/latest" |
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,115 @@ | ||
name: Tag and Release | ||
# 1. Merge current commit and check for errors | ||
# 2. Generate a version | ||
# 3. Draft a release with auto-generated notes (tag not pushed yet) | ||
# 4. Push merged changes | ||
|
||
on: | ||
# since workflow_dispatch will only work if the default branch has this config, | ||
# for testing, this will run action on every merge (does not test inputs) | ||
push: | ||
branches: | ||
- fake-main-for-testing | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
description: 'Where to deploy' | ||
required: true | ||
default: 'staging' | ||
options: [staging, demo, prod] | ||
release_type: | ||
description: 'Part of version to increment (major, minor, patch)' | ||
required: false | ||
default: 'patch' | ||
type: choice | ||
options: [patch, minor, major] | ||
release_title: | ||
description: 'Optional title to replace auto-generated one' | ||
required: false | ||
type: string | ||
additional_notes: | ||
description: 'Optional notes to prepend to auto-generated notes' | ||
required: false | ||
type: string | ||
|
||
jobs: | ||
deployment: | ||
name: "Initiate deployment to ${{ github.event.inputs.environment }}" | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: vita-min-${{ github.event.inputs.environment }} | ||
url: ${{ env.FYST_URL }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Check out ${{ env.TARGET_BRANCH }} branch | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ env.TARGET_BRANCH }} | ||
fetch-tags: true | ||
|
||
- name: Check for merge conflicts | ||
run: | | ||
target_sha=$(git show -s --format=%H) | ||
if [[ ${target_sha} == ${GITHUB_SHA} ]]; then | ||
echo "Target SHA already matches. No need to deploy." | ||
exit 0 | ||
fi | ||
git fetch origin ${GITHUB_SHA} | ||
git merge --ff-only ${GITHUB_SHA} || { | ||
# merge failed | ||
echo "unable to merge via fast-forward. likely conflict." | ||
echo "try viewing the conflict output locally:" | ||
echo "git fetch origin" | ||
echo "git checkout ${{ env.TARGET_BRANCH }}" | ||
echo "git merge --ff ${{ github.ref_name }}" | ||
exit 1 | ||
} | ||
|
||
- name: Increment version | ||
if: github.event.inputs.environment == 'prod' | ||
run: | | ||
# parse major, minor, and patch versions from the last release | ||
latest_tag="$(git tag --list | grep 'version-' | sort --version-sort | tail -n1)" | ||
trimmed_version="${latest_version#version-}" | ||
old_version="${trimmed_version:-0.0.0}" | ||
IFS='.' read -r major minor patch <<< "${old_version}" | ||
echo "OLD_VERSION=${old_version}" >> $GITHUB_ENV | ||
|
||
# increment appropriately for the release type (default to patch) | ||
release_type="${{ github.event.inputs.release_type || 'patch' }}" | ||
echo "incrementing ${release_type} version" | ||
case "${release_type}" in | ||
'major' ) ((major=major+1)); minor=0; patch=0;; | ||
'minor' ) ((minor=minor+1)); patch=0;; | ||
'patch' ) ((patch=patch+1));; | ||
* ) echo "Invalid release type"; exit 1;; | ||
esac | ||
new_version="version-${major}.${minor}.${patch}" | ||
echo "NEW_VERSION=${new_version}" >> ${GITHUB_ENV} | ||
|
||
- name: Generate release notes | ||
if: github.event.inputs.environment == 'prod' | ||
run: | | ||
release_command="gh release create ${{ env.NEW_VERSION }} --target ${GITHUB_SHA} --generate-notes --draft" | ||
if [[ -n "${{ github.event.inputs.release_title }}" ]]; then | ||
release_command="${release_command} --title '${{ github.event.inputs.release_title }}'" | ||
fi | ||
if [[ -n "${{ github.event.inputs.additional_notes }}" ]]; then | ||
release_command="${release_command} --notes '${{ github.event.inputs.additional_notes }}'" | ||
fi | ||
|
||
eval ${release_command} | ||
echo "https://github.com/codeforamerica/vita-min/releases/latest" | ||
|
||
- name: deploy | ||
run: | | ||
echo "Updating branch on GitHub. This triggers deployment in CircleCI." | ||
git push | ||
|
||
echo "✨ Deployment to ${{ github.event.inputs.environment }} initiated!" | ||
echo "👀 Watch progress on CircleCI: https://app.circleci.com/pipelines/github/codeforamerica/vita-min?branch=${{ env.TARGET_BRANCH }}" | ||
if [[ "${{ github.event.inputs.environment == 'prod' }}" ]]; then | ||
echo "📝 (Draft) Release notes here: https://github.com/codeforamerica/vita-min/releases" | ||
echo "🧷 If needed, rollback to: ${{ env.OLD_VERSION }}" | ||
fi |
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
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.
Here the release notes are initially created as a
draft
. It is my hope to automate publishing it once the job succeeds in circleci, but if that proves too challenging then it might be best to publish from the start rather than require a manual follow up step.