Skip to content

Commit

Permalink
Redo versioning scheme
Browse files Browse the repository at this point in the history
The "-" in the current versioning scheme (for builds other than official
releases) isn't compatible with Python package versioning:

    https://packaging.python.org/en/latest/specifications/version-specifiers/

This will matter when we're releasing Python wheels.  Also, datestamps
don't make it especially clear what's changed since the last release.

Define an openslide-bin version consisting of the OpenSlide version
number, plus a fourth component which represents the openslide-bin package
release and starts from 1.  For builds other than official releases,
append "+" followed by a suffix, which normally consists of a datestamp
plus ".local" but can be overridden with the "-x" option.  Nightly builds
will use a datestamp plus ".nightly".

Update the version embedding mechanism for sdist archives to embed the
suffix (or lack of one) instead of the complete version string.

Add a `version` subcommand to report the calculated version string,
optionally with the specified suffix.

Fixes: #193
Signed-off-by: Benjamin Gilbert <[email protected]>
  • Loading branch information
bgilbert committed Dec 7, 2023
1 parent c8c9c06 commit c18933e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- [ ] Run [workflow](https://github.com/openslide/openslide-bin/actions/workflows/update-check.yml) to check for updates
- [ ] Merge any resulting PR; perform any needed manual updates reported by the workflow
- [ ] Submit PR to update `CHANGELOG.md`
- [ ] Submit PR to update `CHANGELOG.md` and `_PROJECT_VERSION`
- [ ] Land PR
- [ ] Create and push signed tag
- [ ] Verify that CI creates a [GitHub release](https://github.com/openslide/openslide-bin/releases/) with release notes, software versions, and artifacts
Expand Down
30 changes: 18 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ on:
required: false
type: string
default: main
pkgver:
description: Set package version string
suffix:
description: Set package version suffix
required: true
type: string
werror:
Expand All @@ -62,6 +62,9 @@ on:
artifact:
description: The name of the output artifact
value: ${{ jobs.sdist.outputs.artifact }}
version:
description: The version of the output artifact
value: ${{ jobs.sdist.outputs.version }}

permissions:
contents: read
Expand All @@ -73,6 +76,7 @@ jobs:
container: ${{ inputs.windows_builder_repo_and_digest }}
outputs:
artifact: ${{ steps.prep.outputs.artifact }}
version: ${{ steps.prep.outputs.version }}
version_suffix: ${{ steps.prep.outputs.version_suffix }}
steps:
- name: Check out repo
Expand Down Expand Up @@ -119,14 +123,16 @@ jobs:
- name: Build source tarball
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
./build.sh -p "${{ inputs.pkgver }}" sdist
./build.sh -x "${{ inputs.suffix }}" sdist
- name: Prep artifact
id: prep
run: |
artifact="openslide-windows-${{ inputs.pkgver }}"
version=$(./build.sh -x "${{ inputs.suffix }}" version)
echo "version=$version" >> $GITHUB_OUTPUT
artifact="openslide-windows-${version}"
echo "artifact=$artifact" >> $GITHUB_OUTPUT
mkdir -p "output/$artifact"
mv "openslide-bin-${{ inputs.pkgver }}.tar.gz" "output/$artifact"
mv "openslide-bin-${version}.tar.gz" "output/$artifact"
if [ -d override/openslide ]; then
suffix=$(git -C override/openslide rev-parse HEAD | cut -c-7)
echo "version_suffix=$suffix" >> $GITHUB_OUTPUT
Expand All @@ -150,8 +156,8 @@ jobs:
- name: Unpack source tarball
run: |
(cd "${{ needs.sdist.outputs.artifact }}" &&
tar xf "openslide-bin-${{ inputs.pkgver }}.tar.gz")
mv "${{ needs.sdist.outputs.artifact }}/openslide-bin-${{ inputs.pkgver }}"/* .
tar xf "openslide-bin-${{ needs.sdist.outputs.version }}.tar.gz")
mv "${{ needs.sdist.outputs.artifact }}/openslide-bin-${{ needs.sdist.outputs.version }}"/* .
rm -r "${{ needs.sdist.outputs.artifact }}"
- name: Download overrides
if: inputs.openslide_repo != '' || inputs.openslide_java_repo != ''
Expand All @@ -168,10 +174,10 @@ jobs:
if [ "${{ inputs.werror }}" = true ]; then
werror="-w"
fi
./build.sh ${suffix:+-s$suffix} -p "${{ inputs.pkgver }}" \
./build.sh ${suffix:+-s$suffix} -x "${{ inputs.suffix }}" \
$werror bdist
mkdir -p "output/${{ needs.sdist.outputs.artifact }}"
mv "openslide-bin-${{ inputs.pkgver }}-windows-x64.zip" \
mv "openslide-bin-${{ needs.sdist.outputs.version }}-windows-x64.zip" \
"output/${{ needs.sdist.outputs.artifact }}"
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand All @@ -190,12 +196,12 @@ jobs:
name: ${{ needs.sdist.outputs.artifact }}
- name: Unpack artifact
shell: bash
run: unzip "${{ needs.sdist.outputs.artifact }}/openslide-bin-${{ inputs.pkgver }}-windows-x64.zip"
run: unzip "${{ needs.sdist.outputs.artifact }}/openslide-bin-${{ needs.sdist.outputs.version }}-windows-x64.zip"
- name: Report package versions
shell: bash
run: cat "openslide-bin-${{ inputs.pkgver }}-windows-x64/VERSIONS.md" >> $GITHUB_STEP_SUMMARY
run: cat "openslide-bin-${{ needs.sdist.outputs.version }}-windows-x64/VERSIONS.md" >> $GITHUB_STEP_SUMMARY
- name: Smoke test
shell: bash
run: |
cd "${GITHUB_WORKSPACE}/openslide-bin-${{ inputs.pkgver }}-windows-x64/bin"
cd "${GITHUB_WORKSPACE}/openslide-bin-${{ needs.sdist.outputs.version }}-windows-x64/bin"
OPENSLIDE_DEBUG=synthetic ./slidetool.exe prop list ""
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
linux_builder_repo_and_digest: ${{ steps.find-linux.outputs.builder_repo_and_digest }}
pkgver: ${{ steps.params.outputs.pkgver }}
suffix: ${{ steps.params.outputs.suffix }}
windows_builder_repo_and_digest: ${{ steps.find-windows.outputs.builder_repo_and_digest }}
steps:
- name: Check out repo
Expand All @@ -45,7 +45,7 @@ jobs:
builder_image: windows
- name: Calculate parameters
id: params
run: echo "pkgver=main-$(echo ${{ github.sha }} | cut -c-7)" >> $GITHUB_OUTPUT
run: echo "suffix=$(date +%Y%m%d).bin.main.$(echo ${{ github.sha }} | cut -c-7)" >> $GITHUB_OUTPUT

stable:
name: Stable
Expand All @@ -56,5 +56,5 @@ jobs:
macos_enable: true
openslide_bin_repo: ${{ github.repository }}
openslide_bin_ref: ${{ github.ref }}
pkgver: ${{ needs.setup.outputs.pkgver }}
suffix: ${{ needs.setup.outputs.suffix }}
windows_builder_repo_and_digest: ${{ needs.setup.outputs.windows_builder_repo_and_digest }}
8 changes: 4 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
linux_builder_repo_and_digest: ${{ steps.find-linux.outputs.builder_repo_and_digest }}
pkgver: ${{ steps.params.outputs.pkgver }}
suffix: ${{ steps.params.outputs.suffix }}
windows_builder_repo_and_digest: ${{ steps.find-windows.outputs.builder_repo_and_digest }}
steps:
- name: Check out repo
Expand All @@ -44,7 +44,7 @@ jobs:
builder_image: windows
- name: Calculate parameters
id: params
run: echo "pkgver=pr-${{ github.event.number }}.${{ github.run_number }}.${{ github.run_attempt }}-$(echo ${{ github.sha }} | cut -c-7)" >> $GITHUB_OUTPUT
run: echo "suffix=$(date +%Y%m%d).bin.pr.${{ github.event.number }}.${{ github.run_number }}.${{ github.run_attempt }}.$(echo ${{ github.sha }} | cut -c-7)" >> $GITHUB_OUTPUT

stable:
name: Stable
Expand All @@ -55,7 +55,7 @@ jobs:
macos_enable: true
openslide_bin_repo: ${{ github.repository }}
openslide_bin_ref: ${{ github.ref }}
pkgver: ${{ needs.setup.outputs.pkgver }}-stable
suffix: ${{ needs.setup.outputs.suffix }}.stable
windows_builder_repo_and_digest: ${{ needs.setup.outputs.windows_builder_repo_and_digest }}

git:
Expand All @@ -71,6 +71,6 @@ jobs:
openslide_java_ref: main
openslide_bin_repo: ${{ github.repository }}
openslide_bin_ref: ${{ github.ref }}
pkgver: ${{ needs.setup.outputs.pkgver }}-git
suffix: ${{ needs.setup.outputs.suffix }}.git
werror: true
windows_builder_repo_and_digest: ${{ needs.setup.outputs.windows_builder_repo_and_digest }}
12 changes: 4 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
runs-on: ubuntu-latest
outputs:
linux_builder_repo_and_digest: ${{ steps.find-linux.outputs.builder_repo_and_digest }}
pkgver: ${{ steps.params.outputs.pkgver }}
windows_builder_repo_and_digest: ${{ steps.find-windows.outputs.builder_repo_and_digest }}
steps:
- name: Check out repo
Expand All @@ -32,9 +31,6 @@ jobs:
uses: ./.github/find-container-digest
with:
builder_image: windows
- name: Calculate parameters
id: params
run: echo "pkgver=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

stable:
name: Stable
Expand All @@ -45,7 +41,7 @@ jobs:
macos_enable: true
openslide_bin_repo: ${{ github.repository }}
openslide_bin_ref: ${{ github.ref }}
pkgver: ${{ needs.setup.outputs.pkgver }}
suffix: ""
windows_builder_repo_and_digest: ${{ needs.setup.outputs.windows_builder_repo_and_digest }}

release:
Expand All @@ -63,7 +59,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
unzip "${{ needs.stable.outputs.artifact }}/openslide-bin-${{ needs.setup.outputs.pkgver }}-windows-x64.zip"
unzip "${{ needs.stable.outputs.artifact }}/openslide-bin-${{ needs.stable.outputs.version }}-windows-x64.zip"
echo "## Changes" > changes
awk -e '/^## / && ok {exit}' \
Expand All @@ -72,12 +68,12 @@ jobs:
"openslide-win64-${{ needs.setup.outputs.pkgver }}/CHANGELOG.md" \
>> changes
echo -e "## Versions\n" >> changes
cat "openslide-bin-${{ needs.setup.outputs.pkgver }}-windows-x64/VERSIONS.md" \
cat "openslide-bin-${{ needs.stable.outputs.version }}-windows-x64/VERSIONS.md" \
>> changes
gh release create --latest --verify-tag \
--repo "${{ github.repository }}" \
--title "Windows build ${{ needs.setup.outputs.pkgver }}" \
--title "Windows build ${{ needs.stable.outputs.version }}" \
--notes-file changes \
"${{ github.ref_name }}" \
"${{ needs.stable.outputs.artifact }}/"*
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ those packages in the specified bitness.

Check for new releases of software packages.

#### `version`

Report the version number that will be used in archive file names.

## Options

These must be specified before the subcommand.
Expand All @@ -49,14 +53,14 @@ These must be specified before the subcommand.

Parallel build with the specified parallelism.

#### `-p<pkgver>`

Set package version string in Zip file names to `pkgver`.

#### `-s<suffix>`

Append `suffix` to the OpenSlide version string.

#### `-w`

Treat OpenSlide and OpenSlide Java build warnings as errors.

#### `-x<suffix>`

Set version number suffix in archive file names to `suffix`.
8 changes: 6 additions & 2 deletions artifacts/postprocess-sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class Args(TypedArgs):
os.environ['MESONINTROSPECT'] = args.introspect
dest = Path(os.environ['MESON_DIST_ROOT'])

# pin openslide-bin version
# pin openslide-bin version suffix
version: str = meson_introspect('projectinfo')['version']
(dest / 'version').write_text(version + '\n')
try:
suffix = version.split('+', 1)[1]
except IndexError:
suffix = ''
(dest / 'suffix').write_text(suffix + '\n')
32 changes: 19 additions & 13 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ clean() {
done
rm -rf "${build}"
grep -Flx "[wrap-redirect]" subprojects/*.wrap | xargs -r rm
if [ ! -e version ]; then
if [ ! -e suffix ]; then
meson subprojects purge --confirm >/dev/null
fi
else
echo "Cleaning..."
rm -rf 64 openslide-bin-*.{tar.gz,zip}
grep -Flx "[wrap-redirect]" subprojects/*.wrap | xargs -r rm
if [ ! -e version ]; then
if [ ! -e suffix ]; then
meson subprojects purge --confirm >/dev/null
fi
fi
Expand Down Expand Up @@ -277,11 +277,12 @@ probe() {
exit 1
fi

if [ -z "${pkgver}" ]; then
export -n OPENSLIDE_BIN_VERSION
pkgver="$(MESON_SOURCE_ROOT=. python3 utils/get-version.py)"
if [ "${pkg_suffix}" != "-DEFAULT-" ]; then
export OPENSLIDE_BIN_SUFFIX="${pkg_suffix}"
else
export -n OPENSLIDE_BIN_SUFFIX
fi
export OPENSLIDE_BIN_VERSION="${pkgver}"
pkgver="$(MESON_SOURCE_ROOT=. python3 utils/get-version.py)"

sbuild=64/sdist
build=64/build
Expand All @@ -300,24 +301,24 @@ trap fail_handler ERR

# Parse command-line options
parallel=""
pkgver=""
pkg_suffix="-DEFAULT-"
ver_suffix=""
openslide_werror=""
while getopts "j:p:s:w" opt
while getopts "j:s:wx:" opt
do
case "$opt" in
j)
parallel="-j${OPTARG}"
;;
p)
pkgver="${OPTARG}"
;;
s)
ver_suffix="${OPTARG}"
;;
w)
openslide_werror="-Dopenslide:werror=true -Dopenslide-java:werror=true"
;;
x)
pkg_suffix="${OPTARG}"
;;
esac
done
shift $(( $OPTIND - 1 ))
Expand Down Expand Up @@ -347,12 +348,17 @@ clean)
updates)
updates
;;
version)
probe
echo "${pkgver}"
;;
*)
cat <<EOF
Usage: $0 [-p<pkgver>] sdist
$0 [-j<n>] [-p<pkgver>] [-s<suffix>] [-w] bdist
Usage: $0 [-x<suffix>] sdist
$0 [-j<n>] [-s<suffix>] [-w] [-x<suffix>] bdist
$0 clean [package...]
$0 updates
$0 [-x<suffix>] version
Packages:
$packages
Expand Down
33 changes: 25 additions & 8 deletions common/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@
import json
import os
from pathlib import Path
import re
import shlex
import subprocess
from typing import Any

# A.B.C.D
# A.B.C = OpenSlide version
# D = ordinal of the openslide-bin release with this A.B.C, starting from 1
# Update the version when releasing openslide-bin.
_PROJECT_VERSION = '4.0.0.1'


def meson_source_root() -> Path:
return Path(os.environ['MESON_SOURCE_ROOT'])
Expand All @@ -53,13 +60,23 @@ def parse_ini_file(path: Path) -> configparser.RawConfigParser:
return ini


def default_version() -> str:
# try the version pinned by 'meson dist'
def project_version(suffix: str) -> str:
if not re.match('[a-zA-Z0-9.]*$', suffix):
raise Exception('Invalid character in version suffix')
if suffix:
return f'{_PROJECT_VERSION}+{suffix}'
else:
return _PROJECT_VERSION


def default_suffix() -> str:
# try the suffix pinned by 'meson dist'
try:
ver = (meson_source_root() / 'version').read_text().strip()
# append "-local" if missing
if '-local' not in ver:
ver += '-local'
return ver
suffix = (meson_source_root() / 'suffix').read_text().strip()
segments = suffix.split('.') if suffix else []
# append "local" segment if missing
if 'local' not in segments:
segments.append('local')
return '.'.join(segments)
except FileNotFoundError:
return date.today().strftime('%Y%m%d') + '-local'
return date.today().strftime('%Y%m%d') + '.local'
8 changes: 3 additions & 5 deletions utils/get-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
# flake8 isn't happy about this
sys.path.insert(0, os.environ['MESON_SOURCE_ROOT'])

from common.meson import default_version # noqa: E402
from common.meson import default_suffix, project_version # noqa: E402

ver = os.environ.get('OPENSLIDE_BIN_VERSION')
if not ver:
ver = default_version()
print(ver)
suffix = os.environ.get('OPENSLIDE_BIN_SUFFIX', default_suffix())
print(project_version(suffix))

0 comments on commit c18933e

Please sign in to comment.