-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (83 loc) · 3.1 KB
/
template_release_version.yml
File metadata and controls
100 lines (83 loc) · 3.1 KB
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
name: Release Version Detector
on:
workflow_call:
inputs:
tag-prefix:
required: false
type: string
default: 'v'
tag-suffix:
required: false
type: string
default: ''
format:
required: false
type: string
default: 'weekly'
outputs:
new_version:
value: ${{ jobs.new_version.outputs.new_version }}
new_tag:
value: ${{ jobs.new_version.outputs.new_tag }}
jobs:
new_version:
name: Get new release version
runs-on: ubuntu-slim
permissions:
contents: read
outputs:
new_version: ${{ steps.set_version.outputs.next_version }}
new_tag: ${{ steps.set_version.outputs.next_tag }}
steps:
- name: Detect new release version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: set_version
run: |
TAG_PREFIX=${{ inputs['tag-prefix'] }}
TAG_SUFFIX=${{ inputs['tag-suffix'] }}
DATE=$(date +"%Y%m%d")
YEAR=$(date +"%Y")
WEEK=$(date +"%-V")
QUARTER=$(date "+%q")
if [ ${{ inputs.format }} == 'quarterly' ] ; then
MINOR=$QUARTER
else
MINOR=$WEEK
fi
if [[ $(gh release view -R ${{ github.repository }} 2>&1) =~ "release not found" ]]; then
COUNTER=0
else
# fetch last tag name from github releases which are not drafts or pre-releases and starts with the given prefix
OLD_TAG_NAME=$(gh release list -R ${{ github.repository }} --limit 100 --exclude-drafts --exclude-pre-releases --json tagName --jq "[.[] | select(.tagName | startswith(\"${TAG_PREFIX}\") and endswith(\"${TAG_SUFFIX}\"))] | .[0].tagName")
echo "Last tag name: ${OLD_TAG_NAME}"
# remove prefix and suffix
OLD_VERSION=${OLD_TAG_NAME#${TAG_PREFIX}}
OLD_VERSION=${OLD_VERSION%${TAG_SUFFIX}}
echo "Last version: ${OLD_VERSION}"
PARTS=(${OLD_VERSION//./ })
COUNTER=${PARTS[2]}
MINOR_FROM_LAST_TAG=${PARTS[1]}
# if we have a new week and the weekly release we start to count from 0
if [ ${MINOR_FROM_LAST_TAG} != ${WEEK} ] && [ ${{ inputs.format }} == 'weekly' ]; then
COUNTER=0
fi
# if we have a new quarter and the quarterly release we start to count from 0
if [ ${MINOR_FROM_LAST_TAG} != ${QUARTER} ] && [ ${{ inputs.format }} == 'quarterly' ]; then
COUNTER=0
fi
# check if valid tag
pattern="[0-9]+.[0-9]+.[0-9]+$"
if ! [[ $OLD_VERSION =~ $pattern ]]; then
COUNTER=0
fi
fi
# increase Version
COUNTER=$((COUNTER+1))
NEW_VERSION="${YEAR}.${MINOR}.${COUNTER}"
NEW_TAG="${TAG_PREFIX}${NEW_VERSION}${TAG_SUFFIX}"
echo "Next version: ${NEW_VERSION}"
echo "Next tag: ${NEW_TAG}"
echo "next_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "next_tag=${NEW_TAG}" >> $GITHUB_OUTPUT
shell: bash