From 2afc2d37b6b48e50fe1a4601be58523e0753cf98 Mon Sep 17 00:00:00 2001 From: silabs-tuD Date: Wed, 25 Dec 2024 09:33:21 +0700 Subject: [PATCH] Update Github Workflow and release version to 5.5.0 --- .github/workflows/python-publish.yml | 78 +++++++++++++++++++++++++++- pyproject.toml | 3 +- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index eac533b..1b291d2 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -6,18 +6,83 @@ # separate terms of service, privacy policy, and support # documentation. +## References: +# 1. https://github.com/actions/create-release +# 2. https://github.com/ArjanCodes/bragir/blob/main/.github/workflows/release.yaml + name: Upload Python Package on: push: - branches: - - 'feat/**' + tags: + - "[0-9]+.[0-9]+.[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+a[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+b[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+" permissions: contents: read +env: + PACKAGE_NAME: "wfx-common-tools" + jobs: + + check-tag-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@v2 + + - name: Extract tag details + id: release + run: | + if [ "${{ github.ref_type }}" = "tag" ]; then + TAG_NAME=${GITHUB_REF#refs/tags/} + 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 "Version is $NEW_VERSION" + echo "Suffix is $SUFFIX" + echo "Tag name is $TAG_NAME" + else + echo "No tag found" + exit 1 + fi + + check-version-pypi: + needs: check-tag-details + runs-on: ubuntu-latest + steps: + - name: Fetch information from PyPI + run: | + response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}") + latest_previous_version=$(echo $response | grep -o '"[0-9]\+\.[0-9]\+\.[0-9]"' | sort -V | tail -n 1) + 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: Compare versions and exit if not newer + run: | + NEW_VERSION=${{ needs.check-tag-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 + release-build: + needs: [check-tag-details, check-version-pypi] runs-on: ubuntu-latest steps: @@ -39,6 +104,15 @@ jobs: name: release-dists path: dist/ + - name: Create Github Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{github.ref}} + generate_release_notes : true + pypi-publish: runs-on: ubuntu-latest needs: diff --git a/pyproject.toml b/pyproject.toml index ebf1b4f..103b83c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ exclude = [ [project] name = "wfx_common_tools" -version = "0.0.4" +version = "5.5.0" authors = [ { name = "silabs-Marc", email = "marc.dorval@silabs.com"}, ] @@ -35,6 +35,7 @@ dependencies = [ maintainers = [ { name="silabs-tuD", email="tu.dao@silabs.com" }, { name="silabs-JulienT", email="julien.tiron@silabs.com" }, + { name = "silabs-Marc", email = "marc.dorval@silabs.com"}, ] description = "Silicon Laboratories WFx Wi-Fi tools for all supported platforms"