Skip to content

main

main #395

Workflow file for this run

name: main
on:
schedule:
- cron: "0 */4 * * *"
workflow_dispatch:
repository_dispatch:
types: [github_release]
permissions: {}
jobs:
build:
name: main
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write # Required for PyPI trusted publishing
steps:
- if: ${{ startsWith(github.event_name, 'repository_dispatch') }}
run: sleep 30
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: true # needed to push commits below
- name: Install uv
uses: astral-sh/setup-uv@803947b9bd8e9f986429fa0c5a41c367cd732b41 # v7.2.1
- name: set git config
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- run: uv run --no-project mirror.py
- name: check for unpushed commits
id: check_unpushed
run: |
UNPUSHED_COMMITS=$(git log origin/main..HEAD)
if [ -z "$UNPUSHED_COMMITS" ]; then
echo "No unpushed commits found."
echo "changes_exist=false" >> $GITHUB_ENV
else
echo "Unpushed commits found."
echo "changes_exist=true" >> $GITHUB_ENV
fi
- name: Build wheels for all platforms
if: env.changes_exist == 'true'
run: |
# Get version from pyproject.toml
VERSION=$(python3 -c "import tomllib; f=open('pyproject.toml','rb'); print(tomllib.load(f)['project']['version'])")
echo "Building wheels for version $VERSION"
# Build wheels for all platforms
python3 build.py --version "$VERSION" --platform all --output-dir dist
- name: Publish to PyPI
if: env.changes_exist == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
- name: push changes if they exist
if: env.changes_exist == 'true'
run: |
git push origin HEAD:refs/heads/main
git push origin HEAD:refs/heads/main --tags
- name: create release on new tag if new changes exist
if: env.changes_exist == 'true'
run: |
TAG_NAME=$(git describe --tags $(git rev-list --tags --max-count=1))
echo $TAG_NAME
gh release create "$TAG_NAME" \
--title "$TAG_NAME" \
--notes "See: https://github.com/numtide/treefmt/releases/tag/$TAG_NAME" \
--latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}