Skip to content

Commit ef116f3

Browse files
Merge branch 'carl/initial-drop-from-internal--cicd' into carl/initial-drop-from-internal--docs
2 parents bc16177 + 6944d9c commit ef116f3

19 files changed

Lines changed: 633 additions & 91 deletions

File tree

.github/actions/python-common-setup/action.yml renamed to .github/actions/python-build-env-setup/action.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ inputs:
55
python-version:
66
description: 'Python version to use'
77
required: true
8-
default: 3.13
9-
10-
# outputs:
8+
default: "3.13"
119

1210
runs:
1311
using: "composite"
@@ -30,3 +28,8 @@ runs:
3028
shell: bash
3129
run: |
3230
pip install --upgrade nox
31+
32+
- name: "Build Environment"
33+
shell: bash
34+
run: |
35+
printenv | sort
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Pull generated version and build number'
2+
description: |
3+
Pull generated build number artifacts.
4+
5+
inputs:
6+
version-file:
7+
description: |
8+
file to save the version and build number file for the local build.
9+
required: false
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: "Pull Build Version"
15+
uses: actions/download-artifact@v4
16+
with:
17+
name: version-with-buildnum-file
18+
path: version-with-buildnum.artifact
19+
- name: "Install Build Version File"
20+
shell: bash
21+
run: |
22+
if [ -n "${{ inputs.version-file }}" ]
23+
then
24+
cp -f version-with-buildnum.artifact/version-with-buildnum.txt ${{ inputs.version-file }}
25+
fi
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: 'Generate a version-with-buildnum.txt file'
2+
description: |
3+
Generate a version string that includes a generated build number and build
4+
variant appended. The version.txt file is used to obtain the branch
5+
invariant portion of the full version. The generated build number will
6+
be unique (within reason) and increasing so that within a lineage the full
7+
version number encodes relative position of any build. The generated build
8+
number is not guaranteed to be sequential.
9+
10+
The current implementation uses a time based build number. Sequence numbers
11+
from the CI/CD system were also considered, and can work just as well.
12+
Repository hashes were not used since they neither encode the relative
13+
build position nor are they unique upon rebuild.
14+
15+
The generated version is output both as a job output string and as a
16+
build artifact file that contains the same.
17+
18+
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+
22+
References:
23+
https://semver.org/
24+
https://packaging.python.org/en/latest/specifications/version-specifiers/
25+
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.
28+
# TODO: add support for epochs (e.g. "<epoch>!" prefix)
29+
# TODO: add support for local variants (e.g. "+<local variant>" suffix)
30+
# TODO: Can/should we *also* encode the SHA? While I dislike its lack of sequence
31+
# or uniqueness, it *does* encode useful information.
32+
33+
inputs:
34+
build-variant:
35+
description: |
36+
Build variant. E.g. "dev", "beta", "rc", etc. Use the keyword "release" for
37+
production releases that should not specify a variant.
38+
required: true
39+
40+
outputs:
41+
version-with-buildnum:
42+
description: 'Full version with variant build number appended'
43+
value: ${{ steps.generate-version-with-buildnum.outputs.version-with-buildnum }}
44+
version:
45+
description: 'Just the simple branch invariant version'
46+
value: ${{ steps.generate-version-with-buildnum.outputs.version }}
47+
buildnum:
48+
description: 'Just the generated build number'
49+
value: ${{ steps.generate-version-with-buildnum.outputs.buildnum }}
50+
variant-normal:
51+
description: 'Normalized build variant string'
52+
value: ${{ steps.generate-version-with-buildnum.outputs.variant-normal }}
53+
variant-raw:
54+
description: 'Raw build variant string (same as input)'
55+
value: ${{ steps.generate-version-with-buildnum.outputs.variant-raw }}
56+
57+
runs:
58+
using: "composite"
59+
steps:
60+
- id: generate-version-with-buildnum
61+
name: "Prepare build version file"
62+
shell: bash
63+
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+
75+
# Generated build number
76+
build_timestamp_b10=$(date +%s) # Time based build number - Base 10
77+
build_timestamp_b16=$(printf '%x' ${build_timestamp_b10}) # Time based build number - Base 16 - More compact, but might be interpreted as a non-digit
78+
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}
82+
83+
# Putting it all together
84+
printf "${version_invariant}.${version_buildnum}${version_variant:+-}${version_variant}" > version-with-buildnum.txt
85+
echo "Created version-with-buildnum.txt : $(cat version-with-buildnum.txt)"
86+
echo "version-with-buildnum=$(cat version-with-buildnum.txt)" | tee -a $GITHUB_OUTPUT
87+
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
90+
echo "variant-raw=${{ inputs.build-variant }}" | tee -a $GITHUB_OUTPUT
91+
- name: Save Artifacts - version-with-buildnum.txt
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: version-with-buildnum-file
95+
path: version-with-buildnum.txt
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build Release Artifacts
2+
3+
permissions:
4+
actions: read
5+
contents: read
6+
7+
on:
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
env:
12+
PYTHON_VERSION: "3.13"
13+
14+
jobs:
15+
build-packages:
16+
name: Build Distribution Packages
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: "Checkout code"
20+
uses: actions/checkout@v4
21+
- name: Prepare common Python build environment
22+
uses: ./.github/actions/python-build-env-setup
23+
with:
24+
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
29+
- name: 'Nox: Build Packages'
30+
run: |
31+
nox -s pkg_build_wheel
32+
- name: 'Nox: Check Packages'
33+
run: |
34+
nox -s pkg_check
35+
- name: "Save Artifacts - Wheel"
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: planet-auth-wheel
39+
path: dist/planet_auth*.whl
40+
- name: "Save Artifacts - Source Package"
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: planet-auth-src-targz
44+
path: dist/planet_auth*.tar.gz
45+
46+
build-docs:
47+
name: "Build Documentation Packages"
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: "Checkout code"
51+
uses: actions/checkout@v4
52+
- name: Prepare common Python build environment
53+
uses: ./.github/actions/python-build-env-setup
54+
with:
55+
python-version: ${{ env.PYTHON_VERSION }}
56+
# - name: "Pull Build Number"
57+
# uses: ./.github/actions/version-dot-buildnum-fetch
58+
# with:
59+
# version-file: version-with-buildnum.txt
60+
- name: "Nox: MKDocs Build"
61+
run: |
62+
nox -s mkdocs_build
63+
- name: "Save Artifacts - MkDocs"
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: planet-auth-mkdocs-site
67+
path: site/**
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Release Orchestration
2+
3+
permissions:
4+
actions: read
5+
contents: read
6+
7+
# TODO: insure we can only release from privileged branches/tags?
8+
9+
on:
10+
# push: # Just for testing FIXME: Remove this.
11+
workflow_dispatch:
12+
inputs:
13+
build-variant:
14+
description: "Build Variant"
15+
type: choice
16+
default: "dev"
17+
options:
18+
- dev
19+
- alpha
20+
- beta
21+
- rc
22+
- release
23+
24+
env:
25+
PYTHON_VERSION: "3.13"
26+
27+
jobs:
28+
generate-build-number:
29+
name: "Generate build number"
30+
runs-on: ubuntu-latest
31+
permissions:
32+
actions: read
33+
contents: write
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
steps:
37+
- name: "Checkout code"
38+
uses: actions/checkout@v4
39+
- name: "Generate unique version and build numbers"
40+
id: gen-buildnum
41+
uses: ./.github/actions/version-dot-buildnum-generate
42+
with:
43+
build-variant: ${{ inputs.build-variant }}
44+
- name: "Tag repository"
45+
# Tagging is part of the build number generation in part because
46+
# tag uniqueness serves as a synchronization mechanism to prevent
47+
# multiple releases of the same version.
48+
run: |
49+
set -x
50+
git config --global user.email "planet-auth-python-github-cicd@planet.com"
51+
git config --global user.name "CICD for github repository ${GITHUB_REPOSITORY}"
52+
if [ "${{ steps.gen-buildnum.outputs.variant-raw }}" = "release" ]
53+
then
54+
git tag -a -m "test tag comment for final release" "${{steps.gen-buildnum.outputs.version}}"
55+
git push origin "${{steps.gen-buildnum.outputs.version}}"
56+
fi
57+
git tag -a -m "test tag comment" "${{steps.gen-buildnum.outputs.version-with-buildnum}}"
58+
git push origin "${{steps.gen-buildnum.outputs.version-with-buildnum}}"
59+
test:
60+
name: "Prerelease Tests"
61+
uses: ./.github/workflows/test.yml
62+
needs: generate-build-number # Doesn't really need it, but gates the pipeline to not waste time.
63+
package:
64+
name: "Build Release Artifacts"
65+
uses: ./.github/workflows/release-build.yml
66+
needs: [test, generate-build-number]
67+
publish:
68+
name: "Publish Release Artifacts"
69+
uses: ./.github/workflows/release-publish.yml
70+
needs: [package, generate-build-number]
71+
secrets:
72+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
73+
PYPI_API_TOKEN_TEST: ${{ secrets.PYPI_API_TOKEN_TEST }}
74+
# with:
75+
# version-with-buildnumber: ${{needs.generate-build-number.outputs.version-with-buildnum}}

0 commit comments

Comments
 (0)