Skip to content

Commit 1c879bd

Browse files
modernize version handling (#20)
* Update to using setuptools_scm * update comments * working on version variants * working on build version number * working on PEP 440 version pipeline * base 10 build number * pull tags * update changelog * bump version for testing * do not double tag release versions * bump version * change tag * version bump * working on version mechanics * fix readme for pypi * bump version * update docs * update docs * bump version * tweaks
1 parent 5861664 commit 1c879bd

File tree

10 files changed

+141
-55
lines changed

10 files changed

+141
-55
lines changed

.github/actions/python-build-env-setup/action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ inputs:
1010
runs:
1111
using: "composite"
1212
steps:
13+
- name: Fetch git tags
14+
shell: bash
15+
run: |
16+
git fetch --tags origin
17+
1318
- name: Set up Python
1419
uses: actions/setup-python@v4
1520
with:

.github/actions/version-dot-buildnum-generate/action.yml

+68-23
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ description: |
1616
build artifact file that contains the same.
1717
1818
This action assumes it is working with a Semantic Versioning version
19-
number. The form of the final, full version number is
20-
<branch invariant version>.<build number>-<build variant>
21-
19+
number.
20+
2221
References:
2322
https://semver.org/
2423
https://packaging.python.org/en/latest/specifications/version-specifiers/
24+
https://peps.python.org/pep-0440/
2525
26-
# TODO: Detect branch for consideration of constructing a build_variant automatically?
27-
# Unless we have a strict branching/release policy, this may never be possible.
2826
# TODO: add support for epochs (e.g. "<epoch>!" prefix)
29-
# TODO: add support for local variants (e.g. "+<local variant>" suffix)
3027
# TODO: Can/should we *also* encode the SHA? While I dislike its lack of sequence
3128
# or uniqueness, it *does* encode useful information.
3229

@@ -58,35 +55,83 @@ runs:
5855
using: "composite"
5956
steps:
6057
- id: generate-version-with-buildnum
58+
# This was initially developed to be a generic semver build number
59+
# generator. PEP 440 has some quirks in regard to the semver specification:
60+
# - PEP 440 specifies variant suffixes of the form "b#" over "-beta[.#]"
61+
# In practice, this makes it harder to promote the build number as part of
62+
# the version that appears before the pre-release suffix.
63+
# - PEP 440 expects single letter variants "a", "b", "rc" over
64+
# the textual "alpha", "beta", "rc" identifiers, and only
65+
# expects these defined pre-release variants. Other variants
66+
# do not seem to be well-supported by python tooling.
67+
# - PEP 440 treats development releases as different from the variant,
68+
# rather than being a pre-release variant of pre-alpha maturity.
69+
# Fully handling this would be more complex.
6170
name: "Prepare build version file"
6271
shell: bash
6372
run: |
64-
# Should be closely synonymous with SCM branch
65-
version_invariant=$(head -1 version.txt | tr -d '\n')
66-
67-
# "pre-release" in semver
68-
if [ "${{ inputs.build-variant }}" = "release" ]
69-
then
70-
version_variant=""
71-
else
72-
version_variant=${{ inputs.build-variant }}
73-
fi
74-
7573
# Generated build number
7674
build_timestamp_b10=$(date +%s) # Time based build number - Base 10
7775
build_timestamp_b16=$(printf '%x' ${build_timestamp_b10}) # Time based build number - Base 16 - More compact, but might be interpreted as a non-digit
7876
build_timestamp_bx16=$(printf '0x%x' ${build_timestamp_b10}) # As above, with leading '0x' so it's never not seen as hex (but is less compact)
79-
# Python packaging doesn't like the "x" in the build number build numbers (even though it makes it less ambigious)
80-
# Reverting to base 10 for now. *sigh*
81-
version_buildnum=${build_timestamp_b10}
77+
semver_buildnum=${build_timestamp_b10}
78+
79+
# The invariant portion of the version should be closely
80+
# synonymous with SCM branch
81+
version_invariant=$(head -1 version.txt | tr -d '\n')
82+
83+
# Configure the pre-release variant for the semver
84+
semver_variant=${{ inputs.build-variant }}
85+
case "${{ inputs.build-variant }}" in
86+
dev)
87+
# PEP 440 treats "dev" as a different dimmension than the variant.
88+
# Squashing to alpha to reduce dimmensions we use.
89+
semver_variant_py="a"
90+
semver_buildnum_py="${semver_buildnum}"
91+
;;
92+
alpha)
93+
semver_variant_py="a"
94+
semver_buildnum_py="${semver_buildnum}"
95+
;;
96+
beta)
97+
semver_variant_py="b"
98+
semver_buildnum_py="${semver_buildnum}"
99+
;;
100+
rc)
101+
semver_variant_py="rc"
102+
semver_buildnum_py="${semver_buildnum}"
103+
;;
104+
release)
105+
semver_variant_py=""
106+
# PEP 440 specifies "+<build>" for local variants,
107+
# making it harder to use it for a public release build number.
108+
semver_buildnum_py=""
109+
;;
110+
*)
111+
echo "Unknown build variant: ${{ inputs.build-variant }}"
112+
exit 1
113+
;;
114+
esac
82115
83116
# Putting it all together
84-
printf "${version_invariant}.${version_buildnum}${version_variant:+-}${version_variant}" > version-with-buildnum.txt
117+
118+
# Semver variant 1:
119+
# <version>.<buildnum>-<variant>
120+
# printf "${version_invariant}.${semver_buildnum}${semver_variant:+-}${semver_variant}" > version-with-buildnum.txt
121+
122+
# Semver variant 2:
123+
# <version>-<variant>+<buildnum>
124+
# printf "${version_invariant}${semver_variant:+-}${semver_variant}${semver_buildnum:++}${semver_buildnum}" > version-with-buildnum.txt
125+
126+
# PEP 440 semver variant:
127+
printf "${version_invariant}${semver_variant_py}${semver_buildnum_py}" > version-with-buildnum.txt
128+
129+
# Saving the result as an artifact
85130
echo "Created version-with-buildnum.txt : $(cat version-with-buildnum.txt)"
86131
echo "version-with-buildnum=$(cat version-with-buildnum.txt)" | tee -a $GITHUB_OUTPUT
87132
echo "version=$(cat version.txt)" | tee -a $GITHUB_OUTPUT
88-
echo "buildnum=${version_buildnum}" | tee -a $GITHUB_OUTPUT
89-
echo "variant-normal=${version_variant}" | tee -a $GITHUB_OUTPUT
133+
echo "buildnum=${semver_buildnum}" | tee -a $GITHUB_OUTPUT
134+
echo "variant-normal=${semver_variant}" | tee -a $GITHUB_OUTPUT
90135
echo "variant-raw=${{ inputs.build-variant }}" | tee -a $GITHUB_OUTPUT
91136
- name: Save Artifacts - version-with-buildnum.txt
92137
uses: actions/upload-artifact@v4

