-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (96 loc) · 4.31 KB
/
semver-major-minor.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#
# 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.upgrade_semver.outputs.RELEASE_BRANCH_NAME }}
RELEASE_TAG: ${{ steps.upgrade_semver.outputs.RELEASE_TAG }}
RELEASE: ${{ steps.setup_for_release.outputs.RELEASE }}
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_commit.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::'` # e.g) version=1, minor=7, patch=7
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 for release
id: setup_for_release
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 }}
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
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-pr:
if: ${{ needs.semver-auto.outputs.RELEASE == 'true' }}
needs:
- semver-auto
uses: ./.github/workflows/_release-pr.yml
with:
release_branch_name: ${{ needs.semver-auto.outputs.RELEASE_BRANCH_NAME }}
release_tag: ${{ needs.semver-auto.outputs.RELEASE_TAG }}
secrets: inherit