diff --git a/.github/workflows/rc.yml b/.github/workflows/rc.yml new file mode 100644 index 0000000..dbd6e7d --- /dev/null +++ b/.github/workflows/rc.yml @@ -0,0 +1,55 @@ +# Release Candidate GitHub Action + +name: release_candidate + +# TODO(actions): +# - [x] create a new AUTO-RC- branch +# - [x] update CHANGES.rst +# - [x] create changes commit +# - [x] push to GH +# - [ ] update README.rst +# - [ ] create readme commit +# - [ ] push to GH +# - [ ] open a PR to `master` + +# TODO(general): +# - [ ] setup the action +# - [ ] cleanup the action + +on: + schedule: + - cron: '0 0 1 * *' # each 1st day of the month + workflow_dispatch: # on manual trigger + + +jobs: + new-rc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # Flag to fetch all history. + # @see https://github.com/marketplace/actions/checkout#Fetch-all-history-for-all-tags-and-branches + fetch-depth: 0 + - run: | + RC_DATE=$(date +'%m-%d-%Y') + git config user.name github-actions + git config user.email github-actions@github.com + git checkout -b auto-release-candidate-${RC_DATE} + git push -u origin auto-release-candidate-${RC_DATE} + + git status + git fetch + + ./bin/update_changelog.sh + + git add CHANGES.rst + git commit -m "chore(rc-changes): update Changes.rst" + git push + + gh pr create --title "chore(auto-release-candidate-${RC_DATE})" \ + --body "Automated release candidate for ${RC_DATE}." \ + --base master \ + --draft + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index af31ba3..8fc1802 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ __pycache__/ .venv/ venv/ +# Release Candidate Artifacts +rc/ \ No newline at end of file diff --git a/bin/update_changelog.sh b/bin/update_changelog.sh new file mode 100755 index 0000000..5ff5ce4 --- /dev/null +++ b/bin/update_changelog.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash + +# Script to create a new RC entry +# +# Actions: +# 1. find latest published version +# 2. find the TBD planned big version +# 3. create new RC version entry +# 4. add change log entries + +set -e # exit on errors + +# TODO: provide that as parameters? + +CHANGE_FILE='CHANGES.rst' +RC_DATE=$(date +'%m-%d-%Y') +WORKSPACE_DIR="${GITHUB_WORKSPACE:-.}/rc" +TMP_CHANGE_LOG="${WORKSPACE_DIR}/rc-${RC_DATE}.txt" + + +############ +# CLEANUPS # +############ + +rm -rf $TMP_CHANGE_LOG +mkdir -p $WORKSPACE_DIR + + +################## +# INITIALIZATION # +################## + +echo "Updating $CHANGE_FILE:" + +LAST_VERSION=$(grep -m1 -E ' \([0-9]+-[0-9]+-[0-9]+\)$' $CHANGE_FILE | awk '{ print $1 }') + +echo "Detected last release version: $LAST_VERSION" + + +################### +# VERSION BUMPING # +################### + + +echo "Bumping patch version..." +MAJOR_COLUMN=1 +MINOR_COLUMN=2 +PATCH_COLUMN=3 + +# `awk` is used to bump the PATCH version since the last public release. +# -F - gives a separator for splitting the original release into columns. +# -v - provides a value for variable to be used in the `awk` command. +# -v K=$PATCH_COLUMN - provides value for `K` - the version column to bump. +# This attempts to preserve the a standard syntax for GNU Awk. +# More can be found here: https://www.gnu.org/software/gawk/manual/gawk.html +BUMPED_VERSION=$(echo $LAST_VERSION | awk -F. -v K=$PATCH_COLUMN '{$K+=1; print $0}' OFS='.') + +echo "Bumped to new candidate version: $BUMPED_VERSION" + +RC_VERSION=${BUMPED_VERSION}rc${RC_DATE} + +echo "Final RC version: $RC_VERSION" + + +################### +# CHANGELOG ENTRY # +################### + + +CHANGE_DIFF_TARGETS="v${LAST_VERSION}..HEAD" +VERSION_TITLE="${RC_VERSION} (__rc__)" +# Using GNU Awk syntax: -v LL specifies the title pattern variable. +TITLE_LINE=$(awk -v LL=${#VERSION_TITLE} 'BEGIN{for(c=0;c> $TMP_CHANGE_LOG + +# COLLECT ALL COMMITS: +git log --pretty=oneline --abbrev-commit $CHANGE_DIFF_TARGETS | sed 's/^/- /' >> $TMP_CHANGE_LOG +# DEBUG: +git log --pretty=oneline --abbrev-commit $CHANGE_DIFF_TARGETS | sed 's/^/- /' + +# CHECK FINAL CONTENT +echo -e "\nCollected info:" +ls $WORKSPACE_DIR +cat $TMP_CHANGE_LOG + +# APPEND INFO TO CHANGE FILE: +# 1. Finds the first (tbd) release +# 2. Populates space between (tbd) release and the latest one with RC changes +# NB: supporting macos and linux interoperability +# see https://stackoverflow.com/questions/43171648/sed-gives-sed-cant-read-no-such-file-or-directory +if [[ "$OSTYPE" == "darwin"* ]]; then +# begin: mac os support +sed -i '' "/^[0-9]\.0\.0.*\(tbd\)/{N;G;r\ +\ +$TMP_CHANGE_LOG +\ +}" $CHANGE_FILE +# end; +else +# begin: linux support +sed -i "/^[0-9]\.0\.0.*\(tbd\)/{N;G;r\ +\ +$TMP_CHANGE_LOG +\ +}" $CHANGE_FILE +# end; +fi + +# CHANGE_LOG_CONTENTS=$(cat $TMP_CHANGE_LOG)