-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (99 loc) · 3.49 KB
/
publish.yml
File metadata and controls
120 lines (99 loc) · 3.49 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
name: Publish to PyPI
on:
release:
types: [published] # Trigger on manual release publications
workflow_call:
inputs:
publish_test:
description: "Publish to TestPyPI"
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
publish_test:
description: "Publish to TestPyPI"
required: false
type: boolean
default: false
jobs:
publish:
runs-on: ubuntu-latest
if: inputs.publish_test != true
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Configure Poetry
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Update versions
run: |
# Configure git to use SSH
git config --local core.sshCommand "ssh -i ~/.ssh/deploy_key"
git remote set-url origin git@github.com:${GITHUB_REPOSITORY}.git
# Get version from git tag
VERSION=$(git describe --tags --abbrev=0)
VERSION=${VERSION#v} # Remove 'v' prefix if present
# Update pyproject.toml
poetry version $VERSION
# Update __init__.py
echo "__version__ = \"$VERSION\"" > pythonik/__init__.py
# Fetch and checkout main branch
git fetch origin main
git checkout main
# Commit and push the changes
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add pyproject.toml pythonik/__init__.py
git commit -m "chore: update version to $VERSION [skip ci]"
git push origin main
- name: Build and publish
run: |
poetry build
poetry publish
publish-test:
runs-on: ubuntu-latest
if: inputs.publish_test == true && github.event_name == 'workflow_dispatch' # Only run for manual triggers with publish_test true
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Configure Poetry
run: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_TOKEN }}
- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Update versions
run: |
# Configure git to use SSH
git config --local core.sshCommand "ssh -i ~/.ssh/deploy_key"
git remote set-url origin git@github.com:${GITHUB_REPOSITORY}.git
# Get version from git tag
VERSION=$(git describe --tags --abbrev=0)
VERSION=${VERSION#v}
poetry version $VERSION
echo "__version__ = \"$VERSION\"" > pythonik/__init__.py
- name: Build and publish to TestPyPI
run: |
poetry build
poetry publish -r testpypi