Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workflow to release for major/minor/patch #78

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 14 additions & 66 deletions .github/workflows/release.yml → .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
#
name: Run release
on:
push:
branches:
- "release/v*.*"
- "!release/v*.*.*"
workflow_call:
inputs:
release_branch_name:
type: string
description: "The release branch name. e.g release/v1.7"
required: true
release_tag:
type: string
description: "The release tag"
required: true

jobs:
dump-contexts-to-log:
Expand All @@ -31,79 +37,21 @@ jobs:
uses: ./.github/workflows/_detect-ci-container.yml
secrets: inherit

semver-auto:
runs-on: ubuntu-latest
outputs:
RELEASE_BRANCH_NAME_SUFFIX: ${{ steps.set_context.outputs.RELEASE_BRANCH_NAME_SUFFIX }}
RELEASE_TAG: ${{ steps.upgrade_semver.outputs.RELEASE_TAG }}
RELEASE: ${{ steps.upgrade_semver.outputs.RELEASE }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set Github context
id: set_context
run: |
RELEASE_BRANCH_NAME_SUFFIX=`echo '${{ github.ref }}' | sed -e 's:^refs/heads/release/::'`
BRANCH_LATEST_TAG=`git tag | grep ${RELEASE_BRANCH_NAME_SUFFIX} | tail -n 1`
RELEASE_KIND=`echo "${{ github.event.head_commit.message }}" | sed -n -E 's:^\[(major|minor|patch)\].*:\1:p'`

echo "RELEASE_BRANCH_NAME_SUFFIX=${RELEASE_BRANCH_NAME_SUFFIX}" >> $GITHUB_OUTPUT # e.g) vx.x
echo "BRANCH_LATEST_TAG=${BRANCH_LATEST_TAG}" >> $GITHUB_OUTPUT # e.g) vx.x.x or empty
echo "RELEASE_KIND=${RELEASE_KIND}" >> $GITHUB_OUTPUT # e.g) major or minor or patch or empty

echo "${RELEASE_BRANCH_NAME_SUFFIX}"
echo "${BRANCH_LATEST_TAG}"
echo "${RELEASE_KIND}"

- name: Upgrade semver
id: upgrade_semver
if: ${{ steps.set_context.outputs.RELEASE_KIND != '' }}
env:
RELEASE_BRANCH_NAME_SUFFIX: ${{ steps.set_context.outputs.RELEASE_BRANCH_NAME_SUFFIX }}
BRANCH_LATEST_TAG: ${{ steps.set_context.outputs.BRANCH_LATEST_TAG }}
RELEASE_KIND: ${{ steps.set_context.outputs.RELEASE_KIND }}
run: |
if [ -z "${BRANCH_LATEST_TAG}" ]; then
case ${RELEASE_KIND} in
major | minor) RELEASE_TAG="${RELEASE_BRANCH_NAME_SUFFIX}.0"; ;;
*) echo "not supported semver kind"; exit 1; ;;
esac
else
IFS=. read -r version minor patch <<< "${BRANCH_LATEST_TAG}"

case ${RELEASE_KIND} in
patch) RELEASE_TAG="$version.$minor.$((patch+1))"; ;;
*) echo "not supported semver kind"; exit 1; ;;
esac
fi

if [ `git tag | grep "${RELEASE_TAG}"` ] || [ `cat versions/VALD_VERSION` = "${RELEASE_TAG}" ]; then
echo "release already exists: ${RELEASE_TAG}"
exit 1
fi

echo "RELEASE=true" >> $GITHUB_OUTPUT
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT # e.g) vx.x.x

echo "${RELEASE_TAG}"

