Skip to content

Commit

Permalink
ci: github and python publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Oct 13, 2024
1 parent 83e0303 commit af5bf41
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 62 deletions.
118 changes: 116 additions & 2 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ name: Dist
on:
push:
branches: [ release, next ]
pull_request:
branches: [ release, next ]

# Notes on the Wheels:
# macos-13 is an intel runner, which cibw wants for x86 builds... But intel mac is busted.
# https://github.com/e-dant/watcher/actions/runs/9929111640/job/27426247416#step:3:293
# We don't support Windows (but we want to) because meson-python doesn't allow us
# to install shared libraries in wheels for Windows. More info and whatnot here:
# https://github.com/mesonbuild/meson-python/discussions/629
# Other refs, for the action file:
# - https://cibuildwheel.pypa.io/en/stable/setup
# - https://github.com/scikit-image/scikit-image/blob/main/.github/workflows/wheels_recipe.yml
jobs:
linux-dist:
runs-on: ${{matrix.os}}
Expand Down Expand Up @@ -79,3 +86,110 @@ jobs:
with:
name: ${{matrix.triple}}.tar.sha256sum
path: out/${{matrix.triple}}.tar.sha256sum
wheels-linux:
name: (x86_64|aarch64)-unknown-linux-(gnu|musl)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- uses: pypa/[email protected]
with:
package-dir: .
output-dir: wheelhouse
config-file: pyproject.toml
- run: python3 tool/shasum.py wheelhouse show
- run: python3 tool/shasum.py wheelhouse mk
- uses: actions/upload-artifact@v4
with:
name: wheels-linux
path: wheelhouse/*
wheels-apple:
name: aarch64-apple-darwin
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: pypa/[email protected]
env:
MACOSX_DEPLOYMENT_TARGET: 11
with:
package-dir: .
output-dir: wheelhouse
config-file: pyproject.toml
- run: python3 tool/shasum.py wheelhouse show
- run: python3 tool/shasum.py wheelhouse mk
- uses: actions/upload-artifact@v4
with:
name: wheels-apple
path: wheelhouse/*
create-gh-release:
name: Create GitHub Release
if: ${{ github.ref == 'refs/heads/release' }}
runs-on: ubuntu-latest
needs:
- linux-dist
- apple-dist
- windows-dist
steps:
- uses: actions/checkout@v4
- run: |
tool/fetch-release-artifacts --no-zip
gh release create "$(cat .version)" --notes "$(tool/show-changelog-for-version)"
gh release upload "$(cat .version)" out/dist/*
env:
GITHUB_TOKEN: ${{ github.token }}
# Ref: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows
publish-wheels-testpypi:
name: Publish Wheels (TestPyPI)
runs-on: ubuntu-latest
needs:
- wheels-apple
- wheels-linux
environment:
name: dist
url: https://test.pypi.org/p/wtr-watcher
permissions: write-all
steps:
- uses: actions/checkout@v4
with:
token: ${{ github.token }}
- run: |
tool/fetch-release-artifacts --no-zip
mkdir dist
find out/dist -name '*.whl' | while read f
do cp "$f" dist ; echo "$f"
done
env:
GH_TOKEN: ${{ github.token }}
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
publish-wheels-pypi:
name: Publish Wheels
if: ${{ github.ref == 'refs/heads/release' }}
runs-on: ubuntu-latest
needs:
- wheels-apple
- wheels-linux
environment:
name: dist
url: https://pypi.org/p/wtr-watcher
permissions: write-all
steps:
- uses: actions/checkout@v4
with:
token: ${{ github.token }}
- run: |
tool/fetch-release-artifacts --no-zip
mkdir dist
find out/dist -name '*.whl' | while read f
do cp "$f" dist ; echo "$f"
done
env:
GH_TOKEN: ${{ github.token }}
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://pypi.org/legacy/
verbose: true
54 changes: 0 additions & 54 deletions .github/workflows/wheels.yml

This file was deleted.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ build-backend = "mesonpy"
requires = ["meson >= 0.61.5", "meson-python >= 0.14.0"]

[project]
name = "watcher"
version = "0.12.0"
name = "wtr-watcher"
version = "0.12.1" # hook: tool/release
authors = [{name = "Will"}]
homepage = "https://github.com/e-dant/watcher"
description = "Filesystem watcher. Works anywhere. Simple, efficient, and friendly."
license.text = "MIT"
readme = "readme.md"
license = {file = "license"}
keywords = ["watcher", "filesystem", "events", "async"]
packages = [{include = "watcher"}]

Expand Down
40 changes: 40 additions & 0 deletions release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release

on:
workflow_run:
workflows: [ "Wheels" ]
branches: [ next ]
types:
- completed
push:
branches: [ next ]

jobs:
a:
name: a
runs-on: ubuntu-latest
steps:
- run: echo ok
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- wheels-apple
- wheels-linux
# if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/wtr-watcher-runner
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- run: |
tool/fetch-release-artifacts --no-zip
mkdir dist
find out/dist -name '*.whl' | while read f
do cp "$f" dist ; echo "$f"
done
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
23 changes: 20 additions & 3 deletions tool/fetch-release-artifacts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#! /usr/bin/env bash
set -e
usage() {
cat <<EOF
Usage: $0 [OPTIONS]
Options:
-h, --help Show this help message and exit
--no-zip Do not zip the artifacts
EOF
}
echo "$@" | grep -q -- --help && usage && exit 0
echo "$@" | grep -q -- -h && usage && exit 0
heredir=$(realpath "$(dirname "$0")/..")
(
[ -d out/dist-unzipped-nested-tmp ] && rm -rf out/dist-unzipped-nested-tmp
Expand All @@ -13,9 +23,16 @@ heredir=$(realpath "$(dirname "$0")/..")
done
(
mkdir dist-tmp
find . -type f | while read f
do zip -r "$f.zip" "$f" && mv "$f.zip" "dist-tmp/$(basename "$f").zip"
done
if echo "$@" | grep -q -- --no-zip
then
find . -type f | while read f
do mv "$f" "dist-tmp/$(basename "$f")"
done
else
find . -type f | while read f
do zip -r "$f.zip" "$f" && mv "$f.zip" "dist-tmp/$(basename "$f").zip"
done
fi
[ -d "$heredir/out/dist" ] && rm -rf "$heredir/out/dist"
[ -d "$heredir/out" ] || mkdir -p "$heredir/out"
mv dist-tmp "$heredir/out/dist"
Expand Down
2 changes: 2 additions & 0 deletions tool/release
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ files-with-versions() {
echo 'CMakeLists.txt
flake.nix
meson.build
pyproject.toml
watcher-py/watcher/watcher.py'
}

Expand All @@ -83,6 +84,7 @@ release::create() {
-E -e "s|( +)([\"']?)([0-9]+\.[0-9]+\.[0-9]+)(.+# hook: tool/release)|\1\2$SEMVER\4|" \
-i -- "$f"
git add "$f"
[ -e "$f--" ] && rm "$f--"
done

git commit -m "release: $SEMVER"
Expand Down
28 changes: 28 additions & 0 deletions tool/show-changelog-for-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
default_version=$(cat "$(dirname "$0")/../.version")
usage() {
cat <<EOF
Usage: $0 [version(= $default_version) | --help, -h]
Example:
For a changelog with the following content:
# A doc
## 0.12.1
text
## 0.12.0
other text
The command:
$ $0 0.12.1
Would display:
text
EOF
}
version=${1:-$default_version}
[ "$1" = "--help" -o "$1" = "-h" ] && { usage ; exit 0; }
changelog="$(dirname "$0")/../changelog.md"
awk \
-v section="## $version" \
'
$0 ~ section { in_section=1; next }
in_section && /^## / && $0 != section { in_section=0 }
in_section { print }' \
"$changelog"

0 comments on commit af5bf41

Please sign in to comment.