Skip to content

Publish Release

Publish Release #40

name: Publish Release
on:
pull_request:
types:
- closed
branches:
- 'main'
workflow_dispatch:
inputs:
version:
description: 'Version for manual hotfix release.'
required: false
default: ''
concurrency:
group: publish-release
cancel-in-progress: false
jobs:
pre-release-checks:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set Version from the PR title.
if: github.event_name == 'pull_request'
run: |
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.pull_request.title }}" >> ${GITHUB_ENV}
- name: Major Version in Upgrade Handler Must Match Tag
if: github.event_name == 'pull_request'
run: |
UPGRADE_HANDLER_MAJOR_VERSION=$(cat app/setup_handlers.go | grep "const releaseVersion" | cut -d ' ' -f4 | tr -d '"')
echo $UPGRADE_HANDLER_MAJOR_VERSION
echo $GITHUB_TAG_MAJOR_VERSION
if [ $GITHUB_TAG_MAJOR_VERSION != $UPGRADE_HANDLER_MAJOR_VERSION ]; then
echo "ERROR: The major version of this release (${{ github.ref_name }}) does not match the major version in the releaseVersion constant ($UPGRADE_HANDLER_MAJOR_VERSION) found in app/setup_handlers.go"
echo "Did you forget to update the 'releaseVersion' in app/setup_handlers.go?"
exit 1
fi
echo "The major version found in 'releaseVersion' in app/setup_handlers.go matches this tagged release - Moving Forward!"
publish-release:
runs-on: buildjet-4vcpu-ubuntu-2004
timeout-minutes: 60
needs:
- pre-release-checks
steps:
- uses: actions/checkout@v3
- name: Echo Release Notes from PR Message.
if: github.event_name == 'pull_request'
id: release_notes
run: |
cat changelog.md > ${{ github.workspace }}-CHANGELOG.txt
cat ${{ github.workspace }}-CHANGELOG.txt
- name: Set Version from the PR title.
if: github.event_name == 'pull_request'
run: |
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.pull_request.title }}" >> ${GITHUB_ENV}
- name: Set Version for Hotfix Release from Input.
if: github.event_name != 'pull_request'
run: |
echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.inputs.version }}" >> ${GITHUB_ENV}
- name: Set CPU Architecture
shell: bash
run: |
if [ "$(uname -m)" == "aarch64" ]; then
echo "CPU_ARCH=arm64" >> $GITHUB_ENV
elif [ "$(uname -m)" == "x86_64" ]; then
echo "CPU_ARCH=amd64" >> $GITHUB_ENV
else
echo "Unsupported architecture" >&2
exit 1
fi
- name: Install Pipeline Dependencies
uses: ./.github/actions/install-dependencies
timeout-minutes: 8
with:
cpu_architecture: ${{ env.CPU_ARCH }}
skip_python: "true"
skip_aws_cli: "true"
skip_docker_compose: "true"
- name: Create Release Tag
shell: bash
run: |
git tag ${GITHUB_TAG_MAJOR_VERSION}
create_tag=$(git push --tags || echo "tag exists")
if [[ $create_tag == "tag exists" ]]; then
echo "Delete existing tag to re-create"
git tag -d ${GITHUB_TAG_MAJOR_VERSION}
git push --delete origin ${GITHUB_TAG_MAJOR_VERSION}
echo "sleep for 5 seconds to let github catch up."
sleep 5
echo "Re-Create Tag."
git tag ${GITHUB_TAG_MAJOR_VERSION}
git push --tags
fi
- name: Create GitHub Release on Pull Request
if: github.event_name == 'pull_request'
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }}
body_path: ${{ github.workspace }}-CHANGELOG.txt
tag_name: ${{ env.GITHUB_TAG_MAJOR_VERSION }}
- name: Create GitHub Release Hot Fix
if: github.event_name != 'pull_request'
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }}
generate_release_notes: true
tag_name: ${{ env.GITHUB_TAG_MAJOR_VERSION }}
- name: Publish Release Files
env:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }}
GORELEASER_CURRENT_TAG: ${{ env.GITHUB_TAG_MAJOR_VERSION }}
run: |
touch .release-env
make release
- name: Clean Up Workspace
if: always()
shell: bash
run: sudo rm -rf * || echo "failed to cleanup workspace please investigate"