-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Teddy Andrieux <[email protected]>
- Loading branch information
1 parent
07d52f7
commit 9155509
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
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: release-${{inputs.tag}} | ||
|
||
jobs: | ||
prepare-version: | ||
runs-on: ubuntu-24.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.4.0/src/semver | ||
chmod +x ./semver | ||
- name: Check hotfix releases | ||
env: | ||
SEMVER_TAG: ${{ inputs.tag }} | ||
run: | | ||
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 | ||
- 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 ${{inputs.tag}}" | ||
git push --set-upstream origin ${{env.RELEASE_BRANCH}} |