-
Notifications
You must be signed in to change notification settings - Fork 11
88 lines (73 loc) · 2.55 KB
/
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
name: "Write version number and tag"
on:
workflow_dispatch:
inputs:
ref:
description: "Target branch"
required: true
type: string
version:
description: "New version number"
required: true
type: string
jobs:
set-version:
runs-on: ubuntu-latest
steps:
- name: Validate and normalise version number
shell: python
run : |
import os
from packaging.version import Version
version_number = str(Version("${{ inputs.version }}"))
version_string = 'v' + version_number
print(f"Normalised version string: {version_string}")
with open(os.environ["GITHUB_ENV"], "a") as github_env:
print(f"VERSION_NUMBER={version_number}", file=github_env)
print(f"VERSION_STRING={version_string}", file=github_env)
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
fetch-tags: true
fetch-depth: 0
- name: "Update version.py"
shell: bash -l {0}
run: |
echo "__version__ = \"${VERSION_STRING}\"" > euphonic/version.py
cat euphonic/version.py
- name: "Update CITATION.cff"
shell: bash -l {0}
run: |
sed -i "s/^version:\ .*/version: ${VERSION_NUMBER}/" CITATION.cff
sed -i "s/^date-released:\ .*/date-released: $(date -I)/" CITATION.cff
- name: "Create commit"
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add euphonic/version.py CITATION.cff
if git diff --cached --quiet
then
echo "No files were changed, skipping commit"
else
git commit -m "Set version number"
fi
- name: "Tag commit"
shell: bash -l {0}
run: |
if test $(git describe --tags --exact-match) = $VERSION_STRING
then
echo "The correct tag is already on this commit"
else
git tag $VERSION_STRING
fi
- name: "Show updated log"
run: |
git log --pretty=oneline --abbrev-commit --decorate | head -n 5
git diff HEAD^
- name: "Push commit to branch"
shell: bash -l {0}
run: |
# Verify that ref is a branch (as opposed to a tag or hash)
git show-ref --verify "refs/heads/${{ inputs.ref }}"
git push origin ${{ inputs.ref }}
git push origin tag $VERSION_STRING