Skip to content

Code freeze

Code freeze #3

name: "Code freeze"
on:
workflow_dispatch:
inputs:
is_major:
description: Whether to do a major bump
required: false
default: False
type: boolean
is_prelease:
description: Whether to keep and bump the pre-release label
required: false
default: false
type: boolean
jobs:
validate-inputs:
runs-on: ubuntu-latest
steps:
- name: main
run: |
if [[ "${{ inputs.is_major }}" == "true" && "${{ inputs.is_prelease }}" == "true" ]]; then
echo Please either major or pre-release, not both
exit 1
fi
create-release-branch:
runs-on: ubuntu-latest
if: contains(fromJSON('["ko3n1g"]'), github.actor)
needs: [validate-inputs]
environment:
name: main
outputs:
version: ${{ steps.release-branch.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
path: ${{ github.run_id }}
fetch-depth: 0
fetch-tags: true
ref: main
token: ${{ secrets.PAT }}
- name: Get release branch ref
id: release-branch
run: |
cd ${{ github.run_id }}
if [[ "${{ inputs.is_prelease }}" == "false" ]]; then
sed -i "/^PRE_RELEASE/c\PRE_RELEASE = ''" nemo_aligner/package_info.py
fi
VERSION=$(python -c 'import nemo_aligner; print(nemo_aligner.__version__)')
echo "Release version r$VERSION" > version
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
git switch --force-create r$VERSION origin/main
git push -u origin r$VERSION --force
bump-next-version:
runs-on: ubuntu-latest
needs: [create-release-branch]
environment:
name: main
env:
VERSION_FILE: nemo_aligner/package_info.py
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
path: ${{ github.run_id }}
fetch-depth: 0
fetch-tags: true
ref: main
token: ${{ secrets.PAT }}
- name: Bump version
id: bump-version
run: |
cd ${{ github.run_id }}
PRE_RELEASE=$(cat nemo_aligner/package_info.py | awk '/^PRE_RELEASE = /' | awk -F"= " '{print $2}' | tr -d '"' | tr -d "'")
MAJOR=$(cat nemo_aligner/package_info.py | awk '/^MAJOR = /' | awk -F"= " '{print $2}')
MINOR=$(cat nemo_aligner/package_info.py | awk '/^MINOR = /' | awk -F"= " '{print $2}')
PATCH=$(cat nemo_aligner/package_info.py | awk '/^PATCH = /' | awk -F"= " '{print $2}')
if [[ "${{ inputs.is_prelease }}" == "true" ]]; then
NEXT_MAJOR=$MAJOR
NEXT_MINOR=$MINOR
NEXT_PRE_RELEASE=rc$(( $(echo $PRE_RELEASE | awk -F"rc" '{print $2}') + 1))
else
NEXT_MAJOR=$(( MAJOR + 1))
NEXT_MINOR='0'
NEXT_PRE_RELEASE="'rc0'"
fi
sed -i "/^MAJOR/c\MAJOR = $NEXT_MAJOR" nemo_aligner/package_info.py
sed -i "/^MINOR/c\MINOR = $NEXT_MINOR" nemo_aligner/package_info.py
sed -i "/^PRE_RELEASE/c\PRE_RELEASE = '$NEXT_PRE_RELEASE'" nemo_aligner/package_info.py
echo "version=$NEXT_MAJOR.$NEXT_MINOR.$PATCH$NEXT_PRE_RELEASE" >> "$GITHUB_OUTPUT"
- name: Create Version Bump PR
uses: peter-evans/create-pull-request@v6
id: create-pull-request
with:
path: ${{ github.run_id }}
branch: bot/chore/version-bump-${{ steps.bump-version.outputs.version }}
title: 'Version bump to `${{ steps.bump-version.outputs.version }}`'
body: |
🚀 Version bump NeMo-Aligner to `${{ steps.bump-version.outputs.version }}`
commit-message: "[🤠]: Howdy folks, let's bump NeMo-Aligner `${{ steps.bump-version.outputs.version }}` !"
signoff: true
assignees: okoenig
labels: 'Run CICD'
notify:
runs-on: ubuntu-latest
needs: [create-release-branch, bump-next-version]
environment:
name: main
steps:
- name: Main
run: |
MESSAGE='{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Releasebot 🤖: NeMo-Aligner has been frozen 🎉 to branch `r${{ needs.create-release-branch.outputs.version }}`"
}
}
]
}'
curl -X POST -H "Content-type: application/json" --data "$MESSAGE" ${{ secrets.SLACK_RELEASE_ENDPOINT }}