Skip to content

Commit c76e702

Browse files
Merge pull request #31 from datajoint/feature/ghactions
add PyPI publishing workflow
2 parents 81b472b + 40be0cb commit c76e702

File tree

3 files changed

+69
-24
lines changed

3 files changed

+69
-24
lines changed
Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,78 @@
1-
name: Release to PyPI
1+
name: Publish to PyPI
22

33
on:
4-
push:
5-
tags:
6-
- '*'
4+
release:
5+
types:
6+
- published
7+
workflow_dispatch:
78

89
jobs:
9-
deploy:
10+
dist:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
1018

19+
- name: Build and inspect package
20+
uses: hynek/build-and-inspect-python-package@v2
21+
22+
publish:
23+
needs: dist
1124
runs-on: ubuntu-latest
25+
if: github.event_name == 'release' && github.event.action == 'published'
1226

1327
steps:
14-
- uses: actions/checkout@v2
15-
- name: Set up Python 3.9
16-
uses: actions/setup-python@v2
28+
- name: Download built artifacts
29+
uses: actions/download-artifact@v4
1730
with:
18-
python-version: 3.9
19-
- name: Install dependencies for testing
20-
run: |
21-
pip install pytest
22-
pip install zarr
23-
pip install setuptools wheel twine
24-
pip install .
25-
- name: Test core with pytest
31+
name: Packages
32+
path: dist
33+
34+
- name: Configure publish credentials
35+
id: publish-config
36+
env:
37+
RELEASE_NAME: ${{ github.event.release.name }}
38+
DEFAULT_USERNAME: ${{ secrets.twine_username }}
39+
DEFAULT_PASSWORD: ${{ secrets.twine_password }}
40+
TEST_USERNAME: ${{ secrets.twine_test_username }}
41+
TEST_PASSWORD: ${{ secrets.twine_test_password }}
2642
run: |
27-
pytest -v
28-
- name: Publish on PyPI
43+
set -euo pipefail
44+
45+
repository="pypi"
46+
username="$DEFAULT_USERNAME"
47+
password="$DEFAULT_PASSWORD"
48+
49+
if [[ -n "${RELEASE_NAME}" && "${RELEASE_NAME}" =~ ^[Tt]est ]]; then
50+
if [[ -z "${TEST_USERNAME}" || -z "${TEST_PASSWORD}" ]]; then
51+
echo "::error::Test PyPI credentials are required for releases starting with 'Test'"
52+
exit 1
53+
fi
54+
repository="testpypi"
55+
username="$TEST_USERNAME"
56+
password="$TEST_PASSWORD"
57+
fi
58+
59+
if [[ -z "${username}" || -z "${password}" ]]; then
60+
echo "::error::PyPI credentials are not configured"
61+
exit 1
62+
fi
63+
64+
{
65+
echo "repository=${repository}"
66+
echo "username=${username}"
67+
echo "password=${password}"
68+
} >> "$GITHUB_OUTPUT"
69+
70+
- name: Publish distribution
2971
env:
30-
TWINE_USERNAME: __token__
31-
TWINE_PASSWORD: ${{ secrets.AIND_PYPI_TOKEN }}
72+
TWINE_USERNAME: ${{ steps.publish-config.outputs.username }}
73+
TWINE_PASSWORD: ${{ steps.publish-config.outputs.password }}
74+
TWINE_REPOSITORY: ${{ steps.publish-config.outputs.repository }}
3275
run: |
33-
python setup.py sdist
34-
twine upload dist/*
76+
python -m pip install --upgrade pip
77+
python -m pip install twine
78+
twine upload --repository "${TWINE_REPOSITORY}" dist/*

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2024, Allen Institute for Neural Dynamics, DataJoint Inc, CatalystNeuro, and contributors
3+
Copyright (c) 2024, Allen Institute for Neural Dynamics, DataJoint Inc., CatalystNeuro, and contributors
4+
Copyright (c) 2025, DataJoint Inc.
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,4 @@ checks = [
206206
]
207207

208208
[tool.codespell]
209-
ignore-words-list = "Nd"
209+
ignore-words-list = "Nd"

0 commit comments

Comments
 (0)