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

Automating cutting .latest + main cleanup #70

Merged
merged 7 commits into from
Jan 31, 2023
Merged
Changes from 6 commits
Commits
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
283 changes: 283 additions & 0 deletions .github/workflows/cut-release-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
# **what?**
# Cuts the `*.latest` branch, bumps dependencies on it, cleans up all files in `.changes/unreleased`
# and `.changes/previous verion on main and bumps main to the input version.

# **why?**
# Clean up the main branch after a release branch is cut and automate cutting the release branch.
# Generally reduces the workload of engineers and reducing error.

# **when?**
# This will run when called manually or when triggered in another workflow.

# Example Usage including required permissions: TODO: update once finalized

# permissions:
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
# contents: read
# pull-requests: write
#
# name: Cut Release Branch
# jobs:
# changelog:
# uses: dbt-labs/actions/.github/workflows/cut-release-branch.yml@main
# with:
# version_to_bump_main: 1.3.0a1
# new_branch_name: 1.2.latest
# repository: dbt-snowflake
# secrets:
# FISHTOWN_BOT_PAT: ${{ secrets.FISHTOWN_BOT_PAT }}

# TODOs
# add note to eventually commit changes directly and bypass checks - same as release - when we move to this model run test action after merge

name: Cut new release branch

on:
workflow_call:
inputs:
version_to_bump_main:
required: true
type: string
new_branch_name:
description: 'The full name of the new branch (ex. 1.5.latest)'
required: true
type: string
repository:
required: true
type: string
PR_title:
required: false
type: string
PR_body:
required: false
type: string
outputs:
PR_number:
description: "PR number for the opened PR"
value: ${{ jobs.cleanup_main.outputs.pr_number }}
secrets:
FISHTOWN_BOT_PAT:
description: "PAT that allows commits, creating branches and opening PRs so the repository"
required: true

workflow_dispatch:
inputs:
version_to_bump_main:
description: 'The alpha version main should bump to (ex. 1.6.0a1)'
required: true
new_branch_name:
description: 'The full name of the new branch (ex. 1.5.latest)'
required: true
repository:
description: "Repository to create new branch and cleanup main:"
required: true
type: choice
options:
- 'dbt-core'
- 'dbt-snowflake'
- 'dbt-redshift'
- 'dbt-bigquery'
- 'dbt-spark'

defaults:
run:
shell: bash

permissions:
contents: write

jobs:
prep_work:
runs-on: ubuntu-latest
steps:
- name: "[DEBUG] Print Inputs"
run: |
echo "Version to bump main: ${{ inputs.version_to_bump_main }}"
echo "Name of branch to cut: ${{ inputs.new_branch_name }}"

- name: Audit New Version and Parse Into Parts
id: semver
uses: dbt-labs/actions/parse-semver@v1
with:
version: ${{ inputs.version_to_bump_main }}

cut_branch:
needs: ['prep_work']
runs-on: ubuntu-latest

steps:

- name: "Checkout ${{ inputs.repository }} repository"
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: "main"
token: ${{ secrets.FISHTOWN_BOT_PAT }}

- name: "Ensure New Branch Does Not Exist"
id: check_new_branch
run: |
if git show-ref --quiet refs/heads/${{ inputs.new_branch_name }}; then
echo "Branch ${{ inputs.new_branch_name }} already exists. Exiting."
exit 1
fi

- name: "Create New Release Branch"
run: |
git checkout -b ${{ inputs.new_branch_name }}

- name: "Bump dependencies via script"
if: repo != dbt-core
run: |
echo "running some script yet to be written now"
scripts/update_dependencies.sh
emmyoop marked this conversation as resolved.
Show resolved Hide resolved

- name: "Commit & Push Changes"
run: |
#Data for commit
user="Github Build Bot"
email="buildbot@fishtownanalytics.com"
commit_message="Cutting .latest branch ${{ inputs.new_branch_name }}"
#Commit changes to branch
git config user.name "$user"
git config user.email "$email"
git pull
git add .
git commit -m "$commit_message"
git push --set-upstream origin ${{ inputs.new_branch_name }}

cleanup_main:
needs: ['cut_branch']
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.create_pr.outputs.pull-request-number }}

steps:

- name: "Set Branch Value"
id: variables
run: |
echo "BRANCH_NAME=cutting_release_branch/main_cleanup" >> $GITHUB_OUTPUT

- name: "Checkout ${{ inputs.repository }} Repository"
uses: actions/checkout@v4.3.0
with:
repository: ${{ inputs.repository }}
ref: "main"
token: ${{ secrets.FISHTOWN_BOT_PAT }}

