-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Package and upload artifacts | ||
description: Package a Python project and upload the artifacts and release notes | ||
inputs: | ||
tag-name: | ||
description: 'The name of the tag for the GitHub release' | ||
required: true | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Parse changelog for release notes | ||
shell: bash | ||
run: | | ||
function extract_version_content() { | ||
changelog=$1 | ||
target_version=$2 | ||
awk -v target="$target_version" ' | ||
/^## / { | ||
if (found) exit; | ||
version=$2; | ||
if (version == target) found=1; | ||
next; | ||
} | ||
found { print; } | ||
' <<< "$changelog" | ||
} | ||
changelog=$(cat "CHANGELOG.md") | ||
target_version=${{ inputs.tag-name }} | ||
echo "TAG_NAME=$target_version" >> $GITHUB_ENV | ||
content=$(extract_version_content "$changelog" "$target_version") | ||
if [ -n "$content" ]; then | ||
echo "::notice::Found release notes for ${target_version}" | ||
echo "$content" >> release-notes.md | ||
else | ||
echo "::warning::Did not find release notes for ${target_version}" | ||
touch release-notes.md | ||
fi | ||
- name: Upload release notes | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: release-notes | ||
path: release-notes.md | ||
|
||
- name: Package and upload artifacts | ||
if: ${{ env.PACKAGE == 'true' }} | ||
uses: hynek/build-and-inspect-python-package@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Release | ||
description: Create a GitHub release and upload the package to PyPI | ||
inputs: | ||
pypi-api-token: | ||
description: 'PyPI API token' | ||
required: true | ||
tag-name: | ||
description: 'The name of the tag for the GitHub release' | ||
required: true | ||
github-token: | ||
description: 'GitHub token' | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Download packages built by build-and-inspect-python-package | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: Packages | ||
path: dist | ||
|
||
- name: Download release notes | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: release-notes | ||
|
||
- name: Create a GitHub release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: dist/* | ||
tag_name: "${{ inputs.tag-name }}" | ||
body_path: release-notes.md | ||
token: ${{ inputs.github-token }} | ||
|
||
- name: Upload package to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ inputs.pypi-api-token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: checkout-and-setup-python | ||
description: 'Checkout the repository and setup Python' | ||
inputs: | ||
python-version: | ||
description: 'Python version to use' | ||
required: false | ||
default: '3.11' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/setup-python@v4 | ||
name: Setup Python | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
cache: 'pip' # caching pip dependencies | ||
|
||
- name: Git check | ||
run: | | ||
git config --global user.email "bump-my-version@github.actions" | ||
git config --global user.name "Testing Git" | ||
git --version | ||
git config --list | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Deploy final documentation | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.PAT }} | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install dependencies | ||
run: | | ||
git pull --all | ||
python -m pip install ".[docs]" | ||
- name: Build and deploy documentation | ||
run: | | ||
mkdocs gh-deploy --strict -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Deploy PR previews | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- closed | ||
|
||
concurrency: preview-${{ github.ref }} | ||
|
||
jobs: | ||
deploy-preview: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install ".[docs]" | ||
- name: Build documentation | ||
run: | | ||
mkdocs build --strict -v | ||
- name: Deploy preview | ||
uses: rossjrw/pr-preview-action@v1 | ||
with: | ||
source-dir: ./site/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
branches: [master] | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
env: | ||
PYTHONUTF8: "1" | ||
|
||
jobs: | ||
|
||
test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- windows-latest | ||
python-version: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Check git is working | ||
run: | | ||
git config --global user.email "bumpversion-test-git@github.actions" | ||
git config --global user.name "Testing Git" | ||
git --version | ||
git config --list | ||
- name: Check mercurial is working | ||
run: | | ||
echo -e '[ui]\nusername = Testing Mercurial<bumpversion-test-hg@github.actions>' > ~/.hgrc | ||
hg --version | ||
- name: Install test dependencies | ||
run: pip install '.[test]' | ||
- name: Test | ||
run: pytest --cov-report=xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: test-reports/coverage.xml | ||
flags: python-${{ matrix.python-version }} | ||
verbose: true # optional (default = false) | ||
env_vars: OS,PYTHON | ||
|
||
# Upload to Test PyPI. | ||
release-test-pypi: | ||
name: Publish in-dev package to test.pypi.org | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.PAT }} | ||
ref: ${{ github.head_ref }} | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
cache: 'pip' # caching pip dependencies | ||
|
||
- name: Install requirements | ||
shell: bash | ||
run: | | ||
python -m pip install --disable-pip-version-check --no-python-version-warning build | ||
python -m pip install --disable-pip-version-check --no-python-version-warning -e . | ||
- name: Set dev version | ||
shell: bash | ||
run: | | ||
export PR_NUMBER=$(gh pr view --json number -q .number || echo "") | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | ||
echo "::notice::PR_NUMBER is: ${PR_NUMBER}" | ||
bump-my-version bump dev bumpversion/__init__.py --no-commit --no-tag --no-configured-files -v | ||
env: | ||
GH_TOKEN: ${{ secrets.PAT }} | ||
|
||
- name: Package | ||
shell: bash | ||
run: | | ||
python -m build | ||
- name: Upload package to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
repository-url: https://test.pypi.org/legacy/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Display the version hint | ||
on: | ||
pull_request: | ||
types: [synchronize, opened, reopened, ready_for_review] | ||
branches: [master] | ||
|
||
jobs: | ||
preview-version-hint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
name: Checkout the repository | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
token: ${{ secrets.PAT }} | ||
|
||
- name: Setup Python and Git | ||
uses: ./.github/actions/setup-python-and-git | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install requirements | ||
run: | | ||
python -m pip install generate-changelog bump-my-version | ||
- name: Get the release hint | ||
id: generate-changelog | ||
run: | | ||
RELEASE_KIND=$(generate-changelog --output release-hint --branch-override ${{ github.base_ref }} --skip-output-pipeline) | ||
echo "::notice::Suggested release type upon merge to ${{ github.base_ref }}: ${RELEASE_KIND}" | ||
echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV | ||
echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT | ||
- name: Get Pull Request Number | ||
id: pr | ||
run: | | ||
PR_NUMBER=$(gh pr view --json number -q .number || echo "${{ github.event.number }}") | ||
echo "pull_request_number=${PR_NUMBER}" >> $GITHUB_OUTPUT | ||
echo "::notice::PR_NUMBER is ${PR_NUMBER}" | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT }} | ||
|
||
- name: Bump version dry run | ||
if: ${{ env.RELEASE_KIND != 'no-release' }} | ||
shell: bash | ||
run: | | ||
# This will display a full log of what would happen if we were to bump the version. | ||
bump-my-version bump --dry-run --verbose "$RELEASE_KIND" | ||
# This retrieves the current and new version numbers as a JSON-formatted string. | ||
VERSION_INFO=$(bump-my-version show --format json --increment "$RELEASE_KIND" current_version new_version) | ||
echo "CURRENT_VERSION=$(echo $VERSION_INFO | jq -r .current_version)" >> $GITHUB_ENV | ||
echo "NEW_VERSION=$(echo $VERSION_INFO | jq -r .new_version)" >> $GITHUB_ENV | ||
- name: Set no-release information | ||
if: ${{ env.RELEASE_KIND == 'no-release' }} | ||
run: | | ||
echo "CURRENT_VERSION=$(bump-my-version show current_version)" >> $GITHUB_ENV | ||
echo "NEW_VERSION=$(bump-my-version show current_version)" >> $GITHUB_ENV | ||
- name: Display the version hint | ||
uses: s-gehring/singleton-comment@v1 | ||
with: | ||
comment-body: | | ||
**Version hint:** ${{ env.RELEASE_KIND }} | ||
**Current version:** ${{ env.CURRENT_VERSION }} | ||
**New version (when merged):** ${{ env.NEW_VERSION }} |
Oops, something went wrong.