-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (81 loc) · 3.34 KB
/
python-publish.yml
File metadata and controls
100 lines (81 loc) · 3.34 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
# This workflow will upload a Python Package to PyPI when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# modified from MCDReforged https://mcdreforged.com/zh-CN
name: Upload Python Package
on:
push:
paths:
- ".github/**"
- "weauth/**"
- "tests/**"
- "*.py"
env:
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }}
jobs:
test:
uses: ./.github/workflows/test.yml
pypi-publish:
runs-on: ubuntu-latest
needs:
- test
if: github.event_name == 'push'
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
# Dedicated environments with protections for publishing are strongly recommended.
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
environment:
name: pypi_release
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
# url: https://pypi.org/p/YOURPROJECT
#
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
# ALTERNATIVE: exactly, uncomment the following line instead:
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install -U pip
pip install setuptools wheel
- name: Get Timestamp Action
uses: nanzm/get-time-action@v2.0
id: time
- name: Modify and get version information
id: version
run: |
version_file=weauth/constants/core_constant.py
if [ "$IS_RELEASE" != "true" ]; then
sed -i "/^__CI_BUILD_NUM/c\__CI_BUILD_NUM = '$GITHUB_RUN_NUMBER'" "$version_file"
fi
- name: Modify time
id: modify_time
env:
TIME: "${{ steps.time.outputs.time }}"
run: |
version_file=weauth/constants/core_constant.py
sed -i "/^BUILD_TIME/c\BUILD_TIME = '$TIME'" "$version_file"
- name: Create distribution
run: |
python setup.py sdist bdist_wheel
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# Fix running the gh-action-pypi-publish action twice in one job causing an error on the 2nd run:
# "InvalidDistribution: Unknown distribution format: 'mcdreforged-2.14.0a2-py3-none-any.whl.publish.attestation'"
# See also:
# https://github.com/pypa/gh-action-pypi-publish/issues/283
# https://github.com/pypa/twine/commit/dd613569856f1dd128040f197948b5c48eb8dd43
attestations: false
- name: Publish distribution to PyPI
if: env.IS_RELEASE == 'true'
uses: pypa/gh-action-pypi-publish@release/v1