Skip to content

Commit a1dadcd

Browse files
committed
update on-release-main workflow with modern permissions
1 parent 12a55b0 commit a1dadcd

File tree

6 files changed

+448
-29
lines changed

6 files changed

+448
-29
lines changed

.github/workflows/on-release-main.yml

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,13 @@ on:
55
types: [published]
66

77
jobs:
8-
9-
set-version:
10-
runs-on: ubuntu-24.04
11-
steps:
12-
- uses: actions/checkout@v4
13-
14-
- name: Export tag
15-
id: vars
16-
run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
17-
if: ${{ github.event_name == 'release' }}
18-
19-
- name: Update project version
20-
run: |
21-
sed -i "s/^version = \".*\"/version = \"$RELEASE_VERSION\"/" pyproject.toml
22-
env:
23-
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
24-
if: ${{ github.event_name == 'release' }}
25-
26-
- name: Upload updated pyproject.toml
27-
uses: actions/upload-artifact@v4
28-
with:
29-
name: pyproject-toml
30-
path: pyproject.toml
31-
328
publish:
339
runs-on: ubuntu-latest
34-
needs: [set-version]
10+
11+
permissions:
12+
id-token: write
13+
contents: write
14+
3515
steps:
3616
- name: Check out
3717
uses: actions/checkout@v4
@@ -48,13 +28,15 @@ jobs:
4828
run: uv build
4929

5030
- name: Publish package
31+
# Requires trusted publisher configuration at pypi
32+
# No environment tokens required
5133
run: uv publish
52-
env:
53-
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
5434

5535
deploy-docs:
5636
needs: publish
5737
runs-on: ubuntu-latest
38+
permissions:
39+
contents: write
5840
steps:
5941
- name: Check out
6042
uses: actions/checkout@v4

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
__marimo__/
32
__pycache__/
43
__pypackages__/

orig2/Makefile

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Makefile for Python project
2+
3+
.DELETE_ON_ERROR:
4+
.PHONY: FORCE
5+
.PRECIOUS:
6+
.SUFFIXES:
7+
8+
ifeq ("","$(shell command -v zsh)")
9+
$(error "zsh not found; you must install zsh first")
10+
endif
11+
12+
SHELL:=zsh -eu -o pipefail -o null_glob
13+
SELF:=$(firstword $(MAKEFILE_LIST))
14+
15+
VE_DIR:=.venv
16+
PY_VERSION:=3.13
17+
18+
SRC_DIRS:=src
19+
TEST_DIRS:=tests
20+
DOC_TESTS:=${SRC_DIRS} # ./README.md
21+
22+
23+
############################################################################
24+
#= BASIC USAGE
25+
default: help
26+
27+
#=> help -- display this help message
28+
help:
29+
@sbin/makefile-extract-documentation "${SELF}"
30+
31+
32+
############################################################################
33+
#= SETUP, INSTALLATION, PACKAGING
34+
35+
#=> devready: create venv, install prerequisites, install pkg in develop mode
36+
.PHONY: devready
37+
devready:
38+
make ${VE_DIR} && source ${VE_DIR}/bin/activate && make develop
39+
@echo '#################################################################################'
40+
@echo '### Do not forget to `source ${VE_DIR}/bin/activate` to use this environment ###'
41+
@echo '#################################################################################'
42+
43+
#=> venv: make a Python 3 virtual environment
44+
${VE_DIR}:
45+
uv venv --python ${PY_VERSION} $@
46+
47+
#=> develop: install package in develop mode
48+
.PHONY: develop
49+
develop:
50+
uv sync --extra dev --extra tests
51+
pre-commit install
52+
53+
#=> install: install package
54+
.PHONY: install
55+
install:
56+
uv sync
57+
58+
#=> build: make sdist and wheel
59+
.PHONY: build
60+
build: %:
61+
python -m build
62+
63+
64+
############################################################################
65+
#= TESTING
66+
# see test configuration in setup.cfg
67+
68+
#=> test: execute tests
69+
#=> test-code: test code (including embedded doctests)
70+
#=> test-docs: test example code in docs
71+
.PHONY: test test-code test-docs
72+
test:
73+
pytest --cov ${SRC_DIRS}
74+
test-code:
75+
pytest ${TEST_DIRS}
76+
test-docs:
77+
pytest ${DOC_TESTS}
78+
stest:
79+
pytest -vvv -s -k ${t}
80+
test-%:
81+
pytest -m '$*' ${TEST_DIRS}
82+
83+
#=> tox -- run all tox tests
84+
tox:
85+
uvx tox
86+
87+
#=> cqa: execute code quality tests
88+
cqa:
89+
uvx ruff format --check
90+
uvx ruff check
91+
92+
############################################################################
93+
#= UTILITY TARGETS
94+
95+
#=> reformat: reformat code
96+
.PHONY: reformat
97+
reformat:
98+
uvx ruff check --fix
99+
uvx ruff format
100+
101+
#=> docs -- make sphinx docs
102+
.PHONY: docs
103+
docs: develop
104+
# RTD makes json. Build here to ensure that it works.
105+
make -C docs html json
106+
107+
############################################################################
108+
#= CLEANUP
109+
110+
#=> clean: remove temporary and backup files
111+
.PHONY: clean
112+
clean:
113+
rm -frv **/*~ **/*.bak
114+
-make -C docs $@
115+
-make -C examples $@
116+
117+
#=> cleaner: remove files and directories that are easily rebuilt
118+
.PHONY: cleaner
119+
cleaner: clean
120+
rm -frv .cache build dist docs/_build
121+
rm -frv **/__pycache__
122+
rm -frv **/*.egg-info
123+
rm -frv **/*.pyc
124+
rm -frv **/*.orig
125+
rm -frv **/*.rej
126+
-make -C docs $@
127+
-make -C examples $@
128+
129+
#=> cleanest: remove files and directories that are more expensive to rebuild
130+
.PHONY: cleanest
131+
cleanest: cleaner
132+
rm -frv .eggs .tox venv
133+
-make -C docs $@
134+
-make -C examples $@
135+
136+
#=> distclean: remove untracked files and other detritus
137+
.PHONY: distclean
138+
distclean: cleanest
139+
git clean -df
140+
141+
142+
############################################################################
143+
#= Repo renamer
144+
145+
#=> rename: rename files and substitute content for new repo name
146+
.PHONY: rename
147+
rename:
148+
./sbin/rename-package
149+
150+
151+
## <LICENSE>
152+
## Copyright 2023 Source Code Committers
153+
##
154+
## Licensed under the Apache License, Version 2.0 (the "License");
155+
## you may not use this file except in compliance with the License.
156+
## You may obtain a copy of the License at
157+
##
158+
## http://www.apache.org/licenses/LICENSE-2.0
159+
##
160+
## Unless required by applicable law or agreed to in writing, software
161+
## distributed under the License is distributed on an "AS IS" BASIS,
162+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163+
## See the License for the specific language governing permissions and
164+
## limitations under the License.
165+
## </LICENSE>

