Skip to content

Commit

Permalink
Release pipeline for Helm charts (#133)
Browse files Browse the repository at this point in the history
Release pipeline
  • Loading branch information
leandroberetta authored Apr 29, 2022
1 parent 44c888f commit 07ce0db
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 0 deletions.
185 changes: 185 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: Release

on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'auto'
type: choice
options:
- minor
- patch
release_branch:
description: Branch to release
required: true
default: master
type: string

jobs:
initialize:
name: Initialize
runs-on: ubuntu-20.04
outputs:
release_version: ${{ steps.release_version.outputs.release_version }}
next_version: ${{ steps.next_version.outputs.next_version }}
branch_version: ${{ steps.branch_version.outputs.branch_version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.releasing_branch }}

- name: Determine release version
env:
RELEASE_TYPE: ${{ github.event.inputs.release_type }}
id: release_version
run: |
RAW_VERSION=$(sed -rn 's/^VERSION \?= (.*)/\1/p' Makefile)
# Remove any pre release identifier (ie: "-SNAPSHOT")
RELEASE_VERSION=${RAW_VERSION%-*}
# If we are doing a patch release, the Makefile contains a version that is already released.
# The version present in the Makefile needs to be bumped and that's our releasing version.
# The next version is two patches from whatever is present in the Makefile.
if [[ $RELEASE_TYPE == "patch" ]]
then
RELEASE_VERSION=$(./.github/workflows/util/bump.py $RELEASE_TYPE $RELEASE_VERSION)
fi
echo "::set-output name=release_version::$RELEASE_VERSION"
- name: Determine next version
env:
RELEASE_TYPE: ${{ github.event.inputs.release_type }}
RELEASE_VERSION: ${{ steps.release_version.outputs.release_version }}
id: next_version
run: |
if [[ $RELEASE_TYPE == "patch" ]]
then
NEXT_VERSION=$(./.github/workflows/util/bump $RELEASE_TYPE $RELEASE_VERSION)
elif [[ $RELEASE_TYPE == "minor" ]]
then
NEXT_VERSION=$(./.github/workflows/util/bump.py $RELEASE_TYPE $RELEASE_VERSION)
fi
echo "::set-output name=next_version::$NEXT_VERSION"
- name: Determine branch version
env:
RELEASE_VERSION: ${{ steps.release_version.outputs.release_version }}
id: branch_version
run: echo "::set-output name=branch_version::$(echo $RELEASE_VERSION | sed 's/\.[0-9]*\+$//')"

- name: Log information
run: |
echo "Release version: ${{ steps.release_version.outputs.release_version }}"
echo "Next version: ${{ steps.next_version.outputs.next_version }}"
echo "Branch version: ${{ steps.branch_version.outputs.branch_version }}"
release:
name: Release
runs-on: ubuntu-20.04
needs: [initialize]
env:
RELEASE_TYPE: ${{ github.event.inputs.release_type }}
RELEASE_VERSION: ${{ needs.initialize.outputs.release_version }}
NEXT_VERSION: ${{ needs.initialize.outputs.next_version }}
BRANCH_VERSION: ${{ needs.initialize.outputs.branch_version }}
RELEASE_BRANCH: ${{ github.event.inputs.release_branch }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.releasing_branch }}

- name: Configure git
run: |
git config user.email '[email protected]'
git config user.name 'kiali-bot'
- name: Build Helm charts
run: make -e VERSION=$RELEASE_VERSION clean build-helm-charts

# Switch to `master` branch before updating docs/index.yaml
- name: Checkout master
if: ${{ github.event.inputs.release_type == 'patch'}}
run: git checkout master

# Anticipated preparation of Makefile so that it contains the released
# version when creating the git tag.
#
# This change to the Makefile is not done for patch releases, because that
# would break the next minor build (remember we have already switched to master).
- name: Prepare Makefile
if: ${{ github.event.inputs.release_type != 'patch'}}
run: sed -i -r "s/^VERSION \?= .*/VERSION \?= $RELEASE_VERSION/" Makefile

- name: Update Helm repositories
run: make -e VERSION=$RELEASE_VERSION update-helm-repos

# Tag the release from sources in the master branch
# Note that if we are doing a patch release, this tag won't contain valid `kiali-server` nor `kiali-operator` directories
# because these directories come from `master` rather than the original ones.
- name: Create tag
run: |
git add Makefile docs
git commit -m "Release $RELEASE_VERSION"
git push origin $(git rev-parse HEAD):refs/tags/$RELEASE_VERSION-master
- name: Publish Helm charts
env:
BUILD_TAG: helm-charts-release-${{ github.run_number }}-main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# If we did a minor release, we need to create the vX.Y branch, so that it can
# be used as a base for a patch release.
# Also, we create a vX.Y.Z tag.
if [[ $RELEASE_TYPE == "minor" ]]
then
git push origin $(git rev-parse HEAD):refs/heads/$BRANCH_VERSION
git push origin $(git rev-parse HEAD):refs/tags/$RELEASE_VERSION
# Bump version stored in the Makefile
sed -i -r "s/^VERSION \?= (.*)/VERSION \?= $NEXT_VERSION-SNAPSHOT/" Makefile
git add Makefile
git commit -m "Prepare for next version"
git push origin $(git rev-parse HEAD):refs/heads/$BUILD_TAG
gh pr create -t "Prepare for next version" -b "Please, merge to update version numbers and prepare for release $NEXT_VERSION." -H $BUILD_TAG -B $RELEASE_BRANCH
# For a patch release, everything is ready to publish the generated charts.
# Let's push to master
elif [[ $RELEASE_TYPE == "patch" ]]
then
git push origin $(git rev-parse HEAD):refs/heads/$BUILD_TAG
gh pr create -t "Prepare for next version" -b "Please, merge to update version numbers and prepare for release $NEXT_VERSION." -H $BUILD_TAG -B $RELEASE_BRANCH
# We did a patch release. In this case we need to go back to the version branch and do changes
# to the Makefile in that branch to record what's the current path release. Then, commit and push.
# Also, a vX.Y.Z branch is created
git checkout $RELEASE_BRANCH
sed -i -r "s/^VERSION \?= (.*)/VERSION \?= $RELEASE_VERSION/" Makefile
git add Makefile
git commit -m "Record that $RELEASE_VERSION was released, in preparation for next patch version."
git push origin $(git rev-parse HEAD):$RELEASE_BRANCH
git push origin $(git rev-parse HEAD):refs/tags/$RELEASE_VERSION
fi
24 changes: 24 additions & 0 deletions .github/workflows/util/bump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

import sys

release_type = sys.argv[1]
version = sys.argv[2]

parts = version.split('.')

major = int(parts[0][1:])
minor = int(parts[1])
patch = int(parts[2])

if release_type == 'major':
major = major + 1
minor = 0
patch = 0
elif release_type == 'minor':
minor = minor + 1
patch = 0
elif release_type == 'patch':
patch = patch + 1

print('.'.join(["v" + str(major), str(minor), str(patch)]))

0 comments on commit 07ce0db

Please sign in to comment.