diff --git a/.github/actions/build-and-test/action.yaml b/.github/actions/build-and-test/action.yaml new file mode 100644 index 0000000..e87df98 --- /dev/null +++ b/.github/actions/build-and-test/action.yaml @@ -0,0 +1,27 @@ +name: build-and-test +description: | + Set up Python and run the build and test steps. + +runs: + using: composite + steps: + - name: Set up Python + uses: ./.github/actions/setup-python + # TODO: move dependencies to a separate file (e.g. a requirements.txt file) + - name: Install dependencies + shell: bash + run: | + python -m pip install pytest build + - name: Run build + shell: bash + run: python -m build + - name: Show dist files + shell: bash + run: | + echo "Dist files:" + ls -lh dist/ + - name: Run pytest + shell: bash + run: | + python -m pip install -e . + pytest diff --git a/.github/actions/setup-python/action.yaml b/.github/actions/setup-python/action.yaml new file mode 100644 index 0000000..6493106 --- /dev/null +++ b/.github/actions/setup-python/action.yaml @@ -0,0 +1,11 @@ +name: build-and-test +description: | + This action lets the Python version for CI be specified in a single place. + +runs: + using: composite + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml deleted file mode 100644 index b9bf77b..0000000 --- a/.github/release-drafter.yml +++ /dev/null @@ -1,21 +0,0 @@ -name-template: 'v$RESOLVED_VERSION' -tag-template: 'v$RESOLVED_VERSION' -version-resolver: - major: - labels: - - 'major' - minor: - labels: - - 'minor' - patch: - labels: - - 'patch' - default: patch -autolabeler: - - label: 'patch' - files: - - '**/**' -template: | - ## What’s Changed - - $CHANGES diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml new file mode 100644 index 0000000..26eecdf --- /dev/null +++ b/.github/workflows/merge.yaml @@ -0,0 +1,20 @@ +# This workflow builds and tests code that is pushed to the `master` branch. + +name: merge + +on: + push: + branches: + - master + +jobs: + merge: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 + - name: Build and test + uses: ./.github/actions/build-and-test diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..cba9306 --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,17 @@ +# This workflow builds and tests code in pull requests. + +name: pr + +on: pull_request + +jobs: + pr: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 + - name: Build and test + uses: ./.github/actions/build-and-test diff --git a/.github/workflows/pulls.yaml b/.github/workflows/pulls.yaml deleted file mode 100644 index b43f4b8..0000000 --- a/.github/workflows/pulls.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: PR Checks - -on: pull_request - -jobs: - pytest: - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - name: Install dependencies - run: | - python -m pip install -e . - python -m pip install pytest - - name: Run pytest - run: pytest diff --git a/.github/workflows/pypi-upload.yaml b/.github/workflows/pypi-upload.yaml deleted file mode 100644 index d0b6636..0000000 --- a/.github/workflows/pypi-upload.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: pypi-publish - -on: - release: - types: released - -jobs: - build-and-publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.release.tag_name }} - - name: Install pypa/build - run: python -m pip install build - - name: Build wheel & source tarball - run: python -m build --sdist --wheel --outdir dist/ . - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_ADEXT_TOKEN }} diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml deleted file mode 100644 index f228578..0000000 --- a/.github/workflows/release-drafter.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Release Drafter - -on: - push: - branches: - - main - pull_request: - types: - - opened - - reopened - - synchronize - -jobs: - update_release_draft: - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@v6 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..cb40f45 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,48 @@ +# This workflow initiates a release of the project. + +name: release + +on: + workflow_dispatch: + inputs: + version: + description: Release version (e.g. `v0.4.5`) + type: string + required: true + +jobs: + release: + permissions: + # `contents: write` is required to create tags and create releases + # `id-token: write` is required for PyPI attestations + contents: write + id-token: write + runs-on: ubuntu-latest + env: + RELEASE_VERSION: ${{ inputs.version }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 + - name: Create local lightweight tag + run: git tag "${RELEASE_VERSION}" + - name: Build and test + uses: ./.github/actions/build-and-test + - name: Push tag + run: git push origin "${RELEASE_VERSION}" + - name: Create release from tag + env: + GH_TOKEN: ${{ github.token }} + run: | + gh api \ + --method POST \ + "/repos/${GITHUB_REPOSITORY}/releases" \ + -f "tag_name=${RELEASE_VERSION}" \ + -f "name=${RELEASE_VERSION}" \ + -F "draft=false" \ + -F "prerelease=false" \ + -F "generate_release_notes=true" + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1