Skip to content
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
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e1ac201
log headers
mrotondo Jan 21, 2025
c310ba2
add aws ip ranges as trusted proxies
mrotondo Jan 21, 2025
fa42747
Update circleci slack notifications:
mpidcock Jan 25, 2025
af67b15
Merge branch 'refs/heads/main' into update-circleci-slack-alerts
mpidcock Jan 29, 2025
845ade1
Breaking a test to trigger tax bot
mpidcock Jan 29, 2025
7174f31
Add staging alerts, primarily for testing
mpidcock Jan 30, 2025
991f0c2
Merge branch 'refs/heads/main' into staging
mpidcock Jan 30, 2025
b957afd
Merge branch 'refs/heads/update-circleci-slack-alerts' into staging
mpidcock Jan 30, 2025
7b7da59
Create github action for tagging and merging releases
mpidcock Jan 30, 2025
c11da6a
Revert "Breaking a test to trigger tax bot"
mpidcock Jan 30, 2025
b73ce63
Merge branch 'refs/heads/update-circleci-slack-alerts' into fake-main…
mpidcock Jan 30, 2025
86d4afe
minor edits
mpidcock Jan 30, 2025
9c60e58
only allow manual dispatch, draft release notes
mpidcock Jan 30, 2025
cf4cde3
add back "on push", but with draft notes
mpidcock Jan 30, 2025
b71c3e1
Merge branch 'refs/heads/main' into fake-main-for-testing
mpidcock Jan 30, 2025
e6c6a39
updates
mpidcock Jan 30, 2025
351ce00
Merge branch 'refs/heads/staging' into fake-main-for-testing
mpidcock Jan 30, 2025
39ef91c
updates
mpidcock Jan 30, 2025
ea460e1
updates
mpidcock Jan 30, 2025
fd9d340
fixing version
mpidcock Jan 30, 2025
3e37810
fetch new tag
mpidcock Jan 30, 2025
f91e7ab
don't merge tag
mpidcock Jan 31, 2025
e949668
Cleanup
mpidcock Jan 31, 2025
6555ebb
Action to publish the latest release notes
mpidcock Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 2.1

orbs:
slack: circleci/slack@4.9.3
slack: circleci/slack@5.1.1

executors:
ruby_executor:
Expand Down Expand Up @@ -119,6 +119,7 @@ jobs:
path: ~/test-results
- slack/notify:
branch_pattern: main, fake-main-for-testing, release
channel: "C0540PNTLGN" # tax-alerts
event: fail
mentions: "@badger"
template: basic_fail_1
Expand Down Expand Up @@ -159,6 +160,7 @@ jobs:
paths: [tmp/parallel_runtime_rspec.log]
- slack/notify:
branch_pattern: main, fake-main-for-testing, release
channel: "C0540PNTLGN" # tax-alerts
event: fail
mentions: "@badger"
template: basic_fail_1
Expand Down Expand Up @@ -188,6 +190,12 @@ jobs:
- run: echo $APTIBLE_PUBLIC_KEY >> ~/.ssh/known_hosts
- run: git fetch --depth=1000000
- run: git push --force git@beta.aptible.com:vita-min-staging/vita-min-staging.git $CIRCLE_SHA1:master
- slack/notify:
event: pass
template: basic_success_1
- slack/notify:
event: fail
template: basic_fail_1
parallelism: 1
deploy_to_aptible--production:
executor: ruby_executor
Expand All @@ -196,6 +204,15 @@ jobs:
- run: echo $APTIBLE_PUBLIC_KEY >> ~/.ssh/known_hosts
- run: git fetch --depth=1000000
- run: git push git@beta.aptible.com:vita-min-prod/vita-min-prod.git $CIRCLE_SHA1:master
- slack/notify:
channel: "C0544ERAFQV" # tax-eng
event: pass
template: success_tagged_deploy_1
- slack/notify:
channel: "C0544ERAFQV" # tax-eng
event: fail
mentions: "@badger"
template: basic_fail_1
parallelism: 1
workflows:
version: 2
Expand All @@ -206,16 +223,17 @@ workflows:
branches:
only: translations_a24d8971fccee9a494b7267ce7f7deae_es
- run_js_tests:
context: gyr_deploy_alerts
context: tax-bot
- run_ruby_tests:
context: gyr_deploy_alerts
context: tax-bot
- run_annotate
- deploy_to_aptible--demo:
requires: [run_js_tests, run_ruby_tests]
filters:
branches:
only: main
- deploy_to_aptible--staging:
context: tax-bot
requires: [run_js_tests, run_ruby_tests]
filters:
branches:
Expand All @@ -225,6 +243,7 @@ workflows:
branches:
only: [circleci-update-flow-explorer-screenshots]
- deploy_to_aptible--production:
context: tax-bot
requires: [run_js_tests, run_ruby_tests]
filters:
branches:
Expand Down
14 changes: 14 additions & 0 deletions .github/release.yml
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
20 changes: 20 additions & 0 deletions .github/workflows/publish-lastest-release.yml
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"
115 changes: 115 additions & 0 deletions .github/workflows/tag-and-release.yml
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"
Copy link
Member Author

@mpidcock mpidcock Feb 3, 2025

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.

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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ module StateFile
module ArchivedIntakes
class EmailAddressController < ArchivedIntakeController
before_action :check_feature_flag

before_action :log_ip_prospects

def log_ip_prospects
puts "request.remote_ip: #{request.remote_ip}"
puts "all headers:"
request.headers.each { |k, v| puts " #{k}: #{v}" }
end

def edit
@form = EmailAddressForm.new
end
Expand Down
Loading