Create Release #17
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]+" | |
env: | |
PACKAGE_NAME: "${{ vars.PACKAGE_NAME }}" | |
OWNER: "${{ vars.OWNER }}" | |
TAP_NAME: "${{ vars.TAP_NAME }}" | |
permissions: | |
contents: write | |
jobs: | |
details: | |
runs-on: ubuntu-latest | |
outputs: | |
new_version: ${{ steps.release.outputs.new_version }} | |
suffix: ${{ steps.release.outputs.suffix }} | |
tag_name: ${{ steps.release.outputs.tag_name }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Extract tag and Details | |
id: release | |
run: | | |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then | |
TAG_NAME="${GITHUB_REF#refs/tags/}" | |
else | |
echo "No tags found!" | |
exit 1 | |
fi | |
NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}') | |
SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "") | |
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT" | |
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
echo "New Version is $NEW_VERSION" >> $GITHUB_STEP_SUMMARY | |
echo "Suffix is $SUFFIX" >> $GITHUB_STEP_SUMMARY | |
echo "Tag name is $TAG_NAME" >> $GITHUB_STEP_SUMMARY | |
check_pypi: | |
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.new_version }} | |
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, check_pypi] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- 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@v3 | |
with: | |
name: dist | |
path: dist/ | |
pypi_publish: | |
name: Upload release to PyPI | |
needs: [build_and_test, details] | |
runs-on: ubuntu-latest | |
environment: | |
name: release | |
permissions: | |
id-token: write | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
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: [build_and_test, details] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Create Changelog | |
id: change-log | |
uses: yorevs/hspylib/.github/actions/changelog@master | |
with: | |
tag-name: "v${{ needs.init.outputs.version }}" | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: dist | |
path: dist/ | |
- name: Create GitHub Release | |
id: create_release | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh release create ${{ needs.details.outputs.tag_name }} dist/* --title "${{ vars.PACKAGE_NAME }}-${{ needs.details.outputs.tag_name }}-rc${{ github.run_number }}" --generate-notes |