Skip to content

Commit 0182f9d

Browse files
authored
ci: upload to TestPyPI only for (pre)releases (#11)
1 parent c516a8e commit 0182f9d

6 files changed

Lines changed: 56 additions & 13 deletions

File tree

.github/tools/check_metadata.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2022 FeatureProbe
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import re
16+
import sys
17+
18+
19+
with open('featureprobe/__init__.py', 'r') as f:
20+
content = f.read()
21+
fmt = re.compile(r"__version__ = '(?P<version>.*)'")
22+
version = fmt.search(content).groupdict()['version']
23+
24+
tag = sys.argv[1].split('/')[-1]
25+
26+
with open('featureprobe/__init__.py', 'w') as f:
27+
version = "__version__ = '%s'" % tag
28+
f.write(re.sub('__version__ = \'.*\'', version, content))

.github/workflows/codestyle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4141
uses: EndBug/add-and-commit@v8.0.2
4242
with:
43-
default_author: github_actions
43+
default_author: github_actor
4444
message: "chore: add license header(s)"
4545

4646
- name: Create pull request
@@ -73,5 +73,5 @@ jobs:
7373
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7474
uses: EndBug/add-and-commit@v8.0.2
7575
with:
76-
default_author: github_actions
76+
default_author: github_actor
7777
message: "style: format python code (pep8)"

.github/workflows/release.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name: "Release to PyPI & TestPyPI"
22

33
on:
4-
push:
5-
branches: [ main ]
6-
4+
release:
5+
types:
6+
- released
7+
- prereleased
78

89
jobs:
910
build-and-publish:
@@ -19,6 +20,20 @@ jobs:
1920
with:
2021
python-version: '3.5'
2122

23+
- name: Set the version metadata to the release tag
24+
run: |
25+
python .github/tools/check_metadata.py ${{ github.ref }}
26+
27+
# - name: PR for bumping version metadata
28+
# uses: peter-evans/create-pull-request@v3
29+
# with:
30+
# author: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
31+
# commit-message: "chore: bump version metadata for ${{ github.ref }}"
32+
# title: "chore: bump version metadata for ${{ github.ref }}"
33+
# body: The version metadata was not updated before release, it has been corrected when building dist, yet please update the code.
34+
# branch: bump-version
35+
# base: ${{ github.event.release.target_commitish }}
36+
2237
- name: Install dependencies
2338
run: |
2439
pip install --upgrade pip
@@ -36,7 +51,7 @@ jobs:
3651
repository_url: https://test.pypi.org/legacy/
3752

3853
- name: Publish to PyPI
39-
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
54+
if: ${{ github.event.action }} == "released"
4055
uses: pypa/gh-action-pypi-publish@release/v1
4156
with:
4257
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: "Tests"
22

33
on:
4-
push:
5-
branches: [ main ]
64
pull_request:
75

86
concurrency:

featureprobe/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
__author__ = 'FeatureProbe'
1616
__license__ = 'Apache 2.0'
1717

18-
__version__ = '1.0.0-beta'
18+
19+
# PEP440 spec:
20+
# [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
21+
__version__ = 'NO_MANUAL_MAINTENANCE_NEEDED'
22+
1923

2024
# --------------- API --------------- #
2125

@@ -39,8 +43,6 @@
3943

4044

4145
__all__ = [
42-
'__version__',
43-
4446
# featureprobe.model
4547

4648
'Condition',

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def _requirements():
3434
'Programming Language :: Python :: 3.10',
3535
]
3636

37-
if 'alpha' in featureprobe.__version__:
37+
if 'a' in featureprobe.__version__:
3838
pypi_classifiers.append('Development Status :: 3 - Alpha')
39-
elif 'beta' in featureprobe.__version__:
39+
elif 'b' in featureprobe.__version__ or 'rc' in featureprobe.__version__:
4040
pypi_classifiers.append('Development Status :: 4 - Beta')
4141
else:
4242
pypi_classifiers.append('Development Status :: 5 - Production/Stable')

0 commit comments

Comments
 (0)