.github/workflows/release-build.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ jobs:
2222
uses: ./.github/actions/python-build-env-setup
2323
with:
2424
python-version: ${{ env.PYTHON_VERSION }}
25-
- name: "Pull Build Number"
26-
uses: ./.github/actions/version-dot-buildnum-fetch
27-
with:
28-
version-file: version-with-buildnum.txt
2925
- name: 'Nox: Build Packages'
3026
run: |
3127
nox -s pkg_build_wheel
@@ -44,7 +40,9 @@ jobs:
4440
path: dist/planet_auth*.tar.gz
4541

4642
# Not building this as a release artifact at this time.
47-
# Docs are published to ReadTheDocs through other mechanisms.
43+
# Docs are published to ReadTheDocs through a webhook
44+
# which causes ReadTheDocs.io to pull, build, and publish
45+
# according to its own configuration.
4846
#
4947
# build-docs:
5048
# name: "Build Documentation Packages"
@@ -56,10 +54,6 @@ jobs:
5654
# uses: ./.github/actions/python-build-env-setup
5755
# with:
5856
# python-version: ${{ env.PYTHON_VERSION }}
59-
# # - name: "Pull Build Number"
60-
# # uses: ./.github/actions/version-dot-buildnum-fetch
61-
# # with:
62-
# # version-file: version-with-buildnum.txt
6357
# - name: "Nox: MKDocs Build"
6458
# run: |
6559
# nox -s mkdocs_build

.github/workflows/release-orchestrate.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ jobs:
6363
then
6464
git tag -a -m "Tagging from release orchestration pipeline" "${{steps.gen-buildnum.outputs.version}}"
6565
git push origin "${{steps.gen-buildnum.outputs.version}}"
66+
else
67+
git tag -a -m "Tagging from release orchestration pipeline" "${{steps.gen-buildnum.outputs.version-with-buildnum}}"
68+
git push origin "${{steps.gen-buildnum.outputs.version-with-buildnum}}"
6669
fi
67-
git tag -a -m "Tagging from release orchestration pipeline" "${{steps.gen-buildnum.outputs.version-with-buildnum}}"
68-
git push origin "${{steps.gen-buildnum.outputs.version-with-buildnum}}"
6970
test:
7071
name: "Prerelease Tests"
7172
uses: ./.github/workflows/test.yml
@@ -81,21 +82,21 @@ jobs:
8182
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8283
steps:
8384
- name: "Create Github Release (Version candidate release)"
84-
# if: needs.generate-build-number.outputs.version-variant-raw != 'release'
85+
if: needs.generate-build-number.outputs.version-variant-raw != 'release'
8586
uses: actions/create-release@v1
8687
with:
87-
tag_name: "${{ needs.generate-build-number.outputs.version-with-buildnum }}"
88+
tag_name: "release-${{ needs.generate-build-number.outputs.version-with-buildnum }}"
8889
release_name: "${{ needs.generate-build-number.outputs.version-with-buildnum }}"
8990
draft: false
90-
prerelease: ${{ inputs.version-prerelease }}
91+
prerelease: true
9192
- name: "Create Github Release (Final version release)"
9293
if: needs.generate-build-number.outputs.version-variant-raw == 'release'
9394
uses: actions/create-release@v1
9495
with:
95-
tag_name: "${{ needs.generate-build-number.outputs.version }}"
96+
tag_name: "release-${{ needs.generate-build-number.outputs.version }}"
9697
release_name: "${{ needs.generate-build-number.outputs.version }}"
9798
draft: false
98-
prerelease: ${{ inputs.version-prerelease }}
99+
prerelease: false
99100
package:
100101
name: "Build Release Artifacts"
101102
uses: ./.github/workflows/release-build.yml

