-
Notifications
You must be signed in to change notification settings - Fork 4
131 lines (116 loc) · 5.1 KB
/
Copy pathrelease.yml
File metadata and controls
131 lines (116 loc) · 5.1 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
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Release
# Releases are NOT automatic. A release manager pushes a git tag manually:
# * v1.7.0-rc1 -> publishes a GitHub *pre-release* only (artifact for the Apache vote)
# * v1.7.0 -> publishes a GitHub *release* and pushes the package to PyPI
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
release:
name: Manual Tag Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Resolve Tag
id: tag
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)-[Rr][Cc]([0-9]+)$ ]]; then
BASE_VERSION="${BASH_REMATCH[1]}"
RC_NUMBER="${BASH_REMATCH[2]}"
IS_RC=true
elif [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
BASE_VERSION="$VERSION"
RC_NUMBER=""
IS_RC=false
else
echo "::error::Tag '$TAG' is not a supported release tag (expected vX.Y.Z or vX.Y.Z-rcN)."
exit 1
fi
# The source release must describe its own version, so pyproject.toml
# has to be bumped and committed before the tag is pushed.
PROJECT_VERSION="$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")"
if [[ "$PROJECT_VERSION" != "$BASE_VERSION" ]]; then
echo "::error::pyproject.toml version ($PROJECT_VERSION) does not match tag version ($BASE_VERSION). Bump pyproject.toml before tagging."
exit 1
fi
# Apache source release artifact naming. The RC number is intentionally
# NOT part of the file name, so the bits that get voted on are byte
# identical to the bits published for the final release.
ARTIFACT="apache-casbin-django-orm-adapter-${BASE_VERSION}-incubating-src.tar.gz"
{
echo "tag=$TAG"
echo "base_version=$BASE_VERSION"
echo "rc_number=$RC_NUMBER"
echo "is_rc=$IS_RC"
echo "artifact=$ARTIFACT"
} >> "$GITHUB_OUTPUT"
- name: Build Apache Source Package
run: |
set -euo pipefail
ARTIFACT="${{ steps.tag.outputs.artifact }}"
# The tarball unpacks into a single top level directory named after the
# artifact, and contains sources only - no binaries, no VCS metadata.
git archive --format=tar.gz \
--prefix="${ARTIFACT%.tar.gz}/" \
-o "$ARTIFACT" HEAD
sha512sum "$ARTIFACT" > "$ARTIFACT.sha512"
- name: Publish GitHub Pre-Release
if: steps.tag.outputs.is_rc == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
ARTIFACT="${{ steps.tag.outputs.artifact }}"
gh release create "${{ steps.tag.outputs.tag }}" \
--title "v${{ steps.tag.outputs.base_version }}-rc${{ steps.tag.outputs.rc_number }}" \
--prerelease \
--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." \
"$ARTIFACT" "$ARTIFACT.sha512"
- name: Publish GitHub Release
if: steps.tag.outputs.is_rc == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
ARTIFACT="${{ steps.tag.outputs.artifact }}"
gh release create "${{ steps.tag.outputs.tag }}" \
--title "v${{ steps.tag.outputs.base_version }}" \
--notes "Version ${{ steps.tag.outputs.base_version }}. The official source package is \`$ARTIFACT\`." \
"$ARTIFACT" "$ARTIFACT.sha512"
- name: Publish to PyPI
if: steps.tag.outputs.is_rc == 'false'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
set -euo pipefail
python -m pip install --upgrade build twine
python -m build
python -m twine upload dist/*