-
-
Notifications
You must be signed in to change notification settings - Fork 1
177 lines (167 loc) · 5.54 KB
/
create-release.yml
File metadata and controls
177 lines (167 loc) · 5.54 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
name: create-release
run-name: Create Release
on:
push:
tags:
- "v?[0-9]+.[0-9]+.[0-9]+"
- "v?[0-9]+.[0-9]+.[0-9]+a[0-9]+"
- "v?[0-9]+.[0-9]+.[0-9]+b[0-9]+"
- "v?[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
workflow_dispatch:
inputs:
tag-name:
description: 'Release Tag name (default to latest)'
type: string
required: false
pypi-publish:
description: 'Publish to PyPi ?'
type: boolean
required: true
default: false
env:
PACKAGE_NAME: "${{ vars.PACKAGE_NAME }}"
OWNER: "${{ vars.OWNER }}"
TAP_NAME: "${{ vars.TAP_NAME }}"
permissions:
contents: write
jobs:
details:
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: actions/checkout@v4
- name: Extract tag and Details
id: release
run: |
set -euo pipefail
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
TAG_NAME="${GITHUB_REF#refs/tags/}"
elif [[ -n "${{ inputs.tag-name }}" ]]; then
TAG_NAME="${{ inputs.tag-name }}"
fi
: "${TAG_NAME:?missing tag_name output}"
echo "TAG-NAME: ${TAG_NAME}" >> $GITHUB_STEP_SUMMARY
echo "tag_name=$(echo ${TAG_NAME})" >> "$GITHUB_OUTPUT"
check_pypi:
if: ${{ inputs['pypi-publish'] }}
needs: details
runs-on: ubuntu-latest
steps:
- name: PyPi Information
run: |
response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}")
latest_previous_version=$(echo $response | jq --raw-output "select(.releases != null) | .releases | keys_unsorted | last")
if [ -z "$latest_previous_version" ]; then
echo "Package not found on PyPI."
latest_previous_version="0.0.0"
fi
echo "Latest version on PyPI: $latest_previous_version"
echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV
- name: Ensure new Version
run: |
NEW_VERSION=${{ needs.details.outputs.tag_name }}
LATEST_VERSION=$latest_previous_version
if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then
echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI."
exit 1
else
echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI."
fi
build_and_test:
needs: details
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.details.outputs.tag_name }}
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ vars.JAVA_VERSION }}
- uses: gradle/gradle-build-action@v2
with:
gradle-version: ${{ vars.GRADLE_VERSION }}
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- uses: actions/setup-python@v3
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Install System packages
run: |
sudo apt-get update
sudo apt-get install -y libmagic1 libmagic-dev portaudio19-dev python3-pyaudio ffmpeg
- name: Update PIP
run: pip install --upgrade pip
- name: Workaround for Python Magic
run: |
python3 -m pip install git+https://github.com/julian-r/python-magic.git
- name: Install Python tools
run: gradle installBuildTools sdist
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: build/dist/
pypi_publish:
if: ${{ inputs['pypi-publish'] }}
name: Upload release to PyPI
needs:
- check_pypi
- build_and_test
runs-on: ubuntu-latest
environment:
name: release
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
github_release:
name: Create GitHub Release
needs:
- details
- build_and_test
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ needs.details.outputs.tag_name }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create Changelog
id: change-log
uses: HS-Teams/hspylib/.github/actions/changelog@master
with:
tag-name: ${{ needs.details.outputs.tag_name }}
- name: Download artifacts
if: ${{ inputs['pypi-publish'] }}
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Create GitHub Release
id: create_release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
: "${TAG:?missing tag_name output}"
echo "${{ steps.change-log.outputs.changelog }}" > changelog
assets="" # Empty by default
[[ "${{ inputs['pypi-publish'] }}" == 'true' ]] && assets="dist/*"
gh release create "${TAG}" \
--title "${{ vars.PACKAGE_NAME }}-${TAG}-rc${{ github.run_number }}" \
--notes-file changelog ${assets}