Skip to content

Commit 76443b1

Browse files
committed
Added automation
1 parent 5179fbe commit 76443b1

File tree

8 files changed

+447
-0
lines changed

8 files changed

+447
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Package and upload artifacts
2+
description: Package a Python project and upload the artifacts and release notes
3+
inputs:
4+
tag-name:
5+
description: 'The name of the tag for the GitHub release'
6+
required: true
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: Parse changelog for release notes
11+
shell: bash
12+
run: |
13+
function extract_version_content() {
14+
changelog=$1
15+
target_version=$2
16+
17+
awk -v target="$target_version" '
18+
/^## / {
19+
if (found) exit;
20+
version=$2;
21+
if (version == target) found=1;
22+
next;
23+
}
24+
found { print; }
25+
' <<< "$changelog"
26+
}
27+
28+
changelog=$(cat "CHANGELOG.md")
29+
target_version=${{ inputs.tag-name }}
30+
echo "TAG_NAME=$target_version" >> $GITHUB_ENV
31+
content=$(extract_version_content "$changelog" "$target_version")
32+
33+
if [ -n "$content" ]; then
34+
echo "::notice::Found release notes for ${target_version}"
35+
echo "$content" >> release-notes.md
36+
else
37+
echo "::warning::Did not find release notes for ${target_version}"
38+
touch release-notes.md
39+
fi
40+
41+
- name: Upload release notes
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: release-notes
45+
path: release-notes.md
46+
47+
- name: Package and upload artifacts
48+
if: ${{ env.PACKAGE == 'true' }}
49+
uses: hynek/build-and-inspect-python-package@v2
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
description: Create a GitHub release and upload the package to PyPI
3+
inputs:
4+
pypi-api-token:
5+
description: 'PyPI API token'
6+
required: true
7+
tag-name:
8+
description: 'The name of the tag for the GitHub release'
9+
required: true
10+
github-token:
11+
description: 'GitHub token'
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Download packages built by build-and-inspect-python-package
18+
uses: actions/download-artifact@v4
19+
with:
20+
name: Packages
21+
path: dist
22+
23+
- name: Download release notes
24+
uses: actions/download-artifact@v4
25+
with:
26+
name: release-notes
27+
28+
- name: Create a GitHub release
29+
uses: softprops/action-gh-release@v1
30+
with:
31+
files: dist/*
32+
tag_name: "${{ inputs.tag-name }}"
33+
body_path: release-notes.md
34+
token: ${{ inputs.github-token }}
35+
36+
- name: Upload package to PyPI
37+
uses: pypa/gh-action-pypi-publish@release/v1
38+
with:
39+
password: ${{ inputs.pypi-api-token }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: checkout-and-setup-python
2+
description: 'Checkout the repository and setup Python'
3+
inputs:
4+
python-version:
5+
description: 'Python version to use'
6+
required: false
7+
default: '3.11'
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- uses: actions/setup-python@v4
12+
name: Setup Python
13+
with:
14+
python-version: ${{ inputs.python-version }}
15+
cache: 'pip' # caching pip dependencies
16+
17+
- name: Git check
18+
run: |
19+
git config --global user.email "[email protected]"
20+
git config --global user.name "Testing Git"
21+
git --version
22+
git config --list
23+
shell: bash

.github/workflows/docs-final.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Deploy final documentation
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
token: ${{ secrets.PAT }}
18+
19+
- name: Set up Python 3.10
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.10"
23+
24+
- name: Install dependencies
25+
run: |
26+
git pull --all
27+
python -m pip install ".[docs]"
28+
29+
- name: Build and deploy documentation
30+
run: |
31+
mkdocs gh-deploy --strict -v

.github/workflows/docs-preview.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Deploy PR previews
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- closed
10+
11+
concurrency: preview-${{ github.ref }}
12+
13+
jobs:
14+
deploy-preview:
15+
runs-on: ubuntu-20.04
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Python 3.10
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.10"
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install ".[docs]"
30+
31+
- name: Build documentation
32+
run: |
33+
mkdocs build --strict -v
34+
35+
- name: Deploy preview
36+
uses: rossjrw/pr-preview-action@v1
37+
with:
38+
source-dir: ./site/

.github/workflows/test.yaml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
branches: [master]
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
env:
13+
PYTHONUTF8: "1"
14+
15+
jobs:
16+
17+
test:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os:
22+
- ubuntu-latest
23+
- windows-latest
24+
python-version:
25+
- "3.8"
26+
- "3.9"
27+
- "3.10"
28+
- "3.11"
29+
runs-on: ${{ matrix.os }}
30+
steps:
31+
- uses: actions/checkout@v3
32+
- uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
- name: Check git is working
36+
run: |
37+
git config --global user.email "[email protected]"
38+
git config --global user.name "Testing Git"
39+
git --version
40+
git config --list
41+
- name: Check mercurial is working
42+
run: |
43+
echo -e '[ui]\nusername = Testing Mercurial<[email protected]>' > ~/.hgrc
44+
hg --version
45+
- name: Install test dependencies
46+
run: pip install '.[test]'
47+
- name: Test
48+
run: pytest --cov-report=xml
49+
- name: Upload coverage to Codecov
50+
uses: codecov/codecov-action@v3
51+
with:
52+
token: ${{ secrets.CODECOV_TOKEN }}
53+
files: test-reports/coverage.xml
54+
flags: python-${{ matrix.python-version }}
55+
verbose: true # optional (default = false)
56+
env_vars: OS,PYTHON
57+
58+
# Upload to Test PyPI.
59+
release-test-pypi:
60+
name: Publish in-dev package to test.pypi.org
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v3
64+
with:
65+
fetch-depth: 0
66+
token: ${{ secrets.PAT }}
67+
ref: ${{ github.head_ref }}
68+
69+
- uses: actions/setup-python@v4
70+
with:
71+
python-version: '3.11'
72+
cache: 'pip' # caching pip dependencies
73+
74+
- name: Install requirements
75+
shell: bash
76+
run: |
77+
python -m pip install --disable-pip-version-check --no-python-version-warning build
78+
python -m pip install --disable-pip-version-check --no-python-version-warning -e .
79+
80+
- name: Set dev version
81+
shell: bash
82+
run: |
83+
export PR_NUMBER=$(gh pr view --json number -q .number || echo "")
84+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
85+
echo "::notice::PR_NUMBER is: ${PR_NUMBER}"
86+
bump-my-version bump dev bumpversion/__init__.py --no-commit --no-tag --no-configured-files -v
87+
env:
88+
GH_TOKEN: ${{ secrets.PAT }}
89+
90+
- name: Package
91+
shell: bash
92+
run: |
93+
python -m build
94+
95+
- name: Upload package to Test PyPI
96+
uses: pypa/gh-action-pypi-publish@release/v1
97+
with:
98+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
99+
repository-url: https://test.pypi.org/legacy/
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Display the version hint
2+
on:
3+
pull_request:
4+
types: [synchronize, opened, reopened, ready_for_review]
5+
branches: [master]
6+
7+
jobs:
8+
preview-version-hint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
name: Checkout the repository
13+
with:
14+
fetch-depth: 0
15+
ref: ${{ github.event.pull_request.head.sha }}
16+
token: ${{ secrets.PAT }}
17+
18+
- name: Setup Python and Git
19+
uses: ./.github/actions/setup-python-and-git
20+
with:
21+
python-version: '3.11'
22+
23+
- name: Install requirements
24+
run: |
25+
python -m pip install generate-changelog bump-my-version
26+
27+
- name: Get the release hint
28+
id: generate-changelog
29+
run: |
30+
RELEASE_KIND=$(generate-changelog --output release-hint --branch-override ${{ github.base_ref }} --skip-output-pipeline)
31+
echo "::notice::Suggested release type upon merge to ${{ github.base_ref }}: ${RELEASE_KIND}"
32+
echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV
33+
echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT
34+
35+
- name: Get Pull Request Number
36+
id: pr
37+
run: |
38+
PR_NUMBER=$(gh pr view --json number -q .number || echo "${{ github.event.number }}")
39+
echo "pull_request_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
40+
echo "::notice::PR_NUMBER is ${PR_NUMBER}"
41+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.PAT }}
44+
45+
- name: Bump version dry run
46+
if: ${{ env.RELEASE_KIND != 'no-release' }}
47+
shell: bash
48+
run: |
49+
# This will display a full log of what would happen if we were to bump the version.
50+
bump-my-version bump --dry-run --verbose "$RELEASE_KIND"
51+
52+
# This retrieves the current and new version numbers as a JSON-formatted string.
53+
VERSION_INFO=$(bump-my-version show --format json --increment "$RELEASE_KIND" current_version new_version)
54+
echo "CURRENT_VERSION=$(echo $VERSION_INFO | jq -r .current_version)" >> $GITHUB_ENV
55+
echo "NEW_VERSION=$(echo $VERSION_INFO | jq -r .new_version)" >> $GITHUB_ENV
56+
57+
- name: Set no-release information
58+
if: ${{ env.RELEASE_KIND == 'no-release' }}
59+
run: |
60+
echo "CURRENT_VERSION=$(bump-my-version show current_version)" >> $GITHUB_ENV
61+
echo "NEW_VERSION=$(bump-my-version show current_version)" >> $GITHUB_ENV
62+
63+
- name: Display the version hint
64+
uses: s-gehring/singleton-comment@v1
65+
with:
66+
comment-body: |
67+
**Version hint:** ${{ env.RELEASE_KIND }}
68+
**Current version:** ${{ env.CURRENT_VERSION }}
69+
**New version (when merged):** ${{ env.NEW_VERSION }}

0 commit comments

Comments
 (0)