|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Release |
| 19 | + |
| 20 | +# Releases are NOT automatic. A release manager pushes a git tag manually: |
| 21 | +# * v1.7.0-rc1 -> publishes a GitHub *pre-release* only (artifact for the Apache vote) |
| 22 | +# * v1.7.0 -> publishes a GitHub *release* and pushes the package to PyPI |
| 23 | +on: |
| 24 | + push: |
| 25 | + tags: |
| 26 | + - 'v*' |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: write |
| 30 | + |
| 31 | +jobs: |
| 32 | + release: |
| 33 | + name: Manual Tag Release |
| 34 | + runs-on: ubuntu-latest |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout Repository |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Set up Python |
| 41 | + uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: '3.12' |
| 44 | + |
| 45 | + - name: Resolve Tag |
| 46 | + id: tag |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + TAG="${GITHUB_REF_NAME}" |
| 50 | + VERSION="${TAG#v}" |
| 51 | +
|
| 52 | + if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)-[Rr][Cc]([0-9]+)$ ]]; then |
| 53 | + BASE_VERSION="${BASH_REMATCH[1]}" |
| 54 | + RC_NUMBER="${BASH_REMATCH[2]}" |
| 55 | + IS_RC=true |
| 56 | + elif [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 57 | + BASE_VERSION="$VERSION" |
| 58 | + RC_NUMBER="" |
| 59 | + IS_RC=false |
| 60 | + else |
| 61 | + echo "::error::Tag '$TAG' is not a supported release tag (expected vX.Y.Z or vX.Y.Z-rcN)." |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
| 65 | + # The source release must describe its own version, so pyproject.toml |
| 66 | + # has to be bumped and committed before the tag is pushed. |
| 67 | + PROJECT_VERSION="$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")" |
| 68 | + if [[ "$PROJECT_VERSION" != "$BASE_VERSION" ]]; then |
| 69 | + echo "::error::pyproject.toml version ($PROJECT_VERSION) does not match tag version ($BASE_VERSION). Bump pyproject.toml before tagging." |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +
|
| 73 | + # Apache source release artifact naming. The RC number is intentionally |
| 74 | + # NOT part of the file name, so the bits that get voted on are byte |
| 75 | + # identical to the bits published for the final release. |
| 76 | + ARTIFACT="apache-casbin-django-orm-adapter-${BASE_VERSION}-incubating-src.tar.gz" |
| 77 | +
|
| 78 | + { |
| 79 | + echo "tag=$TAG" |
| 80 | + echo "base_version=$BASE_VERSION" |
| 81 | + echo "rc_number=$RC_NUMBER" |
| 82 | + echo "is_rc=$IS_RC" |
| 83 | + echo "artifact=$ARTIFACT" |
| 84 | + } >> "$GITHUB_OUTPUT" |
| 85 | +
|
| 86 | + - name: Build Apache Source Package |
| 87 | + run: | |
| 88 | + set -euo pipefail |
| 89 | + ARTIFACT="${{ steps.tag.outputs.artifact }}" |
| 90 | + # The tarball unpacks into a single top level directory named after the |
| 91 | + # artifact, and contains sources only - no binaries, no VCS metadata. |
| 92 | + git archive --format=tar.gz \ |
| 93 | + --prefix="${ARTIFACT%.tar.gz}/" \ |
| 94 | + -o "$ARTIFACT" HEAD |
| 95 | + sha512sum "$ARTIFACT" > "$ARTIFACT.sha512" |
| 96 | +
|
| 97 | + - name: Publish GitHub Pre-Release |
| 98 | + if: steps.tag.outputs.is_rc == 'true' |
| 99 | + env: |
| 100 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + run: | |
| 102 | + set -euo pipefail |
| 103 | + ARTIFACT="${{ steps.tag.outputs.artifact }}" |
| 104 | + gh release create "${{ steps.tag.outputs.tag }}" \ |
| 105 | + --title "v${{ steps.tag.outputs.base_version }}-rc${{ steps.tag.outputs.rc_number }}" \ |
| 106 | + --prerelease \ |
| 107 | + --notes "Release candidate ${{ steps.tag.outputs.rc_number }} for version ${{ steps.tag.outputs.base_version }}. This is not an official release; it is the source package for the Apache vote. Release managers should download \`$ARTIFACT\`, sign it locally, and use it for the vote." \ |
| 108 | + "$ARTIFACT" "$ARTIFACT.sha512" |
| 109 | +
|
| 110 | + - name: Publish GitHub Release |
| 111 | + if: steps.tag.outputs.is_rc == 'false' |
| 112 | + env: |
| 113 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + run: | |
| 115 | + set -euo pipefail |
| 116 | + ARTIFACT="${{ steps.tag.outputs.artifact }}" |
| 117 | + gh release create "${{ steps.tag.outputs.tag }}" \ |
| 118 | + --title "v${{ steps.tag.outputs.base_version }}" \ |
| 119 | + --notes "Version ${{ steps.tag.outputs.base_version }}. The official source package is \`$ARTIFACT\`." \ |
| 120 | + "$ARTIFACT" "$ARTIFACT.sha512" |
| 121 | +
|
| 122 | + - name: Publish to PyPI |
| 123 | + if: steps.tag.outputs.is_rc == 'false' |
| 124 | + env: |
| 125 | + TWINE_USERNAME: __token__ |
| 126 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 127 | + run: | |
| 128 | + set -euo pipefail |
| 129 | + python -m pip install --upgrade build twine |
| 130 | + python -m build |
| 131 | + python -m twine upload dist/* |
0 commit comments