-
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 <teddy.andrieux@scality.com>
- Loading branch information
1 parent
1ed550d
commit 84e5ab9
Showing
1 changed file
with
215 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,215 @@ | ||
name: "Release" | ||
run-name: Release new ${{ inputs.version-type }} from ${{ github.ref_name }} | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version-type: | ||
description: "Version type" | ||
required: true | ||
type: choice | ||
default: "alpha" | ||
options: | ||
- "alpha" | ||
- "beta" | ||
- "GA" | ||
what-is-new: | ||
description: "What's new: it should be a JSON-formatted list such as [\"feature 1\", \"feature 2\"]" | ||
required: false | ||
default: "[]" | ||
type: string | ||
|
||
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: Validate what's new | ||
run: | | ||
# We just check if handle this input using jq will not fail. | ||
# If it does, the workflow will fail in a inconsistent way. | ||
echo '${{ inputs.what-is-new }}' | jq -r '.[]' | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ steps.app-token.outputs.token }} | ||
- name: Install buildchain dependencies | ||
run: | | ||
python3 -m pip install -r buildchain/requirements.txt | ||
- name: Install semver tool | ||
run: | | ||
curl --fail -LO https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.4.0/src/semver | ||
chmod +x ./semver | ||
- name: Compose release tag | ||
run: | | ||
source VERSION | ||
SHORT_VERSION="$VERSION_MAJOR.$VERSION_MINOR" | ||
BASE_VERSION="$SHORT_VERSION.$VERSION_PATCH" | ||
TAG="$BASE_VERSION" | ||
if [ "${{ inputs.version-type }}" == "alpha" ] || [ "${{ inputs.version-type }}" == "beta" ] ; then | ||
TAG="$TAG-${{ inputs.version-type }}" | ||
TAG_QUERY="$TAG*" | ||
elif [ "${{ inputs.version-type }}" == "GA" ]; then | ||
TAG_QUERY="$TAG" | ||
else | ||
echo "Invalid release type: ${{ inputs.version-type }}" | ||
exit 1 | ||
fi | ||
LAST_MATCH_TAG=$(git tag -l --sort=-v:refname "$TAG_QUERY" | head -n 1) | ||
if [ "${{ inputs.version-type }}" == "GA" ] && [ "$LAST_MATCH_TAG" != "" ]; then | ||
echo "Release $LAST_MATCH_TAG already exists" | ||
exit 1 | ||
fi | ||
if [ "${{ inputs.version-type }}" == "alpha" ] || [ "${{ inputs.version-type }}" == "beta" ] ; then | ||
SUFFIX_NUMBER="1" | ||
if [ "$LAST_MATCH_TAG" != "" ]; then | ||
SUFFIX_NUMBER=$(./semver get prerel $LAST_MATCH_TAG | cut -d'.' -f2) | ||
SUFFIX_NUMBER=$((SUFFIX_NUMBER + 1)) | ||
fi | ||
TAG="$TAG.$SUFFIX_NUMBER" | ||
fi | ||
echo "SHORT_VERSION=$SHORT_VERSION" >> $GITHUB_ENV | ||
echo "PATCH_VERSION=$VERSION_PATCH" >> $GITHUB_ENV | ||
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV | ||
echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV | ||
echo "RELEASE_BRANCH=release/$TAG" >> $GITHUB_ENV | ||
- name: Validate ${{ env.RELEASE_TAG }} tag | ||
run: ./semver validate ${{ env.RELEASE_TAG }} | ||
- name: Check if version ${{ env.BASE_VERSION }} is on the right branch | ||
run: | | ||
GIT_REMOTE=$(git remote) | ||
BASE_BRANCH=$(git branch -a --list ${GIT_REMOTE}/development/${{ env.SHORT_VERSION }}) | ||
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 [ "${{ inputs.version-type }}" == "GA" ]; then | ||
sed -i "s/## Release ${{ env.BASE_VERSION }} (in development)/## Release ${{ env.BASE_VERSION }}/" CHANGELOG.md | ||
git add CHANGELOG.md | ||
fi | ||
if [ -z "${NEW_VERSION_SUFFIX}" ]; then | ||
NEW_VERSION_SUFFIX=$(./semver get prerel ${{ env.RELEASE_TAG }}) | ||
[ -n "$NEW_VERSION_SUFFIX" ] && NEW_VERSION_SUFFIX="-$NEW_VERSION_SUFFIX" | ||
fi | ||
sed -i "s/VERSION_SUFFIX=.*/VERSION_SUFFIX=$NEW_VERSION_SUFFIX/" VERSION | ||
git add VERSION | ||
- name: Commit with requested version and push | ||
run: | | ||
git fsck | ||
git gc | ||
git config --global user.email ${{ github.actor }}@scality.com | ||
git config --global user.name ${{ github.actor }} | ||
git commit -m "Release ${{ env.RELEASE_TAG }}" | ||
git push --set-upstream origin ${{ env.RELEASE_BRANCH }} | ||
- name: Create and push `${{ env.RELEASE_TAG }}` tag | ||
run: | | ||
BODY=$(mktemp) | ||
K8S_VERSION=$(python3 -c 'from buildchain.buildchain import versions; print(versions.K8S_VERSION)') | ||
PATCH_MSG="MetalK8s ${{ env.RELEASE_TAG }} embeds Kubernetes $K8S_VERSION." | ||
if [ "${{ env.PATCH_VERSION }}" != "0" ]; then | ||
PATCH_MSG="MetalK8s ${{ env.RELEASE_TAG }} is a patch release (see [the main release ${{ env.SHORT_VERSION }}.0](https://github.com/scality/metalk8s/releases/${{ env.SHORT_VERSION }}.0))." | ||
fi | ||
cat > $BODY <<- EOM | ||
MetalK8s ${{ env.RELEASE_TAG }} | ||
=== | ||
$PATCH_MSG | ||
Useful links | ||
--- | ||
- [Documentation](https://metal-k8s.readthedocs.io/en/${{ env.RELEASE_TAG }}) | ||
- [Upgrade notes](https://metal-k8s.readthedocs.io/en/${{ env.RELEASE_TAG }}/operation/upgrade.html) | ||
- [Changelog](https://github.com/scality/metalk8s/blob/${{ env.RELEASE_TAG }}/CHANGELOG.md) | ||
EOM | ||
if [ '${{ inputs.what-is-new }}' != '[]' ]; then | ||
echo "What's new" >> $BODY | ||
echo "===" >> $BODY | ||
echo "" >> $BODY | ||
while IFS= read -r line; do | ||
echo "- $line" >> $BODY | ||
done <<< $(echo '${{ inputs.what-is-new }}' | jq -r '.[]') | ||
fi | ||
git tag -a "${{ env.RELEASE_TAG }}" -F $BODY | ||
git push origin ${{ env.RELEASE_TAG }} | ||
- name: Prepare branch to merge ${{ env.RELEASE_TAG }} tag | ||
run: | | ||
git checkout -b release/merge-${{ env.RELEASE_TAG }}-tag origin/development/${{ env.SHORT_VERSION }} | ||
git merge ${{ env.RELEASE_TAG }} --no-ff | ||
VERSION_PATCH=${{ env.PATCH_VERSION }} | ||
if [ "${{ inputs.version-type }}" == "GA" ]; then | ||
VERSION_PATCH=$((VERSION_PATCH + 1)) | ||
sed -i "s/## Release ${{ env.BASE_VERSION }}/## Release ${{ env.SHORT_VERSION }}.$VERSION_PATCH (in development)\n\n## Release ${{ env.BASE_VERSION }}/" CHANGELOG.md | ||
git add CHANGELOG.md | ||
sed -i "s/VERSION_PATCH=.*/VERSION_PATCH=$VERSION_PATCH/" VERSION | ||
fi | ||
sed -i "s/VERSION_SUFFIX=.*/VERSION_SUFFIX=-dev/" VERSION | ||
git add VERSION | ||
git commit --amend --no-edit | ||
git push --set-upstream origin release/merge-${{ env.RELEASE_TAG }}-tag | ||
- name: Look for important messages | ||
id: warn_user | ||
run: | | ||
link="https://github.com/${{ github.repository }}/blob/${{ env.RELEASE_TAG }}/" | ||
{ | ||
echo 'COMMENT<<EOF' | ||
echo "# Mentions of ${{ env.RELEASE_TAG }} in ${{ github.ref_name }}" | ||
git grep -rHn "${{ env.RELEASE_TAG }}" | sed -E "s;(.*):([0-9]+):.*;$link\1#L\2;" | ||
echo EOF | ||
} >> "$GITHUB_ENV" | ||
- name: Create pull request | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const pr = await github.rest.pulls.create({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
head: "release/merge-${{ env.RELEASE_TAG }}-tag", | ||
base: "development/${{ env.SHORT_VERSION }}", | ||
title: "Merge release tag for ${{ env.RELEASE_TAG }}" | ||
}); | ||
await github.rest.issues.createComment({ | ||
issue_number: pr.data.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `${{ env.COMMENT }}` | ||
}); | ||
await github.rest.issues.createComment({ | ||
issue_number: pr.data.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: '/approve' | ||
}) |