-
Notifications
You must be signed in to change notification settings - Fork 2
130 lines (107 loc) · 4.17 KB
/
Copy pathpython-publish-pypi.yml
File metadata and controls
130 lines (107 loc) · 4.17 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
name: 📦 Package PyPI
on:
release:
types: [published]
permissions:
contents: write
id-token: write
jobs:
update-version:
name: Update Version Files
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.release.target_commitish }}
fetch-depth: 0
- name: 🔍 Determine branch
id: get_branch
run: |
TARGET="${{ github.event.release.target_commitish }}"
BRANCH="${TARGET#refs/heads/}"
BRANCH="${BRANCH#refs/tags/}"
if git rev-parse --verify "$BRANCH"^{tag} >/dev/null 2>&1 || [[ "$TARGET" == refs/tags/* ]]; then
git fetch --all --tags
TAG_NAME="${TARGET#refs/tags/}"
BRANCH=$(git branch -r --contains "$TAG_NAME" | grep -E "(main|master|develop)" | head -1 | sed 's|origin/||' | xargs || \
git branch -r --contains "$TAG_NAME" | head -1 | sed 's|origin/||' | xargs || \
echo "master")
fi
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "Using branch: $BRANCH"
- name: 🔄 Checkout resolved branch
run: |
git checkout ${{ steps.get_branch.outputs.branch }}
git pull origin ${{ steps.get_branch.outputs.branch }}
- name: 🔍 Extract version from tag
id: extract_version
uses: ./.github/actions/extract-version
with:
tag: ${{ github.event.release.tag_name }}
- name: 📝 Update version files
uses: ./.github/actions/update-version
with:
version: ${{ steps.extract_version.outputs.version }}
- name: 💾 Commit and push
uses: ./.github/actions/commit-push
with:
message: "📦 PyPI: Update version to ${{ steps.extract_version.outputs.version }}"
files: "LAST_VERSION pyproject.toml pycodeloop/__init__.py"
branch: ${{ steps.get_branch.outputs.branch }}
test:
name: Run Tests
needs: [update-version]
uses: ./.github/workflows/test.yml
secrets: inherit
code-quality:
name: Code Quality Checks
needs: [update-version]
uses: ./.github/workflows/code-quality.yml
secrets: inherit
deploy:
name: Deploy to ${{ github.event.release.prerelease && 'TestPyPI' || 'PyPI' }}
needs: [update-version, test, code-quality]
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔍 Determine branch
id: get_branch_deploy
run: |
TARGET="${{ github.event.release.target_commitish }}"
BRANCH="${TARGET#refs/heads/}"
BRANCH="${BRANCH#refs/tags/}"
if [[ "$TARGET" == refs/tags/* ]] || git rev-parse --verify "$BRANCH"^{tag} >/dev/null 2>&1; then
TAG_NAME="${TARGET#refs/tags/}"
BRANCH=$(git branch -r --contains "$TAG_NAME" | grep -E "(main|master|develop)" | head -1 | sed 's|origin/||' | xargs || \
git branch -r --contains "$TAG_NAME" | head -1 | sed 's|origin/||' | xargs || \
echo "master")
fi
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "Using branch: $BRANCH"
- name: 🔄 Checkout branch and pull latest
run: |
git checkout ${{ steps.get_branch_deploy.outputs.branch }}
git pull origin ${{ steps.get_branch_deploy.outputs.branch }}
- name: 🔍 Verify version
uses: ./.github/actions/verify-version
with:
expected: ${{ github.event.release.tag_name }}
- name: 📦 Build Package
uses: ./.github/actions/build-package
with:
python-version: "3.10"
- name: 📦 Publish Package to TestPyPI
if: github.event.release.prerelease == true
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
verbose: true
- name: 📦 Publish Package to PyPI
if: github.event.release.prerelease == false
uses: pypa/gh-action-pypi-publish@release/v1