release:
needs:
- dump-contexts-to-log
- detect-ci-container
- semver-auto
runs-on: ubuntu-latest
if: ${{ needs.semver-auto.outputs.RELEASE == 'true' }}
container:
image: ghcr.io/vdaas/vald/vald-ci-container:${{ needs.detect-ci-container.outputs.TAG_NAME }}
env:
RELEASE_BRANCH_NAME: release/${{ needs.semver-auto.outputs.RELEASE_BRANCH_NAME_SUFFIX }}
RELEASE_TAG: ${{ needs.semver-auto.outputs.RELEASE_TAG }}
RELEASE_BRANCH_NAME: ${{ inputs.release_branch_name }}
RELEASE_TAG: ${{ inputs.release_tag }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.DISPATCH_TOKEN }}

- name: Set Git config
run: |
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/release-major-minor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: "Run [major/minor] Release"
on:
push:
branches:
- "main"
env:
BACKPORT_LABEL_PREFIX: "actions/backport/"

jobs:
dump-contexts-to-log:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/dump-context

semver-auto:
runs-on: ubuntu-latest
needs: [dump-contexts-to-log]
outputs:
RELEASE_BRANCH_NAME: ${{ steps.set_context.outputs.RELEASE_BRANCH_NAME }}
RELEASE: ${{ steps.upgrade_semver.outputs.RELEASE }}
RELEASE_TAG: ${{ steps.upgrade_semver.outputs.RELEASE_TAG }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.DISPATCH_TOKEN }}

- name: Set Git config
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}

- name: Set context
id: set_context
run: |
LATEST_TAG=`git tag --sort=v:refname | tail -n 1`
UNSUPPORTED_VERSION=`git tag --sort=v:refname | sed -E 's/^v([0-9]+\.[0-9]+).*$/v\1/' | uniq | tail -n 2 | head -n 1`
RELEASE_KIND=`echo "${{ github.event.head_cmmit.message }}" | sed -n -E 's:^\[(major|minor)\].*:\1:p'`

echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_OUTPUT # e.g) v1.7.6
echo "RELEASE_KIND=${RELEASE_KIND}" >> $GITHUB_OUTPUT # e.g) major or minor
echo "UNSUPPORTED_VERSION=${UNSUPPORTED_VERSION}" >> $GITHUB_OUTPUT # e.g) v1.6

echo "LATEST_TAG=${LATEST_TAG}"
echo "RELEASE_KIND=${RELEASE_KIND}"
echo "UNSUPPORTED_VERSION=${UNSUPPORTED_VERSION}"

- name: Upgrade semver
id: upgrade_semver
if: ${{ steps.set_context.outputs.RELEASE_KIND != '' }}
env:
LATEST_TAG: ${{ steps.set_context.outputs.LATEST_TAG }}
RELEASE_KIND: ${{ steps.set_context.outputs.RELEASE_KIND }}
run: |
IFS=. read -r version minor patch <<< `echo "${LATEST_TAG}" | sed -e 's:^v::'`

case ${RELEASE_KIND} in
major) RELEASE_TAG="v$((version+1)).0.0"; RELEASE_BRANCH_NAME="release/v$((version+1)).0"; ;;
minor) RELEASE_TAG="v$version.$((minor+1)).0"; RELEASE_BRANCH_NAME="release/v$version.$((minor+1))"; ;;
*) echo "no need to update"; exit 0; ;;
esac

echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_OUTPUT
echo "RELEASE_BRANCH_NAME=${RELEASE_BRANCH_NAME}" >> $GITHUB_OUTPUT

echo "RELEASE_TAG=${RELEASE_TAG}"
echo "RELEASE_BRANCH_NAME=${RELEASE_BRANCH_NAME}"

- name: Setup branch
id: setup_branch
if: ${{ steps.upgrade_semver.outputs.RELEASE_TAG != '' }}
env:
RELEASE_TAG: ${{ steps.upgrade_semver.outputs.RELEASE_TAG }}
RELEASE_BRANCH_NAME: ${{ steps.upgrade_semver.outputs.RELEASE_BRANCH_NAME }}
run: |
git checkout -b ${RELEASE_BRANCH_NAME} && git push origin ${RELEASE_BRANCH_NAME}
gh label create "${BACKPORT_LABEL_PREFIX}${RELEASE_BRANCH_NAME}" # e.g) actions/backport/release/v1.8

