-
Notifications
You must be signed in to change notification settings - Fork 188
109 lines (96 loc) · 3.46 KB
/
Copy pathv5-publish.yml
File metadata and controls
109 lines (96 loc) · 3.46 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
name: Publish Release (v5)
on:
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
type: choice
required: true
options:
- testpypi
- pypi
default: 'testpypi'
pull_request:
branches:
- master
permissions:
contents: write
id-token: write
jobs:
publish-pypi:
name: "PyPI"
runs-on: ubuntu-latest
environment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'testpypi' }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- id: get_version
name: Get version from pyproject.toml
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- id: get_prerelease
name: Determine if pre-release
run: |
VERSION="${{ steps.get_version.outputs.version }}"
if [[ "$VERSION" =~ (a|alpha|b|beta|rc)[0-9]* ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
echo "Pre-release: true"
else
echo "prerelease=false" >> $GITHUB_OUTPUT
echo "Stable release"
fi
- name: Create GitHub Release
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'pypi'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: v${{ steps.get_version.outputs.version }}
body: |
See [v5_MIGRATION_GUIDE.md](https://github.com/${{ github.repository }}/blob/main/v5_MIGRATION_GUIDE.md) for migration instructions.
draft: false
prerelease: ${{ steps.get_prerelease.outputs.prerelease }}
- name: Configure Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Configure dependencies
run: |
pip install --user --upgrade pip
pip install --user pipx
pipx ensurepath
pipx install poetry
poetry config virtualenvs.in-project true
poetry install
- name: Build release
run: |
poetry build
ls -lh dist/
echo "Build successful! Artifacts created:"
ls -lh dist/
- name: Publish to Test PyPI
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'testpypi'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
print-hash: true
# - name: Publish to PyPI
# if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'pypi'
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# print-hash: true
- name: Summary
run: |
echo "### Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Version: ${{ steps.get_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Environment: ${{ github.event.inputs.environment }}" >> $GITHUB_STEP_SUMMARY
echo "- Pre-release: ${{ steps.get_prerelease.outputs.prerelease }}" >> $GITHUB_STEP_SUMMARY