- name: "Check Current Version In Code"
id: determine_version
run: |
current_version=$(grep current_version .bumpversion.cfg | sed 's/.*= //')
echo "current_version=$current_version" >> $GITHUB_OUTPUT

- name: "Parse Current Version Into Parts for Changelog Directories"
id: semver-current
uses: dbt-labs/actions/parse-semver@v1
with:
version: ${{ steps.determine_version.outputs.current_version }}

- name: "Create PR Branch"
run: |
user="Github Build Bot"
email="buildbot@fishtownanalytics.com"
git config user.name "$user"
git config user.email "$email"
git checkout -b ${{ steps.variables.output.BRANCH_NAME }}
git push origin ${{ steps.variables.output.BRANCH_NAME }}
git branch --set-upstream-to=origin/${{ steps.variables.output.BRANCH_NAME }} ${{ steps.variables.output.BRANCH_NAME }}

- name: "Bump Version"
run: |
source env/bin/activate
pip install -r dev-requirements.txt
env/bin/bumpversion --allow-dirty --new-version ${{ inputs.version_to_bump_main }} major
git status

- name: "Commit Version Bump to Branch"
run: |
git add .
git commit -m "Bumping version to ${{ inputs.version_to_bump_main }}"
git push

- name: "Install Homebrew Packages"
run: |
brew install pre-commit
brew tap miniscruff/changie https://github.com/miniscruff/changie
brew install changie

- name: "Check if Any Unreleased Changelog Files Exists"
shell: bash
id: unreleased_changelog_check
run: |
git fetch origin ${{ inputs.sha }}
if echo grep '.changes/unreleased/.*.yaml'; then
echo "unreleased_exists=true" >> $GITHUB_OUTPUT
echo "Unreleased changelogs exist for this PR, they will be deleted"
else
echo "unreleased_exists=false" >> $GITHUB_OUTPUT
echo "No unreleased changelog exists for this PR, nothing to delete"
fi

- name: "Check if Any Prerelease Changelog Files Exists"
# prerelease changelog files will be under the current version, not the version we just bumped to
shell: bash
id: prerelease_changelog_check
run: |
git fetch origin ${{ inputs.sha }}
if echo grep '.changes/${{ steps.semver-current.outputs.base-version }}/.*.yaml'; then
echo "prerelease_exists=true" >> $GITHUB_OUTPUT
echo "Changelogs exist for this PR, delete them now"
else
echo "prerelease_exists=false" >> $GITHUB_OUTPUT
echo "No prerelease changelogs exists for this PR, nothing to delete"
fi

- name: "Delete Unreleased Changelog YAMLs"
if: ${{ steps.unreleased_changelog_check.outputs.unreleased_exists }} = true
run: |
rm .changes/unreleased/*.yaml

- name: "Delete Pre Release Changelogs and YAMLs"
if: ${{ steps.prerelease_changelog_check.outputs.prerelease_exists }} = true
run: |
rm .changes/${{ steps.semver-current.outputs.base-version }}/*.yaml
rm .changes/${{ steps.semver-current.outputs.major }}.${{ steps.semver-current.outputs.minor }}.*.md

- name: "Cleanup CHANGELOG.md"
run: |
changie merge

- name: "Commit Changelog Cleanup to Branch"
run: |
git add .
git commit -m "Clean up changelog on main"
git push

- name: "Determine PR Title"
id: pr_title
run: |
echo "pr_title=${{ inputs.PR_title }}" >> $GITHUB_OUTPUT
if ${{ inputs.PR_title }} == ""; then
echo "pr_title='Clean up changelogs and bump to version ${{ inputs.version_to_bump_main }}'" >> $GITHUB_OUTPUT
else

- name: "Determine PR Body"
id: pr_body
run: |
echo "pr_body=${{ inputs.PR_body }}" >> $GITHUB_OUTPUT
if ${{ inputs.PR_body }} == ""; then
echo "pr_body='Clean up changelogs and bump to version ${{ inputs.version_to_bump_main }}'" >> $GITHUB_OUTPUT
else

- name: "Create Pull Request"
id: create_pr
uses: peter-evans/create-pull-request@v3
with:
author: 'Github Build Bot <buildbot@fishtownanalytics.com>'
base: ${{github.ref}}
title: "${{ steps.pr_title.outputs.pr_title }}"
body: "${{ steps.pr_body.outputs.pr_body }}"
branch: '${{ steps.variables.output.BRANCH_NAME }}'
labels: |
Skip Changelog