|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 7 | + - "[0-9]+.[0-9]+.[0-9]+a[0-9]+" |
| 8 | + - "[0-9]+.[0-9]+.[0-9]+b[0-9]+" |
| 9 | + - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+" |
| 10 | + |
| 11 | +env: |
| 12 | + PACKAGE_NAME: "snakemake-interface-logger-plugins" |
| 13 | + OWNER: "cademirch" |
| 14 | + |
| 15 | +jobs: |
| 16 | + details: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + new_version: ${{ steps.release.outputs.new_version }} |
| 20 | + suffix: ${{ steps.release.outputs.suffix }} |
| 21 | + tag_name: ${{ steps.release.outputs.tag_name }} |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v2 |
| 24 | + |
| 25 | + - name: Extract tag and Details |
| 26 | + id: release |
| 27 | + run: | |
| 28 | + if [ "${{ github.ref_type }}" = "tag" ]; then |
| 29 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 30 | + NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}') |
| 31 | + SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "") |
| 32 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 33 | + echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT" |
| 34 | + echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" |
| 35 | + echo "Version is $NEW_VERSION" |
| 36 | + echo "Suffix is $SUFFIX" |
| 37 | + echo "Tag name is $TAG_NAME" |
| 38 | + else |
| 39 | + echo "No tag found" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + check_pypi: |
| 44 | + needs: details |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - name: Fetch information from PyPI |
| 48 | + run: | |
| 49 | + response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}") |
| 50 | + latest_previous_version=$(echo $response | grep -oP '"releases":\{"\K[^"]+' | sort -rV | head -n 1) |
| 51 | + if [ -z "$latest_previous_version" ]; then |
| 52 | + echo "Package not found on PyPI." |
| 53 | + latest_previous_version="0.0.0" |
| 54 | + fi |
| 55 | + echo "Latest version on PyPI: $latest_previous_version" |
| 56 | + echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV |
| 57 | +
|
| 58 | + - name: Compare versions and exit if not newer |
| 59 | + run: | |
| 60 | + NEW_VERSION=${{ needs.details.outputs.new_version }} |
| 61 | + LATEST_VERSION=$latest_previous_version |
| 62 | + if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then |
| 63 | + echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI." |
| 64 | + exit 1 |
| 65 | + else |
| 66 | + echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI." |
| 67 | + fi |
| 68 | +
|
| 69 | + setup_and_build: |
| 70 | + needs: [details, check_pypi] |
| 71 | + runs-on: ubuntu-latest |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v2 |
| 74 | + |
| 75 | + - name: Install uv |
| 76 | + uses: astral-sh/setup-uv@v3 |
| 77 | + |
| 78 | + - name: "Set up Python" |
| 79 | + uses: actions/setup-python@v5 |
| 80 | + with: |
| 81 | + python-version-file: "pyproject.toml" |
| 82 | + |
| 83 | + - name: Install the project |
| 84 | + run: uv sync --all-extras --dev |
| 85 | + |
| 86 | + - name: Build source and wheel distribution |
| 87 | + run: | |
| 88 | + uv build |
| 89 | +
|
| 90 | + - name: Upload artifacts |
| 91 | + uses: actions/upload-artifact@v3 |
| 92 | + with: |
| 93 | + name: dist |
| 94 | + path: dist/ |
| 95 | + |
| 96 | + pypi_publish: |
| 97 | + name: Upload release to PyPI |
| 98 | + needs: [setup_and_build, details] |
| 99 | + runs-on: ubuntu-latest |
| 100 | + environment: |
| 101 | + name: release |
| 102 | + permissions: |
| 103 | + id-token: write |
| 104 | + steps: |
| 105 | + - name: Download artifacts |
| 106 | + uses: actions/download-artifact@v3 |
| 107 | + with: |
| 108 | + name: dist |
| 109 | + path: dist/ |
| 110 | + |
| 111 | + - name: Publish distribution to PyPI |
| 112 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 113 | + |
| 114 | + github_release: |
| 115 | + name: Create GitHub Release |
| 116 | + needs: [setup_and_build, details] |
| 117 | + runs-on: ubuntu-latest |
| 118 | + permissions: |
| 119 | + contents: write |
| 120 | + steps: |
| 121 | + - name: Checkout Code |
| 122 | + uses: actions/checkout@v3 |
| 123 | + with: |
| 124 | + fetch-depth: 0 |
| 125 | + |
| 126 | + - name: Download artifacts |
| 127 | + uses: actions/download-artifact@v3 |
| 128 | + with: |
| 129 | + name: dist |
| 130 | + path: dist/ |
| 131 | + |
| 132 | + - name: Create GitHub Release |
| 133 | + id: create_release |
| 134 | + env: |
| 135 | + GH_TOKEN: ${{ github.token }} |
| 136 | + run: | |
| 137 | + gh release create ${{ needs.details.outputs.tag_name }} dist/* --title ${{ needs.details.outputs.tag_name }} --generate-notes |
0 commit comments