Skip to content

Commit ac66ae5

Browse files
authored
Add automated workflows (#79)
* commit initial workflows * get `setup.py` version from `git` * fix shared action extensions * fix action paths/names * run build/test action before release * set `fetch_tags: true` on `actions/checkout` * set `fetch_depth: 0` to get all tag history * revert testing changes for `release.yaml` * Revert "fix shared action extensions" This reverts commit 78235c1. * add docs * minor doc updates
1 parent 293eed3 commit ac66ae5

7 files changed

Lines changed: 157 additions & 11 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: build-and-test
2+
description: |
3+
Set up Python and run the build and test steps.
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Set up Python
9+
uses: ./.github/actions/setup-python
10+
# TODO: move dependencies to a separate file (e.g. a requirements.txt file)
11+
- name: Install dependencies
12+
shell: bash
13+
run: |
14+
python -m pip install pytest mock build
15+
- name: Run build
16+
shell: bash
17+
run: python -m build
18+
- name: Show dist files
19+
shell: bash
20+
run: |
21+
echo "Dist files:"
22+
ls -lh dist/
23+
- name: Run pytest
24+
shell: bash
25+
run: |
26+
python -m pip install -e .
27+
pytest
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: build-and-test
2+
description: |
3+
This action lets the Python version for CI be specified in a single place.
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- name: Set up Python
9+
uses: actions/setup-python@v5
10+
with:
11+
python-version: "3.10"
12+
cache: pip

.github/workflows/merge.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This workflow builds and tests code that is pushed to the `master` branch.
2+
3+
name: merge
4+
5+
on:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
merge:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-tags: true
18+
fetch-depth: 0
19+
- name: Build and test
20+
uses: ./.github/actions/build-and-test

.github/workflows/pr.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
# This workflow builds and tests code in pull requests.
2+
13
name: pr
24

35
on: pull_request
46

57
jobs:
6-
pytest:
8+
pr:
79
runs-on: ubuntu-latest
810
steps:
911
- name: Checkout repo
1012
uses: actions/checkout@v4
11-
- uses: actions/setup-python@v5
1213
with:
13-
python-version: "3.10"
14-
- name: Install dependencies
15-
# TODO: move test dependencies to a separate file
16-
run: |
17-
python -m pip install -e .
18-
python -m pip install pytest mock
19-
- name: Run pytest
20-
run: pytest
14+
fetch-tags: true
15+
fetch-depth: 0
16+
- name: Build and test
17+
uses: ./.github/actions/build-and-test

.github/workflows/release.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This workflow initiates a release of the project.
2+
3+
name: release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: Release version (e.g. `1.13.12`)
10+
type: string
11+
required: true
12+
13+
jobs:
14+
release:
15+
permissions:
16+
# `contents: write` is required to create tags and create releases
17+
contents: write
18+
runs-on: ubuntu-latest
19+
env:
20+
RELEASE_VERSION: ${{ inputs.version }}
21+
steps:
22+
- name: Checkout repo
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-tags: true
26+
fetch-depth: 0
27+
- name: Create local lightweight tag
28+
run: git tag "${RELEASE_VERSION}"
29+
- name: Build and test
30+
uses: ./.github/actions/build-and-test
31+
- name: Push tag
32+
run: git push origin "${RELEASE_VERSION}"
33+
- name: Create release from tag
34+
env:
35+
GH_TOKEN: ${{ github.token }}
36+
run: |
37+
gh api \
38+
--method POST \
39+
"/repos/${GITHUB_REPOSITORY}/releases" \
40+
-f "tag_name=${RELEASE_VERSION}" \
41+
-f "name=${RELEASE_VERSION}" \
42+
-F "draft=false" \
43+
-F "prerelease=false" \
44+
-F "generate_release_notes=true"
45+
- name: Publish package distributions to PyPI
46+
# TODO: setup attestations and trusted publishing.
47+
uses: pypa/gh-action-pypi-publish@release/v1
48+
with:
49+
# attestations require trusted publishing which isn't setup yet
50+
attestations: false
51+
password: ${{ secrets.PYPI_TOKEN }}

MAINTAINERS.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Maintainers
2+
3+
This document is intended for maintainers of the `nutechsoftware/alarmdecoder` repository.
4+
5+
It summarizes information about the automated processes involved with the repository.
6+
7+
## GitHub Actions Automation
8+
9+
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.
10+
11+
### Reusable Actions
12+
13+
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.
14+
15+
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.
16+
17+
### Workflows
18+
19+
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.
20+
21+
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.
22+
23+
#### Automated Workflows
24+
25+
Some workflows are configured to run automatically based on certain GitHub events. Examples of these workflows are listed below:
26+
27+
- `pr.yaml` - runs in response to pull requests being opened
28+
- `merge.yaml` - runs anytime a change is pushed to the `master` branch (i.e. when a PR is merged)
29+
30+
#### Manual Workflows
31+
32+
Some workflows are configured to run based on a manual invocation from a maintainer. Examples of these workflows are listed below:
33+
34+
- `release.yaml` - runs a workflow to build, test, and release the `alarmdecoder` Python packages to PyPI
35+
36+
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.

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ def readme():
1414
extra_requirements.append('future>=0.14.3')
1515

1616
setup(name='alarmdecoder',
17-
version='1.13.12',
17+
setuptools_git_versioning={
18+
"enabled": True,
19+
},
20+
setup_requires=["setuptools-git-versioning>=2.0,<3"],
1821
description='Python interface for the AlarmDecoder (AD2) family '
1922
'of alarm devices which includes the AD2USB, AD2SERIAL and AD2PI.',
2023
long_description=readme(),

0 commit comments

Comments
 (0)