From 524b5f37cba1875906aab183b380f7ab86bfc0f9 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Sun, 9 Mar 2025 19:33:15 -0400 Subject: [PATCH 1/6] Update GHAs workflows This PR updates the GHA workflows. It mostly matches https://github.com/nutechsoftware/alarmdecoder/pull/79. --- .github/actions/build-and-test/action.yaml | 27 +++++++++++ .github/actions/setup-python/action.yaml | 12 +++++ .github/release-drafter.yml | 21 --------- .github/workflows/merge.yaml | 20 ++++++++ .github/workflows/pr.yaml | 17 +++++++ .github/workflows/pulls.yaml | 16 ------- .github/workflows/pypi-upload.yaml | 22 --------- .github/workflows/release-drafter.yml | 19 -------- .github/workflows/release.yaml | 54 ++++++++++++++++++++++ 9 files changed, 130 insertions(+), 78 deletions(-) create mode 100644 .github/actions/build-and-test/action.yaml create mode 100644 .github/actions/setup-python/action.yaml delete mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/merge.yaml create mode 100644 .github/workflows/pr.yaml delete mode 100644 .github/workflows/pulls.yaml delete mode 100644 .github/workflows/pypi-upload.yaml delete mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/release.yaml diff --git a/.github/actions/build-and-test/action.yaml b/.github/actions/build-and-test/action.yaml new file mode 100644 index 0000000..592ce10 --- /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 mock 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..db5d6b8 --- /dev/null +++ b/.github/actions/setup-python/action.yaml @@ -0,0 +1,12 @@ +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.10" + cache: pip 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..b153601 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,54 @@ +# 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 + +on: pull_request + +jobs: + release: + permissions: + # `contents: write` is required to create tags and create releases + contents: write + runs-on: ubuntu-latest + env: + # RELEASE_VERSION: ${{ inputs.version }} + RELEASE_VERSION: v0.4.5 + 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 + # # TODO: setup attestations and trusted publishing. + # uses: pypa/gh-action-pypi-publish@release/v1 + # with: + # # attestations require trusted publishing which isn't setup yet + # attestations: false + # password: ${{ secrets.PYPI_TOKEN }} From e65cc86f47cd977b4aa61ea616ef2a72d43684b3 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Sun, 9 Mar 2025 19:37:27 -0400 Subject: [PATCH 2/6] rm cache option I think it only supports `requirements.txt` and `pyproject.toml` files --- .github/actions/setup-python/action.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/setup-python/action.yaml b/.github/actions/setup-python/action.yaml index db5d6b8..45f3845 100644 --- a/.github/actions/setup-python/action.yaml +++ b/.github/actions/setup-python/action.yaml @@ -9,4 +9,3 @@ runs: uses: actions/setup-python@v5 with: python-version: "3.10" - cache: pip From d773a93141e6e1fd3656f6869aebbc34bcc46fef Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Sun, 9 Mar 2025 19:50:56 -0400 Subject: [PATCH 3/6] rm unnecessary dependency --- .github/actions/build-and-test/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/build-and-test/action.yaml b/.github/actions/build-and-test/action.yaml index 592ce10..e87df98 100644 --- a/.github/actions/build-and-test/action.yaml +++ b/.github/actions/build-and-test/action.yaml @@ -11,7 +11,7 @@ runs: - name: Install dependencies shell: bash run: | - python -m pip install pytest mock build + python -m pip install pytest build - name: Run build shell: bash run: python -m build From d6bcc30f0b2bddc9582ab5c403cbe6a7a8498ce0 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Sun, 9 Mar 2025 19:51:21 -0400 Subject: [PATCH 4/6] use python `3.12` this was the version being used before these changes --- .github/actions/setup-python/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-python/action.yaml b/.github/actions/setup-python/action.yaml index 45f3845..6493106 100644 --- a/.github/actions/setup-python/action.yaml +++ b/.github/actions/setup-python/action.yaml @@ -8,4 +8,4 @@ runs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.12" From 5159d8cf72c72e88a417ec96e7597a4b11a807db Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Sun, 9 Mar 2025 19:51:53 -0400 Subject: [PATCH 5/6] enable PyPI attestation --- .github/workflows/release.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b153601..67f4e71 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,7 +16,9 @@ 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 }} @@ -46,9 +48,4 @@ jobs: # -F "prerelease=false" \ # -F "generate_release_notes=true" # - name: Publish package distributions to PyPI - # # TODO: setup attestations and trusted publishing. # uses: pypa/gh-action-pypi-publish@release/v1 - # with: - # # attestations require trusted publishing which isn't setup yet - # attestations: false - # password: ${{ secrets.PYPI_TOKEN }} From 727868aafc048e263e2d47865e34ecc0a999d844 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Sun, 9 Mar 2025 19:55:40 -0400 Subject: [PATCH 6/6] revert release testing changes --- .github/workflows/release.yaml | 51 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 67f4e71..cb40f45 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,15 +2,13 @@ name: release -# on: -# workflow_dispatch: -# inputs: -# version: -# description: Release version (e.g. `v0.4.5`) -# type: string -# required: true - -on: pull_request +on: + workflow_dispatch: + inputs: + version: + description: Release version (e.g. `v0.4.5`) + type: string + required: true jobs: release: @@ -21,8 +19,7 @@ jobs: id-token: write runs-on: ubuntu-latest env: - # RELEASE_VERSION: ${{ inputs.version }} - RELEASE_VERSION: v0.4.5 + RELEASE_VERSION: ${{ inputs.version }} steps: - name: Checkout repo uses: actions/checkout@v4 @@ -33,19 +30,19 @@ jobs: 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 + - 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