diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fd1b287..8282d8b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,10 @@ name: sleepKIT CI -on: [push] +on: + push: + branches: + - main + pull_request: env: PYTHON_VERSION: '3.12' diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 7c77992..3624cd0 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -1,10 +1,18 @@ name: Deploy to GitHub Pages on: - release: - types: - - created + workflow_call: + inputs: + ref: + description: Git ref (branch, tag, or SHA) to publish from + required: false + type: string workflow_dispatch: + inputs: + ref: + description: Git ref (branch, tag, or SHA) to publish from + required: false + type: string permissions: contents: read @@ -28,6 +36,8 @@ jobs: steps: - name: Checkout 🛎️ uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref || github.ref }} - name: Setup Pages id: pages uses: actions/configure-pages@v4 diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml new file mode 100644 index 0000000..89c9d71 --- /dev/null +++ b/.github/workflows/pypi.yaml @@ -0,0 +1,58 @@ +name: Publish to PyPI + +on: + workflow_call: + inputs: + ref: + description: Git ref (branch, tag, or SHA) to publish from + required: false + type: string + workflow_dispatch: + inputs: + ref: + description: Git ref (branch, tag, or SHA) to publish from + required: false + type: string + +env: + PACKAGE_NAME: sleepkit + PYTHON_VERSION: '3.12' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref || github.ref }} + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + enable-cache: true + - name: Install and Build 🔧 + run: | + uv build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + + publish: + runs-on: ubuntu-latest + needs: + - build + environment: + name: pypi + url: https://pypi.org/p/${{ env.PACKAGE_NAME }} + permissions: + id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish to PyPI 📦 + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/release-please-lock.yaml b/.github/workflows/release-please-lock.yaml deleted file mode 100644 index 11bc4fe..0000000 --- a/.github/workflows/release-please-lock.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Sync uv.lock for release PRs - -on: - pull_request: - types: - - opened - - synchronize - - ready_for_review - - reopened - -jobs: - update-uv-lock: - if: startsWith(github.head_ref, 'release-please--') - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Checkout release PR branch - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - name: Install uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Regenerate uv.lock - run: uv lock - - name: Commit updated lockfile - if: ${{ !cancelled() }} - run: | - if git diff --quiet -- uv.lock; then - echo "uv.lock already up to date." - exit 0 - fi - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add uv.lock - git commit -m "chore: sync uv.lock after version bump" - git push diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml deleted file mode 100644 index 505d376..0000000 --- a/.github/workflows/release-please.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Release Please - -on: - push: - branches: - - main - workflow_dispatch: - -jobs: - release-please: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - issues: write - steps: - - uses: googleapis/release-please-action@v4 - with: - config-file: release-please-config.json - manifest-file: .release-please-manifest.json diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4820043..7a00dcd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,51 +1,84 @@ -name: Release to PyPi +name: Release Please on: - release: - types: - - created push: - tags: - - "v*" + branches: + - main + pull_request: + types: + - opened + - synchronize + - ready_for_review + - reopened workflow_dispatch: -env: - PACKAGE_NAME: sleepkit - PYTHON_VERSION: '3.12' - jobs: - build: + release-please: + if: github.event_name != 'pull_request' runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.release_created }} + releases_created: ${{ steps.release.outputs.releases_created }} + tag_name: ${{ steps.release.outputs.tag_name }} + permissions: + contents: write + pull-requests: write + issues: write + steps: + - id: release + uses: googleapis/release-please-action@v4 + with: + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + + update-uv-lock: + if: github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-please--') + runs-on: ubuntu-latest + permissions: + contents: write steps: - - name: Checkout 🛎️ + - name: Checkout release PR branch uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} - name: Install uv uses: astral-sh/setup-uv@v5 with: - enable-cache: true - - name: Install and Build 🔧 + enable-cache: true + - name: Regenerate uv.lock + run: uv lock + - name: Commit updated lockfile + if: ${{ !cancelled() }} run: | - uv build - - name: Store the distribution packages - uses: actions/upload-artifact@v4 - with: - name: python-package-distributions - path: dist/ + if git diff --quiet -- uv.lock; then + echo "uv.lock already up to date." + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add uv.lock + git commit -m "chore: sync uv.lock after version bump" + git push - publish: - runs-on: ubuntu-latest - needs: - - build - environment: - name: pypi - url: https://pypi.org/p/${{ env.PACKAGE_NAME }} + publish-pypi: + needs: release-please + if: needs.release-please.outputs.releases_created == 'true' || needs.release-please.outputs.release_created == 'true' permissions: + contents: read id-token: write - steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: python-package-distributions - path: dist/ - - name: Publish to PyPI 📦 - uses: pypa/gh-action-pypi-publish@release/v1 + uses: ./.github/workflows/pypi.yaml + with: + ref: ${{ needs.release-please.outputs.tag_name }} + secrets: inherit + + publish-docs: + needs: release-please + if: needs.release-please.outputs.releases_created == 'true' || needs.release-please.outputs.release_created == 'true' + permissions: + contents: read + pages: write + id-token: write + uses: ./.github/workflows/docs.yaml + with: + ref: ${{ needs.release-please.outputs.tag_name }} + secrets: inherit