echo "RELEASE=true" >> ${GITHUB_OUTPUT}
echo "RELEASE_TAG=${RELEASE_TAG}"
echo "RELEASE_BRANCH_NAME=${RELEASE_BRANCH_NAME}"
echo "LABEL_NAME=${BACKPORT_LABEL_PREFIX}${RELEASE_BRANCH_NAME}"

release:
if: ${{ needs.semver-auto.outputs.RELEASE == 'true' }}
needs:
- semver-auto
uses: ./.github/workflows/_release.yml
with:
release_branch_name: ${{ needs.semver-auto.outputs.RELEASE_BRANCH_NAME }}
release_tag: ${{ needs.semver-auto.outputs.RELEASE_TAG }}
secrets: inherit
83 changes: 83 additions & 0 deletions .github/workflows/release-patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: "Run patch release"
on:
push:
branches:
- "release/v*.*"
- "!release/v*.*.*"

jobs:
dump-contexts-to-log:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/dump-context

semver-auto:
runs-on: ubuntu-latest
outputs:
RELEASE_BRANCH_NAME_SUFFIX: ${{ steps.set_context.outputs.RELEASE_BRANCH_NAME_SUFFIX }}
RELEASE_TAG: ${{ steps.upgrade_semver.outputs.RELEASE_TAG }}
RELEASE: ${{ steps.upgrade_semver.outputs.RELEASE }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set context
id: set_context
run: |
RELEASE_BRANCH_NAME_SUFFIX=`echo '${{ github.ref }}' | sed -e 's:^refs/heads/release/::'`
BRANCH_LATEST_TAG=`git tag | grep ${RELEASE_BRANCH_NAME_SUFFIX} | tail -n 1`
RELEASE_KIND=`echo "${{ github.event.head_commit.message }}" | sed -n -E 's:^\[(patch)\].*:\1:p'`

echo "RELEASE_BRANCH_NAME_SUFFIX=${RELEASE_BRANCH_NAME_SUFFIX}" >> $GITHUB_OUTPUT # e.g) vx.x
echo "BRANCH_LATEST_TAG=${BRANCH_LATEST_TAG}" >> $GITHUB_OUTPUT # e.g) vx.x.x or empty
echo "RELEASE_KIND=${RELEASE_KIND}" >> $GITHUB_OUTPUT # e.g) major or minor or patch or empty

echo "RELEASE_BRANCH_NAME_SUFFIX=${RELEASE_BRANCH_NAME_SUFFIX}"
echo "BRANCH_LATEST_TAG=${BRANCH_LATEST_TAG}"
echo "RELEASE_KIND=${RELEASE_KIND}"

- name: Upgrade semver
id: upgrade_semver
if: ${{ steps.set_context.outputs.RELEASE_KIND != '' }}
env:
BRANCH_LATEST_TAG: ${{ steps.set_context.outputs.BRANCH_LATEST_TAG }}
RELEASE_KIND: ${{ steps.set_context.outputs.RELEASE_KIND }}
run: |
IFS=. read -r version minor patch <<< "${BRANCH_LATEST_TAG}" # version=v1, minor=7, patch=7

case ${RELEASE_KIND} in
patch) RELEASE_TAG="$version.$minor.$((patch+1))"; ;;
*) echo "not supported semver kind"; exit 1; ;;
esac

echo "RELEASE=true" >> $GITHUB_OUTPUT
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT # e.g) vx.x.x

echo "RELEASE_TAG=${RELEASE_TAG}"

release:
if: ${{ needs.semver-auto.outputs.RELEASE == 'true' }}
needs:
- semver-auto
uses: ./.github/workflows/_release.yml
with:
release_branch_name: "release/${{ needs.semver-auto.outputs.RELEASE_BRANCH_NAME_SUFFIX }}"
release_tag: ${{ needs.semver-auto.outputs.RELEASE_TAG }}
secrets: inherit
Loading