forked from alxrem/prometheus-logstash-exporter
-
Notifications
You must be signed in to change notification settings - Fork 3
131 lines (116 loc) · 3.72 KB
/
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
name: Trigger release
on:
workflow_dispatch:
inputs:
version-bump:
description: 'Whether to bump major, minor or patch version'
required: false
default: patch
type: choice
options:
- major
- minor
- patch
desired-version:
description: 'Version to be released; if specified, version-bump will be ignored'
required: false
default: ''
concurrency: trigger-release
env:
TAG_PREFIX: ""
INITIAL_TAG: 0.1.0
SEMVER_VERSION: 3.4.0
defaults:
run:
shell: bash
jobs:
release:
name: Trigger release
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Validate ref
run: |
if [ "${{ github.ref }}" != refs/heads/master ]; then
>&2 echo "Invalid ref: ${{ github.ref }} (expected: refs/heads/master)"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
fetch-depth: 0
- name: Setup semver
uses: sap/cs-actions/setup-semver@main
with:
version: ${{ env.SEMVER_VERSION }}
install-directory: ${{ runner.temp }}/bin
- name: Determine current release
id: get_current_release
uses: sap/cs-actions/get-highest-tag@main
with:
prefix: ${{ env.TAG_PREFIX }}
- name: Determine target release
id: get_target_release
run: |
version_bump=${{ inputs.version-bump }}
desired_version=${{ inputs.desired-version }}
current_version=${{ steps.get_current_release.outputs.version }}
if [ -z "$desired_version" ]; then
case $version_bump in
major|minor|patch)
# ok
;;
*)
>&2 echo "Invalid input: version-bump ($version_bump)"
exit 1
esac
if [ -z "$current_version" ]; then
version=${INITIAL_TAG/#$TAG_PREFIX/}
tag=$INITIAL_TAG
else
version=$(semver bump $version_bump $current_version)
tag=$TAG_PREFIX$version
fi
else
if [[ $desired_version =~ ^$TAG_PREFIX([0-9].*)$ ]]; then
version=${BASH_REMATCH[1]}
tag=$desired_version
else
>&2 echo "Invalid input: desired-version ($desired_version) should start with $TAG_PREFIX."
exit 1
fi
if [ "$(semver validate $version)" != valid ]; then
>&2 echo "Invalid input: desired-version ($version) is not a valid semantic version."
exit 1
fi
if [ "$(semver compare $version $current_version)" -le 0 ]; then
>&2 echo "Invalid input: desired-version ($version) should be higher than current version ($current_version)."
exit 1
fi
fi
echo "Target version: $version"
echo "Target tag: $tag"
echo "version=$version" >> $GITHUB_OUTPUT
echo "tag=$tag" >> $GITHUB_OUTPUT
- name: Determine target commit
id: get_target_commit
run: |
sha=$(git rev-parse HEAD)
echo "Target commit: $sha"
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Wait for check suites to complete
uses: sap-contributions/await-check-suites@master
with:
ref: ${{ steps.get_target_commit.outputs.sha }}
intervalSeconds: 10
timeoutSeconds: 1800
failStepIfUnsuccessful: true
appSlugFilter: github-actions
- name: Create Release
env:
GH_TOKEN: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
run: |
gh release create ${{ steps.get_target_release.outputs.tag }} \
--target "${{ steps.get_target_commit.outputs.sha }}"