forked from HumanSignal/label-studio-converter
-
Notifications
You must be signed in to change notification settings - Fork 2
101 lines (85 loc) · 2.88 KB
/
release-set-version.yml
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
name: "Release: Set version"
on:
workflow_call:
inputs:
version:
required: true
type: string
branch:
required: true
type: string
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
type: string
branch:
description: 'Branch reference'
required: true
default: 'develop'
type: string
env:
PYTHON_VERSION_FILE: "label_studio_converter/__init__.py"
jobs:
commit-version:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: hmarr/debug-action@v3.0.0
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_PAT }}
ref: ${{ inputs.branch }}
fetch-depth: 1
- name: Get GitHub user details
id: get-github-user
uses: actions/github-script@v7
env:
ACTOR_USERNAME: ${{ github.event.sender.login }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const actor_username = process.env.ACTOR_USERNAME;
let user_name = 'robot-ci-heartex';
let user_email = 'robot-ci-heartex@users.noreply.github.com';
try {
const {data: user} = await github.rest.users.getByUsername({
username: actor_username,
});
user_name = user.login;
user_email = user.email;
} catch (e) {
console.log(e)
}
core.setOutput('user_name', user_name);
core.setOutput('user_email', user_email);
- name: Configure git
shell: bash
run: |
set -xeuo pipefail
git config --global user.name '${{ steps.get-github-user.outputs.user_name }}'
git config --global user.email '${{ steps.get-github-user.outputs.user_email }}'
- name: Validate user input
id: validate-user-input
shell: bash
run: |
set -xeuo pipefail
regexp='^[v]?([0-9]+)\.([0-9]+)\.([0-9]+)(\.dev[0-9]*)?$'
if [[ "${{ inputs.version }}" =~ $regexp ]]; then
echo "${{ inputs.version }} does match the regexp ${regexp}"
else
echo "${{ inputs.version }} does not match the regexp ${regexp}"
exit 1
fi
- name: Commit version file
id: make-commit
run: |
set -euo pipefail
sed -i "s/^__version__[ ]*=.*/__version__ = '${{ inputs.version }}'/g" ${{ env.PYTHON_VERSION_FILE }}
git add ${{ env.PYTHON_VERSION_FILE }}
git commit --message "chore: Bump version to ${{ inputs.version }}"
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
git push origin HEAD:refs/heads/${{ inputs.branch }}