-
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
44 changed files
with
3,521 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,30 @@ | ||
# https://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[.gitattributes] | ||
indent_size = 16 | ||
|
||
[*.{diff,patch}] | ||
end_of_line = lf | ||
trim_trailing_whitespace = false | ||
|
||
[*.json] | ||
indent_size = 2 | ||
|
||
[*.md] | ||
indent_size = 2 | ||
trim_trailing_whitespace = false | ||
|
||
[*.py] | ||
indent_size = 4 | ||
|
||
[*.yml] | ||
indent_size = 2 |
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,25 @@ | ||
# CAUTION: | ||
# Always run the following command after adding/editing an | ||
# `eol` entry: | ||
# | ||
# git add --renormalize FILES_WITH_AFFECTED_EXTENSION | ||
# | ||
# This keeps existing files consistent with the new setting. | ||
# | ||
# Example: | ||
# | ||
# git add --renormalize '*.foo' '*.bar' | ||
|
||
.editorconfig text eol=lf | ||
.gitattributes text eol=lf | ||
|
||
# LF required for interactive patching as of Git 2.17.1 | ||
*.diff text eol=lf | ||
*.patch text eol=lf | ||
|
||
*.json text eol=lf | ||
*.md text eol=lf | ||
*.py text eol=lf | ||
*.toml text eol=lf | ||
*.txt text eol=lf | ||
*.yml text eol=lf |
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,40 @@ | ||
name: Build package distribution | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
ref: | ||
description: |- | ||
The branch, tag or SHA to checkout. | ||
type: string | ||
required: true | ||
|
||
jobs: | ||
build-dist: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Check out source tree | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
|
||
- name: Use specified Python version | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version-file: .python-version | ||
|
||
- name: Install pypa/build | ||
run: | | ||
python -m pip install --disable-pip-version-check \ | ||
--no-color --no-input --user \ | ||
build | ||
- name: Build wheel and source tarball | ||
run: python -m build | ||
|
||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
if-no-files-found: error |
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,62 @@ | ||
name: Run CI checks | ||
|
||
on: | ||
- push | ||
- workflow_call | ||
|
||
env: | ||
CI_POETRY_VERSION: "1.7.1" | ||
|
||
jobs: | ||
ci-checks: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Check out source tree | ||
uses: actions/checkout@v4 | ||
|
||
- name: Load cached Poetry installation | ||
id: load-cached-poetry | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.local | ||
key: poetry-release-v${{ env.CI_POETRY_VERSION }} | ||
|
||
- name: Update PATH | ||
if: steps.load-cached-poetry.outputs.cache-hit == 'true' | ||
run: | | ||
echo ~/.local/bin >> "${GITHUB_PATH}" | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
if: steps.load-cached-poetry.outputs.cache-hit != 'true' | ||
with: | ||
version: ${{ env.CI_POETRY_VERSION }} | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
|
||
- name: Print current package version | ||
run: poetry version --no-ansi --no-interaction | ||
|
||
- name: Use specified Python version | ||
uses: actions/setup-python@v5 | ||
with: | ||
cache: poetry | ||
python-version-file: .python-version | ||
|
||
- name: Install dependencies | ||
# See also: | ||
# https://github.com/python-poetry/poetry/issues/7184 | ||
run: poetry install --no-ansi --no-interaction --no-root | ||
|
||
- name: Install target package | ||
run: poetry install --no-ansi --no-interaction | ||
|
||
- name: Run static typechecking | ||
run: poetry run poe typecheck | ||
|
||
- name: Run linter | ||
run: poetry run poe linter | ||
|
||
- name: Run man page generator | ||
run: poetry run poe doc |
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,61 @@ | ||
name: PR post-merge | ||
|
||
on: | ||
pull_request_target: | ||
types: [closed] | ||
|
||
jobs: | ||
ci-checks: | ||
if: github.event.pull_request.merged == true | ||
uses: ./.github/workflows/ci.yml | ||
|
||
build-dist: | ||
if: github.event.pull_request.merged == true | ||
needs: ci-checks | ||
uses: ./.github/workflows/build-dist.yml | ||
with: | ||
ref: ${{ github.sha }} | ||
|
||
publish-release: | ||
if: >- | ||
github.event.pull_request.merged == true | ||
&& contains(github.event.pull_request.labels.*.name, 'auto-release') | ||
&& startsWith(github.head_ref, 'release/') | ||
needs: build-dist | ||
runs-on: ubuntu-22.04 | ||
environment: | ||
name: pypi | ||
url: https://pypi.org/p/itchcraft | ||
permissions: | ||
contents: write | ||
id-token: write | ||
steps: | ||
- name: Download the distributions | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
|
||
- name: Publish to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
||
- name: Sign the distributions | ||
uses: sigstore/[email protected] | ||
with: | ||
inputs: >- | ||
dist/*.tar.gz | ||
dist/*.whl | ||
- name: Create draft release | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
RELEASE_BRANCH: ${{ github.head_ref }} | ||
REPOSITORY: ${{ github.repository }} | ||
MERGE_COMMIT: ${{ github.sha }} | ||
run: | | ||
set -ex | ||
VERSION="${RELEASE_BRANCH#release/}" | ||
gh release create "v${VERSION}" --draft --generate-notes \ | ||
--repo "${REPOSITORY}" --target "${MERGE_COMMIT}" | ||
gh release upload "v${VERSION}" dist/* \ | ||
--repo "${REPOSITORY}" |
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,173 @@ | ||
name: Manually run this to prepare a release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
target_version: | ||
description: |- | ||
New version number for the release (or a Poetry bump rule) | ||
required: true | ||
|
||
env: | ||
CI_POETRY_VERSION: "1.7.1" | ||
|
||
jobs: | ||
bump-version: | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
new_version: ${{ steps.gather_new_version.outputs.new_version }} | ||
steps: | ||
- name: Check out source tree | ||
uses: actions/checkout@v4 | ||
|
||
- name: Load cached Poetry installation | ||
id: load-cached-poetry | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.local | ||
key: poetry-release-v${{ env.CI_POETRY_VERSION }} | ||
|
||
- name: Update PATH | ||
if: steps.load-cached-poetry.outputs.cache-hit == 'true' | ||
run: | | ||
echo ~/.local/bin >> "${GITHUB_PATH}" | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
if: steps.load-cached-poetry.outputs.cache-hit != 'true' | ||
with: | ||
version: ${{ env.CI_POETRY_VERSION }} | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
|
||
- name: Print current package version | ||
run: poetry version --no-ansi --no-interaction | ||
|
||
- name: Bump package version | ||
env: | ||
TARGET_VERSION: ${{ inputs.target_version }} | ||
run: poetry version --no-ansi --no-interaction "${TARGET_VERSION}" | ||
|
||
- id: gather_new_version | ||
name: Gather bumped package version | ||
run: | | ||
env -i >> "${GITHUB_OUTPUT}" \ | ||
"new_version=$(poetry version --no-ansi --no-interaction --short)" | ||
- name: Print bumped package version | ||
env: | ||
NEW_VERSION: ${{ steps.gather_new_version.outputs.new_version }} | ||
run: | | ||
echo "New package version: ${NEW_VERSION}" | ||
# Workaround for https://github.com/actions/runner/issues/667 | ||
# See also: | ||
# https://gist.github.com/swinton/03e84635b45c78353b1f71e41007fc7c | ||
- name: Commit bumped package version | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
FILE_TO_COMMIT: pyproject.toml | ||
NEW_VERSION: ${{ steps.gather_new_version.outputs.new_version }} | ||
RELEASE_BRANCH: release/${{ steps.gather_new_version.outputs.new_version }} | ||
run: | | ||
set -ex | ||
MESSAGE="Bump version to ${NEW_VERSION}" | ||
BASE_REF_SHA="$(git rev-parse @)" | ||
OBJECT_SHA=$(git rev-parse ":${FILE_TO_COMMIT}") | ||
gh api --method POST '/repos/:owner/:repo/git/refs' \ | ||
-H 'Accept: application/vnd.github+json' \ | ||
-H 'X-GitHub-Api-Version: 2022-11-28' \ | ||
--field ref="refs/heads/${RELEASE_BRANCH}" \ | ||
--field sha="${BASE_REF_SHA}" | ||
gh api --method PUT "/repos/:owner/:repo/contents/${FILE_TO_COMMIT}" \ | ||
-H 'Accept: application/vnd.github+json' \ | ||
-H 'X-GitHub-Api-Version: 2022-11-28' \ | ||
--field message="${MESSAGE}" \ | ||
--field content=@<(base64 -i "${FILE_TO_COMMIT}") \ | ||
--field branch="${RELEASE_BRANCH}" \ | ||
--field sha="${OBJECT_SHA}" | ||
build-dist: | ||
needs: bump-version | ||
uses: ./.github/workflows/build-dist.yml | ||
with: | ||
ref: release/${{ needs.bump-version.outputs.new_version }} | ||
|
||
publish-testpypi: | ||
needs: build-dist | ||
runs-on: ubuntu-22.04 | ||
environment: | ||
name: testpypi | ||
url: https://test.pypi.org/p/itchcraft | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Download the distributions | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
|
||
- name: Publish to TestPyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
repository-url: https://test.pypi.org/legacy/ | ||
|
||
- name: Sign the distributions | ||
uses: sigstore/[email protected] | ||
with: | ||
inputs: >- | ||
dist/*.tar.gz | ||
dist/*.whl | ||
create-pr: | ||
needs: | ||
- bump-version | ||
- publish-testpypi | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Check out source tree | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: release/${{ needs.bump-version.outputs.new_version }} | ||
|
||
- name: Create pull request | ||
env: | ||
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | ||
GITHUB_TOKEN: ${{ github.token }} | ||
NEW_VERSION: ${{ needs.bump-version.outputs.new_version }} | ||
RELEASE_BRANCH: release/${{ needs.bump-version.outputs.new_version }} | ||
run: | | ||
set -ex | ||
MESSAGE="Prepare v${NEW_VERSION} release" | ||
gh api --method POST '/repos/:owner/:repo/pulls' \ | ||
-H 'Accept: application/vnd.github+json' \ | ||
-H 'X-GitHub-Api-Version: 2022-11-28' \ | ||
--field title="${MESSAGE}" \ | ||
--field head="${RELEASE_BRANCH}" \ | ||
--field base="${DEFAULT_BRANCH}" \ | ||
--field body='Merging this PR will publish a PyPI package'` | ||
`' based on the `'"${RELEASE_BRANCH}"'` branch and'` | ||
`' create a draft release on GitHub.' \ | ||
> "${HOME}/create_pr_response.json" | ||
env -i >> "${GITHUB_ENV}" \ | ||
"PR_NUMBER=$(jq -r '.number' "${HOME}/create_pr_response.json")" | ||
- name: Add label to pull request | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
run: | | ||
set -ex | ||
gh api --method POST \ | ||
-H 'Accept: application/vnd.github+json' \ | ||
-H 'X-GitHub-Api-Version: 2022-11-28' \ | ||
"/repos/:owner/:repo/labels" \ | ||
--field name='auto-release' \ | ||
--field description='Will create tag and release on merge' \ | ||
--field color='7f0000' \ | ||
|| true | ||
gh api --method POST \ | ||
-H 'Accept: application/vnd.github+json' \ | ||
-H 'X-GitHub-Api-Version: 2022-11-28' \ | ||
"/repos/:owner/:repo/issues/${PR_NUMBER}/labels" \ | ||
--field 'labels[]=auto-release' |
Oops, something went wrong.