Skip to content

Commit

Permalink
ci/release: add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
aprucolimartins committed Nov 18, 2024
1 parent 9979111 commit 8af8cfd
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: "Release"
run-name: Release ${{ inputs.tag }}

on:
workflow_dispatch:
inputs:
revision:
type: string
description: "commit sha1 revision where to start the release, must be the long commit sha1"
required: true
tag:
type: string
description: "the new tag/release version to create"
required: true

env:
RELEASE_BRANCH: feature/release-${{inputs.tag}}

jobs:
prepare-version:
runs-on: ubuntu-20.04
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.ACTIONS_APP_ID }}
private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{inputs.revision}}
token: ${{ steps.app-token.outputs.token }}
- name: Install semver tool
run: |
curl --fail -LO https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.3.0/src/semver
chmod +x ./semver
- name: Check hotfix releases
env:
SEMVER_TAG: ${{ inputs.tag }}
run: |
if [[ "$SEMVER_TAG" =~ ^([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)\.([[:digit:]]+)(.*) ]]; then
echo "Hotfix version detected: ${BASH_REMATCH[1]}, hotfix: ${BASH_REMATCH[2]}, prerelease: ${BASH_REMATCH[3]}"
echo HOTFIX_VERSION="${BASH_REMATCH[2]}" >> $GITHUB_ENV
echo NEW_VERSION_SUFFIX=".${BASH_REMATCH[2]}${BASH_REMATCH[3]}" >> $GITHUB_ENV
# if a hotfix version is detected, we 'tweak' the tag to make it a valid semver tag
# This will only be usd for internal validation, the "official" tag will be the 4-digit
# tag that was provided
SEMVER_TAG="${BASH_REMATCH[1]}-hotfix.${BASH_REMATCH[2]}${BASH_REMATCH[3]}"
fi
echo SEMVER_TAG="$SEMVER_TAG" >> $GITHUB_ENV
- name: Validate input tag
run: ./semver validate $SEMVER_TAG
- name: Prevent major/minor version change
run: |
source VERSION
diff=$(./semver diff "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH$VERSION_SUFFIX" $SEMVER_TAG)
if [[ "$diff" == "prerelease" ]]
then
echo "version match"
exit 0
fi
# prevent changes on major/minor/patch version
# major/minor these are done manually by creating a new dev/* branch
# patch is done at the end of this workflow
echo "version mismatch, can only upgrade patch version"
exit 1
- name: Check version is on the right branch
run: |
source VERSION
# Need to unshallow and fetch dev branches first
git fetch --unshallow --no-tags origin HEAD '+refs/heads/development/*:refs/remotes/origin/development/*'
GIT_REMOTE=$(git remote)
BASE_BRANCH=$(git branch -a --list ${GIT_REMOTE}/development/${VERSION_MAJOR}.${VERSION_MINOR})
if ! git merge-base --is-ancestor HEAD ${BASE_BRANCH}; then
echo "Version commit is not included in base branch ${BASE_BRANCH}"
exit 1
fi
NEXT_MAJOR=$((VERSION_MAJOR+1)).0
NEXT_MINOR=${VERSION_MAJOR}.$((VERSION_MINOR+1))
NEXT_PATCH=${VERSION_MAJOR}.${VERSION_MINOR}.$((VERSION_PATCH+1))
for BRANCH in $(git branch -a --list ${GIT_REMOTE}/development/{$NEXT_MAJOR,$NEXT_MINOR,$NEXT_PATCH}); do
if git merge-base --is-ancestor $BRANCH HEAD ; then
echo "Version commit includes next target branch ${BRANCH}"
exit 1
fi
done
- name: Prepare branch
run: git checkout -b ${{env.RELEASE_BRANCH}}
- name: Set the new version
run: |
if [ -z "${NEW_VERSION_SUFFIX}" ]; then
NEW_VERSION_SUFFIX=$(./semver get prerel ${{inputs.tag}})
[ -n "$NEW_VERSION_SUFFIX" ] && NEW_VERSION_SUFFIX="-$NEW_VERSION_SUFFIX"
fi
sed -i "s/VERSION_SUFFIX=.*/VERSION_SUFFIX=$NEW_VERSION_SUFFIX/" VERSION
- name: Commit with requested version and push
run: |
git fsck
git gc
git add VERSION
git config --global user.email ${{github.actor}}@scality.com
git config --global user.name ${{github.actor}}
git commit -m "Release version ${{inputs.tag}}"
git push --set-upstream origin ${{env.RELEASE_BRANCH}}
- name: Create Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
with:
name: Release ${{ inputs.tag }}
tag_name: ${{ inputs.tag }}
generate_release_notes: true
target_commitish: ${{ env.RELEASE_BRANCH }}
outputs:
supported-until-date: ${{ steps.compute-supported-until-date.outputs.supported-until-date }}

0 comments on commit 8af8cfd

Please sign in to comment.