RELEASE.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ To release a new version, complete the following steps:
2525

2626
1. Create a release branch off of `main` that bumps the version number in
2727
branch invariant [version.txt](./version.txt) file, and updates the
28-
[changelog.md](./docs/changelog.md). The [version-with-buildnum.txt](./version-with-buildnum.txt)
29-
should also be kept up to date, and is used to assign versions to local
30-
builds.
28+
[changelog.md](./docs/changelog.md).
3129
2. Collect all features targeted for the intended release in the branch, and
3230
create a PR to merge the release branch into `main`.
3331
3. Ensure that all tests are passing on `main` branch after all merges.

docs/changelog.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Changelog
22

3-
## 2.0.4.X - 2025
4-
- Initial Beta release series to shakedown public release pipelines and
5-
initial integrations.
3+
## 2.1.0 - 2025 TBD
4+
- Initial public release targeting integration with the
5+
[Planet Client for Python](https://github.com/planetlabs/planet-client-python).
66

7-
## [Unreleased: 2.0.0 - 2.0.3] - YYYY-MM-DD
8-
- 2.X is the initial public release of Planet auth libraries, targeting
9-
integration with our public Python SDK [`planet-client-python`](https://github.com/planetlabs/planet-client-python)
7+
## [Unreleased: 2.0.*] - YYYY-MM-DD
8+
- All releases in the 2.0.X series are development releases, even if not
9+
tagged as such. This work included some shakedowns of the release pipelines.

docs/readme.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Planet Auth Utility Library
2+
3+
## Overview
4+
The Planet Auth Library provides generic authentication utilities for clients
5+
and services. For clients, it provides the means to obtain access tokens that
6+
can be used to access network services. For services, it provides tools to
7+
validate the same access tokens.
8+
9+
The architecture of the code was driven by OAuth2, but is intended to be easily
10+
extensible to new authentication protocols in the future. Since clients
11+
and resource servers are both themselves clients to authorization servers in
12+
an OAuth2 deployment, this combining of client and server concerns in a single
13+
library was seen as natural.
14+
15+
Currently, this library supports OAuth2, Planet's legacy proprietary
16+
authentication protocols, and static API keys.
17+
18+
This library does not make any assumptions about the specific environment in which
19+
it is operating, leaving that for higher level applications to configure.
20+
21+
The [Planet SDK for Python](https://developers.planet.com/docs/pythonclient/)
22+
leverages this library, and is pre-configured for the Planet Insights Platform used
23+
by customers.
24+
25+
## Installation
26+
Install from PyPI using pip:
27+
28+
```bash
29+
pip install planet-auth
30+
```
31+
32+
## Documentation
33+
34+
See [Planet Auth Library](https://planet-auth.readthedocs.io/en/latest/) on
35+
_ReadTheDocs.io_ for complete documentation.

pyproject.toml

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ requires-python = ">=3.9"
77
dynamic = ["version"]
88
# version = "X.X.X"
99
description = "Planet Auth Utility Code"
10-
readme = "docs/index.md"
10+
# README.md - front page for GitHub. Focus on contributor experience.
11+
# docs/readme.md - front page for PyPI. Library user orientation.
12+
# docs/index.md - front page for ReadTheDocs doc page. Complete developer user documentation.
13+
readme = "docs/readme.md"
1114
authors = [{ name = "Carl Adams", email = "[email protected]" }]
12-
license = {file = "LICENSE"}
15+
license = "Apache-2.0"
16+
license-files = [
17+
"LICENSE",
18+
]
1319
classifiers = [
1420
"Development Status :: 5 - Production/Stable",
15-
"License :: OSI Approved :: Apache Software License",
1621
]
1722
keywords = []
1823
dependencies = [
@@ -78,12 +83,16 @@ internal = [
7883
plauth = "planet_auth_utils.commands.cli.main:cmd_plauth"
7984

8085
[build-system]
81-
requires = ["setuptools>=62.0.0", "wheel"]
86+
requires = ["setuptools>=64", "setuptools_scm>=8", "wheel"]
8287
build-backend = "setuptools.build_meta"
8388

8489
[tool.setuptools.dynamic]
90+
# Using setuptools_scm to manage versioning
8591
# version = {file = "version.txt"}
86-
version = {file = "version-with-buildnum.txt"}
92+
# version = {file = "version-with-buildnum.txt"}
93+
94+
[tool.setuptools_scm]
95+
# version_file = "version-setuptools_scm.txt"
8796

8897
## ###########################################################################
8998
## Testing

version-with-buildnum.txt

-1
This file was deleted.

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.4
1+
2.0.11

0 commit comments

Comments
 (0)