-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (134 loc) · 4.74 KB
/
merged-pr.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Merged Pull Request
on:
pull_request:
types: [closed]
jobs:
merged_release_version:
name: "If not merged and has a release version"
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check_version.outputs.version}}
steps:
- id: check_version
run: |
if [[ $GITHUB_HEAD_REF =~ release\/v([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}) ]]; then
v=${BASH_REMATCH[1]}
echo "::notice::Current release ${v}"
echo "version=${v}" >> $GITHUB_OUTPUT
fi
create-tag:
name: "Create tag"
needs: [merged_release_version]
runs-on: ubuntu-latest
steps:
- id: validate
run: |
VERSION=${{needs.merged_release_version.outputs.version}}
if [ "$VERSION" == "" ]; then
exit
fi
- uses: actions/checkout@v3
- uses: rickstaa/action-create-tag@v1
with:
tag: "v${{needs.merged_release_version.outputs.version}}"
message: "Latest release"
# get_latest_release:
# name: "Get latest release"
# runs-on: ubuntu-latest
# outputs:
# version: ${{ steps.check_version.outputs.version }}
# steps:
# - uses: actions/checkout@v3
# - id: check_version
# run: |
# v=$(jq .version pkg/consts/metadata.json)
# echo "::notice file=pkg/consts/metadata.json::Latest release ${v}"
# echo "version=$v" >> $GITHUB_OUTPUT
# validate:
# name: "Validate"
# needs: ["merged_release_version","get_latest_release"]
# runs-on: ubuntu-latest
# outputs:
# is_valid: ${{ steps.validate.outputs.is_valid }}
# steps:
# - uses: actions/checkout@v3
# - id: validate
# run: |
# VERSION=${{needs.merged_release_version.outputs.version}}
# echo "::notice::Latest release ${VERSION}"
# CURRENT_VERSION=${{needs.get_latest_release.outputs.version}}
# echo "::notice::Current release ${CURRENT_VERSION}"
# if [ "$VERSION" == "$CURRENT_VERSION" ]; then
# echo "::warning::No change"
# exit 1
# fi
# regex="([0-9]+).([0-9]+).([0-9]+)"
# if [[ ${VERSION} =~ $regex ]]; then
# l_major="${BASH_REMATCH[1]}"
# l_minor="${BASH_REMATCH[2]}"
# l_build="${BASH_REMATCH[3]}"
# else
# echo "::error::Invalid latest release ${VERSION}"
# exit 1
# fi
# if [[ ${CURRENT_VERSION} =~ $regex ]]; then
# c_major="${BASH_REMATCH[1]}"
# c_minor="${BASH_REMATCH[2]}"
# c_build="${BASH_REMATCH[3]}"
# else
# echo "::error::Invalid current release ${CURRENT_VERSION}"
# exit 1
# fi
# if [ "$l_major" -lt "$c_major" ]; then
# echo "::warning::Major version is smaller than current"
# exit 1
# fi
# if [ "$l_minor" -lt "$c_minor" ]; then
# echo "::warning::Minor version is smaller than current"
# exit 1
# fi
# if [ "$l_build" -lt "$c_build" ]; then
# echo "::warning::Build version is smaller than current"
# exit 1
# fi
# echo "is_valid=1" >> $GITHUB_OUTPUT
# update_metadata:
# name: "Update metadata"
# needs: [validate,merged_release_version]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# ref: ${{ github.head_ref }}
# fetch-depth: 0
# - name: "Update metadata.json"
# run: |
# VERSION=${{needs.merged_release_version.outputs.version}}
# BUILD_TIME=$(date +"%Y-%m-%dT%H:%M:%S%:z")
# BUILD_RUNNER="github"
# tmp=$(jq --arg a "$BUILD_TIME" --arg b "$VERSION" --arg c "$BUILD_RUNNER" '.build_time = $a | .version = $b | .build_runner = $c' ./pkg/consts/metadata.json)
# echo $tmp > ./pkg/consts/metadata.json
# - name: Commit files
# run: |
# git config --local user.name "github-actions[bot]"
# git commit -a -m "Updated release version $VERSION"
# - name: Push changes
# uses: ad-m/github-push-action@master
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# branch: ${{ github.head_ref }}
# close_pr:
# needs: [validate]
# if: always()
# name: Close pull request
# runs-on: ubuntu-latest
# steps:
# - run: |
# if [ "${{needs.validate.outputs.is_valid}}" == "1" ]; then
# exit
# fi
# echo "::warning::This pull request should not be merged!"
# # - uses: superbrothers/close-pull-request@v3
# # with:
# # comment: "Invalid version"