orig2/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# biocommons.example Test Package
2+
3+
[![codecov](https://codecov.io/gh/biocommons/biocommons.example/graph/badge.svg?token=CCUMQQV5R6)](https://codecov.io/gh/biocommons/biocommons.example)
4+
5+
---
6+
7+
This repo provides a template for biocommons Python packages. Here's how to use it:
8+
9+
1. Click the [Use this template](https://github.com/biocommons/example/generate)
10+
button. Name the new repo like "biocommons.something".
11+
1. Clone your repo locally.
12+
1. In the repo, type `make rename`. The new name will be chosen based on the repo name.
13+
1. Remove this header.
14+
1. Commit and push.
15+
16+
Delete this section in your generated template.
17+
18+
---
19+
20+
## Installation
21+
22+
To install from pypi: ```pip install biocommons.example```
23+
24+
## Developer Setup
25+
26+
### Prerequisites
27+
28+
- [GNU make](https://www.gnu.org/software/make/): Current mechanism for consistent invocation of developer tools.
29+
- Mac: [Install brew](https://brew.sh/), then [install make](https://formulae.brew.sh/formula/make)
30+
- Ubuntu: `sudo apt install make`
31+
- [uv](https://docs.astral.sh/uv/): An extremely fast Python package and project manager, written in Rust.
32+
- All platforms: See the [uv installation instructions](https://docs.astral.sh/uv/getting-started/installation/).
33+
- [zsh](https://www.zsh.org/): Shell used by the Makefile
34+
- Mac: included by default
35+
- Ubuntu: `sudo apt install zsh`
36+
37+
### One-time developer setup
38+
39+
Create a Python virtual environment and install dependencies:
40+
41+
make devready
42+
43+
### Development
44+
45+
Activate your environment:
46+
47+
source venv/bin/activate
48+
49+
Code reformatting:
50+
51+
make reformat
52+
53+
Test:
54+
55+
make test # for current environment
56+
make tox # for all supported versions
57+
58+
Build:
59+
60+
git tag 0.0.0
61+
make build
62+
63+
Try it:
64+
65+
$ python3 -m biocommons.example
66+
Marvin says:
67+
There's only one life-form as intelligent as me within thirty parsecs...
68+
69+
$ marvin-quote
70+
Marvin says:
71+
You think you've got problems? What are you supposed to do if you...
72+
73+
$ ipython
74+
>>> from biocommons.example import __version__, get_quote_from_marvin
75+
>>> __version__
76+
'0.1.dev8+gd5519a8.d20211123'
77+
>>> get_quote()
78+
"The first ten million years were the worst, ...
79+
80+
81+
# Features
82+
83+
## Code structure and features
84+
85+
* Modern pyproject.toml with setuptools
86+
* Versioning based on git tag (only)
87+
* Easy development setup
88+
* Support for namespaces
89+
* Testing with coverage using pytest; tests may be in `tests/`, embedded in the package, and in doc strings
90+
* Examples for logging and package data
91+
* Command-line with argument parsing with argparse
92+
93+
## DevOps
94+
95+
* Quality tools: Code linting and reformatting with Ruff
96+
* GitHub Actions for testing and packaging

0 commit comments

Comments
 (0)