-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (112 loc) · 4.19 KB
/
codebase-versioning.yml
File metadata and controls
129 lines (112 loc) · 4.19 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Codebase Versioning
on:
pull_request:
branches:
- main
types: [closed]
jobs:
auto-versioning:
permissions:
contents: write
runs-on: ubuntu-latest
# Don't run if pull request is closed without merging.
if: github.event.pull_request.merged == true
env:
PR_LABELS: ${{ toJson(github.event.pull_request.labels) }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
ssh-key: ${{ secrets.DEPLOY_KEY }}
- name: Configure Git
run: |
echo "Configuring git..."
git config --global user.name 'vechain-ci'
git config --global user.email 'vechain.ci@vechain.org'
- name: Determine increment type
id: increment
run: |
label_names=$(echo "${PR_LABELS}" | jq -r ".[] | .name")
echo "PR labels: ${label_names}"
increment_type="patch" # Default increment type
for label in ${label_names[@]}; do
case "${label}" in
increment:major)
increment_type="major"
;;
increment:minor)
# Only update if a major increment hasn't been set
if [ "$increment_type" != "major" ]; then
increment_type="minor"
fi
;;
increment:patch)
# Only update if neither major nor minor has been set
if [ "$increment_type" != "major" ] && [ "$increment_type" != "minor" ]; then
increment_type="patch"
fi
;;
esac
done
echo "increment_type=${increment_type}" >> $GITHUB_OUTPUT
- name: Define new tag
id: define-new-tag
run: |
echo "Determining current SHA..."
CURRENT_SHA=$(git rev-parse HEAD)
echo "Current SHA: $CURRENT_SHA"
echo "Fetching the latest tag..."
git fetch --tags
LATEST_TAG=$(git tag -l 'v.*' | sort -V | tail -n1)
if [[ -z "$LATEST_TAG" ]]; then
echo "No existing tags found. Starting from initial version."
MAJOR=1
MINOR=0
PATCH=0
else
echo "Latest tag: $LATEST_TAG"
IFS='-' read -ra TAG_PARTS <<< "$LATEST_TAG"
IFS='.' read -ra VERSION_PARTS <<< "${TAG_PARTS[0]}"
MAJOR=${VERSION_PARTS[1]}
MINOR=${VERSION_PARTS[2]}
PATCH=${VERSION_PARTS[3]}
PREVIOUS_SHA=$(git rev-list -n 1 $LATEST_TAG)
echo "Latest tag version: MAJOR=$MAJOR, MINOR=$MINOR, PATCH=$PATCH, PREVIOUS_SHA=$PREVIOUS_SHA"
if [[ "$CURRENT_SHA" == "$PREVIOUS_SHA" ]]; then
echo "Current SHA is the same as the SHA in the latest tag. Skipping further steps."
exit 0
fi
fi
increment_type="${{ steps.increment.outputs.increment_type }}"
if [[ "${increment_type}" == "major" ]]; then
echo "Major version increment detected. INCREMENTING MAJOR VERSION."
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [[ "${increment_type}" == "minor" ]]; then
echo "Minor version increment detected. INCREMENTING MINOR VERSION"
MINOR=$((MINOR + 1))
PATCH=0
elif [[ "${increment_type}" == "patch" ]]; then
echo "Patch version increment detected. INCREMENTING PATCH VERSION."
PATCH=$((PATCH + 1))
else
echo "No version increment detected, INCREMENTING PATCH VERSION by default."
PATCH=$((PATCH + 1))
fi
echo "NEW_TAG=v.${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_OUTPUT
- name: Create and Push New Tag
if: steps.define-new-tag.outputs.NEW_TAG != ''
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
NEW_TAG=${{ steps.define-new-tag.outputs.NEW_TAG }}
echo "Preparing new tag: ${NEW_TAG}"
if git rev-parse "${NEW_TAG}" >/dev/null 2>&1; then
echo "Tag ${NEW_TAG} already exists. Skipping tag creation and exiting job."
exit 0
else
echo "Creating and pushing new tag: ${NEW_TAG}"
git tag -a "${NEW_TAG}" -m "${NEW_TAG} - ${PR_TITLE}"
git push origin "${NEW_TAG}"
fi