Skip to content

Daily Release and Publish #76

Daily Release and Publish

Daily Release and Publish #76

Workflow file for this run

name: Daily Release and Publish
on:
schedule:
# Run at 5am PST (13pm UTC) every week
- cron: "0 13 * * *"
workflow_dispatch: # Allow manual triggering
jobs:
release-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write # Required for creating tags
id-token: write # Required for trusted publishing
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for setuptools-scm to work properly
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check for commits since last successful daily release
id: release_guard
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
WORKFLOW_FILE="daily-release.yml"
BRANCH="${{ github.ref_name }}"
: "${BRANCH:=main}"
RESPONSE=$(gh api \
repos/$GITHUB_REPOSITORY/actions/workflows/$WORKFLOW_FILE/runs \
-f status=success \
-f branch="$BRANCH" \
-f per_page=1 2>/dev/null || true)
LAST_SUCCESS_SHA=$(echo "$RESPONSE" | jq -r '.workflow_runs[0].head_sha // ""')
echo "Last successful run commit: ${LAST_SUCCESS_SHA:-none found}"
if [[ -z "$LAST_SUCCESS_SHA" ]]; then
echo "No prior successful runs detected; continuing with release."
echo "should_release=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! git cat-file -e "$LAST_SUCCESS_SHA^{commit}" 2>/dev/null; then
echo "Last successful run commit not present locally; continuing with release."
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "last_success_sha=$LAST_SUCCESS_SHA" >> "$GITHUB_OUTPUT"
exit 0
fi
COMMITS_SINCE=$(git rev-list --count "$LAST_SUCCESS_SHA"..HEAD)
echo "Commits since last successful run: $COMMITS_SINCE"
if [[ "$COMMITS_SINCE" -gt 0 ]]; then
echo "should_release=true" >> "$GITHUB_OUTPUT"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
fi
echo "last_success_sha=$LAST_SUCCESS_SHA" >> "$GITHUB_OUTPUT"
- name: Skip release when no new commits
if: steps.release_guard.outputs.should_release != 'true'
run: echo "No new commits since last successful daily release. Skipping build and publish."
- name: Set up Python
if: steps.release_guard.outputs.should_release == 'true'
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Poetry
if: steps.release_guard.outputs.should_release == 'true'
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Check latest pixie-sdk version
if: steps.release_guard.outputs.should_release == 'true'
id: pixie-version
run: |
LATEST_VERSION=$(curl -s https://pypi.org/pypi/pixie-sdk/json | jq -r '.info.version')
echo "Latest pixie-sdk version: $LATEST_VERSION"
echo "latest=$LATEST_VERSION" >> $GITHUB_OUTPUT
- name: Update pixie-sdk dependency
if: steps.release_guard.outputs.should_release == 'true'
run: |
echo "Updating pixie-sdk to version ${{ steps.pixie-version.outputs.latest }}"
poetry add "pixie-sdk@^${{ steps.pixie-version.outputs.latest }}"
- name: Check for changes and commit
id: changes
if: steps.release_guard.outputs.should_release == 'true'
run: |
if git diff --quiet pyproject.toml; then
echo "No dependency updates needed"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Dependency updates found in pyproject.toml"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: update pixie-sdk to ${{ steps.pixie-version.outputs.latest }}"
git push
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.release_guard.outputs.should_release == 'true'
run: |
poetry install --only main --no-interaction
- name: Generate version with setuptools-scm
id: version
if: steps.release_guard.outputs.should_release == 'true'
run: |
pip install setuptools-scm
VERSION=$(python -m setuptools_scm)
# Strip local version identifier (+g...) for PyPI compatibility
CLEAN_VERSION=$(echo $VERSION | cut -d'+' -f1)
echo "Generated version: $VERSION"
echo "Clean version for PyPI: $CLEAN_VERSION"
echo "version=$CLEAN_VERSION" >> $GITHUB_OUTPUT
echo "full_version=$VERSION" >> $GITHUB_OUTPUT
- name: Update Poetry version
if: steps.release_guard.outputs.should_release == 'true'
run: |
poetry version ${{ steps.version.outputs.version }}
echo "Updated pyproject.toml version to: ${{ steps.version.outputs.version }}"
- name: Build package
if: steps.release_guard.outputs.should_release == 'true'
run: |
poetry build
- name: Publish to PyPI
if: steps.release_guard.outputs.should_release == 'true'
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry publish