-
Notifications
You must be signed in to change notification settings - Fork 8
145 lines (135 loc) · 4.78 KB
/
package-release.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Release
on:
workflow_call:
inputs:
GO_VERSION:
required: true
type: string
GO111MODULE:
required: false
type: string
CGO_ENABLED:
required: false
type: number
default: 1
RELEASE:
required: true
type: string
IS_DRAFT:
required: false
type: boolean
default: false
BUILD_PATH:
required: false
type: string
default: "./..."
UNIT_TESTS_PATH:
required: false
type: string
default: "./..."
# TEST_MULTI_ENVIRONMENTS:
# required: false
# type: boolean
# default: true
push:
branches: [ main, master ]
tags:
- 'v*.*.*'
jobs:
test:
uses: ./.github/workflows/go-basic-tests.yaml
with:
GO_VERSION: ${{ inputs.GO_VERSION }}
GO111MODULE: ${{ inputs.GO111MODULE }}
CGO_ENABLED: ${{ inputs.CGO_ENABLED }}
UNIT_TESTS_PATH: ${{ inputs.UNIT_TESTS_PATH }}
BUILD_PATH: ${{ inputs.BUILD_PATH }}
# TEST_MULTI_ENVIRONMENTS: ${{ inputs.TEST_MULTI_ENVIRONMENTS }}
secrets: inherit
create_release:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get latest tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "Latest tag: $latest_tag"
- name: Determine version bump
id: version_bump
run: |
tag_name=${{ steps.latest_tag.outputs.latest_tag }}
commit_range="${tag_name}..HEAD"
major_bump=$(git diff --name-only $commit_range | grep -E '^major-.*\.md$' | wc -l)
minor_bump=$(git diff --name-only $commit_range | grep -E '^minor-.*\.md$' | wc -l)
if [ $major_bump -gt 0 ]; then
echo "{name}={$bump_type} major" >> $GITHUB_OUTPUT
elif [ $minor_bump -gt 0 ]; then
echo "{name}={$bump_type} minor" >> $GITHUB_OUTPUT
else
echo "{name}={$bump_type} patch" >> $GITHUB_OUTPUT
fi
- name: Increment tag version
id: increment_tag
run: |
tag_name=${{ steps.latest_tag.outputs.latest_tag }}
bump_type=${{ steps.version_bump.outputs.bump_type }}
if [ $bump_type == "major" ]; then
tag_name=$(echo $tag_name | awk -F. '{$1++;$2=0;$3=0;print $0}')
elif [ $bump_type == "minor" ]; then
tag_name=$(echo $tag_name | awk -F. '{$2++;$3=0;print $0}')
else
tag_name=$(echo $tag_name | awk -F. '{$3++;print $0}')
fi
echo "{name}={$tag_name}" >> $GITHUB_OUTPUT
# - name: Extract version
# id: extract_version
# run: |
# version=$(echo $latest_tag | jq -r 'sub("^[^0-9]*"; "")')
# echo "Version: $version"
# - name: Increase version
# id: increase_version
# run: |
# next_version=$((version + 1))
# echo "Next version: $next_version"
# - name: Set tag name
# id: set_tag_name
# run: |
# next_version=$((${{ github.event_name == 'release' }} ? $(echo "${{ github.ref }}" | awk -F'/' '{print $3}') : $(echo "${{ github.ref }}-$(date +%s)" | awk -F'/' '{print $3}')))
# tag_name=v$(echo "$next_version" | cut -d'.' -f-3)
# echo "{name}={$tag_name}" >> $GITHUB_OUTPUT
# continue-on-error: true
# - name: Set tag name
# id: set_tag_name
# run: |
# # Get the latest tag name in the repository
# last_tag=$(git describe --tags --abbrev=0)
# # Extract the major, minor, and patch version numbers from the latest tag
# major=$(echo "$last_tag" | cut -d'.' -f1 | sed 's/v//')
# minor=$(echo "$last_tag" | cut -d'.' -f2)
# patch=$(echo "$last_tag" | cut -d'.' -f3)
# # Increment the patch version number
# next_patch=$(($patch + 1))
# # Set the new tag name with the incremented patch version number
# tag_name="v$major.$minor.$next_patch"
# # Set the tag_name output variable
# echo "{name}={$tag_name}" >> $GITHUB_OUTPUT
# continue-on-error: true
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.increment_tag.outputs.tag_name }}
release_name: Release ${{ steps.increment_tag.outputs.tag_name }}
body: |
Release ${{ steps.increment_tag.outputs.tag_name }}
-------------------------------
Add release notes here.
draft: false
prerelease: false