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/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 index 7e83bc8..cba9306 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,20 +1,17 @@ +# This workflow builds and tests code in pull requests. + name: pr on: pull_request jobs: - pytest: + pr: runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4 - - uses: actions/setup-python@v5 with: - python-version: "3.10" - - name: Install dependencies - # TODO: move test dependencies to a separate file - run: | - python -m pip install -e . - python -m pip install pytest mock - - name: Run pytest - run: pytest + fetch-tags: true + fetch-depth: 0 + - name: Build and test + uses: ./.github/actions/build-and-test diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2d49f05 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,51 @@ +# This workflow initiates a release of the project. + +name: release + +on: + workflow_dispatch: + inputs: + version: + description: Release version (e.g. `1.13.12`) + type: string + required: true + +jobs: + release: + permissions: + # `contents: write` is required to create tags and create releases + contents: 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 + # 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 }} diff --git a/MAINTAINERS.md b/MAINTAINERS.md new file mode 100644 index 0000000..1fe1afc --- /dev/null +++ b/MAINTAINERS.md @@ -0,0 +1,36 @@ +# Maintainers + +This document is intended for maintainers of the `nutechsoftware/alarmdecoder` repository. + +It summarizes information about the automated processes involved with the repository. + +## GitHub Actions Automation + +This section describes how GitHub Actions is used to automate test and release processes for the `nutechsoftware/alarmdecoder` repository. GitHub Actions is free for public repositories. More information about GitHub Actions can be found on their official documentation site here: https://docs.github.com/en/actions. + +### Reusable Actions + +The GitHub Actions workflows described below make use of [composite actions](https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action) to help consolidate common workflow steps. + +These actions are found in the [.github/actions](./.github/actions) directory. Each action has a `description` field at the top of the file that describes its purpose. + +### Workflows + +The GitHub Actions workflows can be found in the [.github/workflows](./.github/workflows) directory. Each workflow has a comment at the top of the file that describes its purpose. + +The sections below further delineate between automated and manual workflows that are in use. More information on triggering workflows (both automatically and manually) can be found here: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/triggering-a-workflow. + +#### Automated Workflows + +Some workflows are configured to run automatically based on certain GitHub events. Examples of these workflows are listed below: + +- `pr.yaml` - runs in response to pull requests being opened +- `merge.yaml` - runs anytime a change is pushed to the `master` branch (i.e. when a PR is merged) + +#### Manual Workflows + +Some workflows are configured to run based on a manual invocation from a maintainer. Examples of these workflows are listed below: + +- `release.yaml` - runs a workflow to build, test, and release the `alarmdecoder` Python packages to PyPI + +More information on manually triggering GitHub Actions workflows can be found here: https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow. diff --git a/setup.py b/setup.py index 2ce5995..20f058c 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,10 @@ def readme(): extra_requirements.append('future>=0.14.3') setup(name='alarmdecoder', - version='1.13.12', + setuptools_git_versioning={ + "enabled": True, + }, + setup_requires=["setuptools-git-versioning>=2.0,<3"], description='Python interface for the AlarmDecoder (AD2) family ' 'of alarm devices which includes the AD2USB, AD2SERIAL and AD2PI.', long_description=readme(),