From a9951dcfa10107ed391523bcac62c59077164c9a Mon Sep 17 00:00:00 2001 From: Samuel Searles-Bryant Date: Wed, 10 Jul 2024 17:29:14 +0100 Subject: [PATCH] Extend build workflow to publish the package This includes a simple set of checks to ensure the tag matches the version of the package and is mentioned in the changelog. --- .github/workflows/build.yaml | 18 -------- .github/workflows/build_and_publish.yaml | 58 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 18 deletions(-) delete mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/build_and_publish.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 42b6bb8..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: build - -on: - pull_request: - -# Only allow one instance of this workflow for each PR. -concurrency: - group: ${{ github.workflow }}-${{ github.ref_name }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-24.04 - timeout-minutes: 5 - - steps: - - uses: actions/checkout@v4 - - uses: hynek/build-and-inspect-python-package@v2 diff --git a/.github/workflows/build_and_publish.yaml b/.github/workflows/build_and_publish.yaml new file mode 100644 index 0000000..397994c --- /dev/null +++ b/.github/workflows/build_and_publish.yaml @@ -0,0 +1,58 @@ +name: build and publish + +on: + pull_request: + push: + tags: + - v* + +# Only allow one instance of this workflow for each PR. +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v4 + - uses: hynek/build-and-inspect-python-package@v2 + + verify: + runs-on: ubuntu-24.04 + # if: github.repository_owner == 'kraken-tech' && github.ref_type == 'tag' + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version-file: '.github/workflows/.python-version' + cache: 'pip' + - run: python -m pip install . + - id: package_version + run: echo "version=$(python -c "from importlib.metadata import version; print(version('datetime-tools'))")" >> $GITHUB_OUTPUT + - name: check package version matches tag + run: | + [ "v{{ steps.package_version.outputs.version }}" = "{{ github.ref_name }}"] + - name: check changelog includes version + run: grep {{ github.ref_name }} < CHANGELOG.md + + publish: + environment: publish + if: github.repository_owner == 'kraken-tech' && github.ref_type == 'tag' + needs: [build, verify] + runs-on: ubuntu-24.04 + timeout-minutes: 5 + + permissions: + id-token: write + + steps: + - uses: actions/download-artifact@v4 + with: + name: Packages + path: dist + - uses: pypa/gh-action-pypi-publish@release/v1