Skip to content

Commit 3b54828

Browse files
authored
Merge pull request #753 from zapta/main
Added a skeleton for publishing to test pypi.
2 parents e2ceef0 + d8ad36a commit 3b54828

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: publish-to-test-pypi
2+
3+
on:
4+
# Manual activation.
5+
workflow_dispatch:
6+
7+
jobs:
8+
publish-to-test-pypi:
9+
runs-on: ubuntu-latest
10+
11+
env:
12+
# These are set later.
13+
BASE_VERSION: ""
14+
TIMESTAMP: ""
15+
DYNAMIC_VERSION: ""
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Create backup of original apio/__init__.py
22+
run: |
23+
cp apio/__init__.py apio/__init__.py.backup
24+
echo "Backup created as apio/__init__.py.backup"
25+
cat -n apio/__init__.py.backup
26+
27+
- name: Extract original version from apio/__init__.py
28+
shell: python -u {0}
29+
run: |
30+
import os
31+
import sys
32+
33+
# Add repository root to the workflow step Python path
34+
repo_root = os.getcwd()
35+
sys.path.insert(0, repo_root)
36+
37+
# Get original version.
38+
import apio
39+
original_version = apio.__version__
40+
41+
# Export original version to the workflow env
42+
with open(os.environ["GITHUB_ENV"], "a") as env_file:
43+
print(f"ORIGINAL_VERSION={original_version}")
44+
env_file.write(f"ORIGINAL_VERSION={original_version}\n")
45+
46+
# - name: Extract base version from apio/__init__.py
47+
# run: |
48+
# BASE_VERSION=$(grep '^__version__ =' apio/__init__.py | sed -E 's/^__version__\s*=\s*"([^"]+)".*/\1/')
49+
# echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
50+
# echo "Base version detected: $BASE_VERSION"
51+
52+
- name: Generate dynamic version with timestamp
53+
run: |
54+
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
55+
echo "TIMESTAMP=$TIMESTAMP"
56+
echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV
57+
58+
DYNAMIC_VERSION="${ORIGINAL_VERSION}.dev${TIMESTAMP}"
59+
echo "DYNAMIC_VERSION=$DYNAMIC_VERSION"
60+
echo "DYNAMIC_VERSION=$DYNAMIC_VERSION" >> $GITHUB_ENV
61+
62+
- name: Update __version__ in apio/__init__.py
63+
run: |
64+
sed -i "s/^__version__ = .*/__version__ = \"$DYNAMIC_VERSION\"/" apio/__init__.py
65+
echo "Version updated to ${{ env.DYNAMIC_VERSION }}"
66+
cat -n apio/__init__.py
67+
68+
- name: Verify changes with diff
69+
run: |
70+
diff apio/__init__.py.backup apio/__init__.py || true
71+
72+
- name: Set up Python
73+
uses: actions/setup-python@v5
74+
with:
75+
python-version: "3.x"
76+
77+
- name: Install build tool
78+
run: python -m pip install --upgrade pip build
79+
80+
- name: Build package distributions
81+
run: |
82+
# Creates dist/*.tar.gz and dist/*.whl from pyproject.toml
83+
python -m build
84+
85+
- name: Publish to TestPyPI
86+
uses: pypa/gh-action-pypi-publish@release/v1
87+
with:
88+
repository-url: https://test.pypi.org/legacy/
89+
# Using an API TOKEN that was generated once in Test Pypi and is
90+
# stored as a secret in this repo.
91+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"FTDIUSB",
9494
"Fumo",
9595
"GENCODE",
96+
"getcwd",
9697
"González",
9798
"gowin",
9899
"graphviz",
@@ -158,6 +159,7 @@
158159
"pylint",
159160
"pymdownx",
160161
"Pypi",
162+
"pyproject",
161163
"pyserial",
162164
"pytest",
163165
"pyxx",

0 commit comments

Comments
 (0)