Skip to content

Commit

Permalink
Use invoke as library (#25)
Browse files Browse the repository at this point in the history
Make a proper package.
This is to be able to properly distribute the invoke tasks.
For more information on this, see
https://docs.pyinvoke.org/en/stable/concepts/library.html

Put everything in a single pyprojects.toml file and use flit
for building.
Remove all unnecessary files related to this change.
Update dependabot config (removing updating the requirements*.txt).

Use git to determine repo root for hooks.

Check hook config directly for this repo, when updating pre-commit
hooks in the 'CI - Update dependencies PR' workflow.
Use `--freeze` option specifically for this repository when updating it
in the pre-commit config file for the update dependencies workflow.

Remove python code section from documentation.
  • Loading branch information
CasperWA authored Jul 6, 2022
1 parent 07b0fdc commit 1b5dce8
Show file tree
Hide file tree
Showing 21 changed files with 194 additions and 156 deletions.
10 changes: 0 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,3 @@ updates:
target-branch: ci/dependency-updates
labels:
- CI/CD
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "05:18"
# Should be bigger than or equal to the total number of dependencies (currently 2+2)
open-pull-requests-limit: 10
target-branch: ci/dependency-updates
labels:
- CI/CD
1 change: 1 addition & 0 deletions .github/workflows/_local_ci_cd_updated_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ jobs:
update_python_api_ref: false
update_docs_landing_page: false
changelog_exclude_tags_regex: "^v[0-9]+$"
test: false
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
21 changes: 21 additions & 0 deletions .github/workflows/_local_ci_check_pyproject_dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI - Check dependencies PR

on:
schedule:
# At 7:30 every Monday (5:30 UTC)
- cron: "30 5 * * 1"
workflow_dispatch:

jobs:
update-pyproject-dependencies:
name: Call reusable workflow
if: github.repository_owner == 'CasperWA'
uses: ./.github/workflows/ci_check_pyproject_dependencies.yml
with:
git_username: "Casper Welzel Andersen"
git_email: "casper+github@welzel.nu"
permanent_dependencies_branch: "ci/dependency-updates"
install_extras: "[dev,docs]"
pr_labels: "CI/CD"
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
35 changes: 9 additions & 26 deletions .github/workflows/cd_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
path: main

- name: Checkout CasperWA/ci-cd
uses: actions/checkout@v3
with:
repository: CasperWA/ci-cd
ref: main
path: ci-cd

- name: Set up Python ${{ inputs.python_version }}
uses: actions/setup-python@v4
Expand All @@ -115,8 +107,8 @@ jobs:
run: |
python -m pip install -U pip
pip install -U setuptools wheel build
pip install ./main${{ inputs.install_extras }}
pip install -r ./ci-cd/requirements.txt
pip install .${{ inputs.install_extras }}
pip install git+https://github.com/CasperWA/ci-cd.git@v1
- name: Update changelog
uses: CharMixer/auto-changelog-action@v1
Expand All @@ -125,7 +117,6 @@ jobs:
release_branch: ${{ inputs.release_branch }}
exclude_tags_regex: "${{ inputs.changelog_exclude_tags_regex }}"
exclude_labels: "${{ inputs.changelog_exclude_labels }}"
output: "main/CHANGELOG.md"

- name: Set up git user
run: |
Expand All @@ -142,37 +133,33 @@ jobs:
echo "package_dir MUST be supplied, since python_package was set to 'true'."
exit 1
fi
invoke setver --version="${REF}" --repo-folder=main --package-dir=${{ inputs.package_dir }}
ci-cd setver --version="${REF}" --root-repo-path="${PWD}" --package-dir=${{ inputs.package_dir }}
fi
MAIN_DIR="${{ github.workspace }}/main"
git -C ${MAIN_DIR} commit -am "Release ${REF} - Changelog"
git commit -am "Release ${REF} - Changelog"
if [ -z "${{ inputs.tag_message_file }}" ] || [ ! -f "main/${{ inputs.tag_message_file }}" ]; then
TAG_MSG_FILE=${{ github.workspace }}/.tmp_tag-msg_${{ github.run_id }}_${{ github.run_number }}_${{ github.run_attempt }}.txt
if [ -z "${{ inputs.tag_message_file }}" ] || [ ! -f "${{ inputs.tag_message_file }}" ]; then
TAG_MSG_FILE=.tmp_tag-msg_${{ github.run_id }}_${{ github.run_number }}_${{ github.run_attempt }}.txt
echo -e "TAG_NAME\n\nThe full release changelog can be seen in the\n[repository source file](https://github.com/${{ github.repository }}/blob/TAG_NAME/CHANGELOG.md)." > ${TAG_MSG_FILE}
echo "Using default release tag message."
REMOVE_TAG_MSG_FILE=true
else
echo "Using found release tag message text file at ${{ inputs.tag_message_file }}."
TAG_MSG_FILE=main/${{ inputs.tag_message_file }}
TAG_MSG_FILE=${{ inputs.tag_message_file }}
REMOVE_TAG_MSG_FILE=false
fi
sed -i "s|TAG_NAME|${REF}|" "${TAG_MSG_FILE}"
git -C ${MAIN_DIR} tag -af -F "${TAG_MSG_FILE}" ${REF}
git tag -af -F "${TAG_MSG_FILE}" ${REF}
if [ "${REMOVE_TAG_MSG_FILE}" == "true" ]; then rm -f "${TAG_MSG_FILE}"; fi
working-directory: ./ci-cd
- name: Build source distribution
run: |
# First, clean the git tree
git checkout -- .
${{ inputs.build_cmd }}
working-directory: ./main
- name: Update '${{ inputs.release_branch }}'
uses: CasperWA/push-protected@v2
Expand All @@ -184,7 +171,6 @@ jobs:
tags: true
unprotect_reviews: true
debug: ${{ inputs.test }}
path: main

- name: Get tagged versions
run: |
Expand All @@ -193,7 +179,6 @@ jobs:
else
echo "PREVIOUS_VERSION=$(git tag -l --sort -version:refname | sed -n 2p)" >> $GITHUB_ENV
fi
working-directory: ./main
- name: Create release-specific changelog
uses: CharMixer/auto-changelog-action@v1
Expand All @@ -219,7 +204,6 @@ jobs:
with:
user: __token__
password: ${{ secrets.PyPI_token }}
packages_dir: main/dist/
repository_url: https://test.pypi.org/legacy/

- name: Publish package to PyPI
Expand All @@ -228,7 +212,6 @@ jobs:
with:
user: __token__
password: ${{ secrets.PyPI_token }}
packages_dir: main/dist/

docs:
name: Deploy release documentation
Expand All @@ -252,7 +235,7 @@ jobs:
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install -e .${{ inputs.doc_extras || inputs.install_extras }}
pip install .${{ inputs.doc_extras || inputs.install_extras }}
- name: Set up git user
run: |
Expand Down
30 changes: 7 additions & 23 deletions .github/workflows/ci_cd_updated_default_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
path: main

- name: Checkout CasperWA/ci-cd
if: env.RELEASE_RUN == 'false'
uses: actions/checkout@v3
with:
repository: CasperWA/ci-cd
ref: main
path: ci-cd

- name: Set up Python ${{ inputs.python_version }}
if: env.RELEASE_RUN == 'false'
Expand All @@ -154,8 +145,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install ./main${{ inputs.doc_extras }}
pip install -r ./ci-cd/requirements.txt
pip install .${{ inputs.doc_extras }}
pip install git+https://github.com/CasperWA/ci-cd.git@v1
- name: Set up git user
if: env.RELEASE_RUN == 'false'
Expand All @@ -166,7 +157,6 @@ jobs:
- name: Clean working tree
if: env.RELEASE_RUN == 'false'
run: git checkout -- .
working-directory: ./main

- name: Update API Reference
if: env.RELEASE_RUN == 'false' && inputs.update_python_api_ref
Expand All @@ -182,14 +172,13 @@ jobs:
DEBUG=
fi
invoke create-api-reference-docs ${DEBUG} \
ci-cd create-api-reference-docs ${DEBUG} \
--pre-clean \
--repo-folder=main \
--root-repo-path=${PWD} \
--package-dir="${{ inputs.package_dir }}" \
--unwanted-dirs="${{ inputs.exclude_dirs }}" \
--unwanted-files="${{ inputs.exclude_files }}" \
--full-docs-dirs="${{ inputs.full_docs_dirs }}"
working-directory: ./ci-cd
- name: Update landing page
if: env.RELEASE_RUN == 'false' && inputs.update_docs_landing_page
Expand All @@ -201,12 +190,11 @@ jobs:
LANDING_PAGE_REPLACEMENTS="${LANDING_PAGE_REPLACEMENTS/,/${{ inputs.landing_page_replacements_mapping_separator }}}"
fi
invoke create-docs-index \
--repo-folder=main \
ci-cd create-docs-index \
--root-repo-path=${PWD} \
--replacements="${LANDING_PAGE_REPLACEMENTS}" \
--replacements-separator="${{ inputs.landing_page_replacements_separator }}" \
--internal-separator="${{ inputs.landing_page_replacements_mapping_separator }}"
working-directory: ./ci-cd
- name: Determine if documentation was updated
if: env.RELEASE_RUN == 'false'
Expand All @@ -229,7 +217,6 @@ jobs:
echo -e "\u2714 All good !"
echo "UPDATE_DEFAULT_BRANCH=false" >> $GITHUB_ENV
fi
working-directory: ./main
- name: Update '${{ inputs.default_repo_branch }}'
if: env.RELEASE_RUN == 'false' && env.UPDATE_DEFAULT_BRANCH == 'true' && ( ! inputs.test )
Expand All @@ -241,7 +228,6 @@ jobs:
force: true
tags: true
unprotect_reviews: true
path: main

# Note: This updated changelog will only exist for the `latest` documentation
# release.
Expand All @@ -253,13 +239,11 @@ jobs:
release_branch: ${{ inputs.default_repo_branch }}
exclude_tags_regex: "${{ inputs.changelog_exclude_tags_regex }}"
exclude_labels: "${{ inputs.changelog_exclude_labels }}"
output: "main/CHANGELOG.md"
future_release: "Unreleased changes"

- name: Deploy documentation
if: env.RELEASE_RUN == 'false' && ( ! inputs.test )
run: mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ inputs.default_repo_branch }}
working-directory: ./main

update-dependencies-branch:
name: Update permanent dependencies branch
Expand All @@ -281,7 +265,7 @@ jobs:
- name: Get PR body
run: |
if [ -z "${{ inputs.update_dependencies_pr_body_file }}" ] || [ ! -f "main/${{ inputs.update_dependencies_pr_body_file }}" ]; then
if [ -z "${{ inputs.update_dependencies_pr_body_file }}" ] || [ ! -f "${{ inputs.update_dependencies_pr_body_file }}" ]; then
PR_BODY_FILE=.tmp_pr-body_${{ github.run_id }}_${{ github.run_number }}_${{ github.run_attempt }}.txt
echo "PR_BODY_FILE=${PR_BODY_FILE}" >> $GITHUB_ENV
Expand Down
29 changes: 9 additions & 20 deletions .github/workflows/ci_check_pyproject_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ jobs:
with:
ref: ${{ inputs.permanent_dependencies_branch }}
fetch-depth: 0
path: main

- name: Checkout CasperWA/ci-cd
uses: actions/checkout@v3
with:
repository: CasperWA/ci-cd
ref: main
path: ci-cd

- name: Set up Python ${{ inputs.python_version }}
uses: actions/setup-python@v4
Expand All @@ -75,38 +67,36 @@ jobs:
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install ./main${{ inputs.install_extras }}
pip install -r ./ci-cd/requirements.txt
pip install .${{ inputs.install_extras }}
pip install git+https://github.com/CasperWA/ci-cd.git@v1
- name: Set up git user
run: |
git config --global user.name "${{ inputs.git_username }}"
git config --global user.email "${{ inputs.git_email }}"
- name: Run invoke task
- name: Run ci-cd task
run: |
if [ "${{ inputs.fail_fast }}" == "true" ]; then
FAIL_FAST=--fail-fast
else
FAIL_FAST=
fi
invoke update-deps --repo-folder=main ${FAIL_FAST}
ci-cd update-deps --root-repo-path="${PWD}" ${FAIL_FAST}
MAIN_DIR="${{ github.workspace }}/main"
if [ -n "$(git -C ${MAIN_DIR} status --porcelain pyproject.toml)" ]; then
if [ -n "$(git status --porcelain pyproject.toml)" ]; then
echo "UPDATE_DEPS=true" >> $GITHUB_ENV
git -C ${MAIN_DIR} add pyproject.toml
git -C ${MAIN_DIR} commit -m "Update dependencies in \`pyproject.toml\`"
git add pyproject.toml
git commit -m "Update dependencies in \`pyproject.toml\`"
else
echo "UPDATE_DEPS=false" >> $GITHUB_ENV
fi
working-directory: ./ci-cd
- name: Set PR body
if: env.UPDATE_DEPS == 'true'
run: |
if [ -z "${{ inputs.pr_body_file }}" ] || [ ! -f "main/${{ inputs.pr_body_file }}" ]; then
if [ -z "${{ inputs.pr_body_file }}" ] || [ ! -f "${{ inputs.pr_body_file }}" ]; then
PR_BODY_FILE=.tmp_pr-body_${{ github.run_id }}_${{ github.run_number }}_${{ github.run_attempt }}.txt
echo "PR_BODY_FILE=${PR_BODY_FILE}" >> $GITHUB_ENV
Expand All @@ -115,7 +105,7 @@ jobs:
echo "REMOVE_PR_BODY_FILE=true" >> $GITHUB_ENV
else
echo "Using found PR body text file at ${{ inputs.pr_body_file }}."
echo "PR_BODY_FILE=main/${{ inputs.pr_body_file }}" >> $GITHUB_ENV
echo "PR_BODY_FILE=${{ inputs.pr_body_file }}" >> $GITHUB_ENV
echo "REMOVE_PR_BODY_FILE=false" >> $GITHUB_ENV
fi
Expand Down Expand Up @@ -143,7 +133,6 @@ jobs:
title: "[Auto-generated] Check & update dependencies (`pyproject.toml`)"
body: ${{ steps.pr_body.outputs.result }}
labels: "${{ inputs.pr_labels }}"
path: ./main

- name: Information
run: 'echo "${{ steps.cpr.outputs.pull-request-operation }} PR #${{ steps.cpr.outputs.pull-request-number }}: ${{ steps.cpr.outputs.pull-request-url }}"'
6 changes: 5 additions & 1 deletion .github/workflows/ci_update_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ jobs:
if: inputs.update_pre-commit
run: |
pre-commit autoupdate
if [ -n "$(grep -i '\- repo: https://github.com/CasperWA/ci-cd' .pre-commit-config.yaml)" ]; then
# Using hooks from this repository
pre-commit autoupdate --repo https://github.com/CasperWA/ci-cd --freeze
fi
if [ -n "$(git status --porcelain .pre-commit-config.yaml)" ]; then
# Set environment variable notifying next steps that the hooks changed
Expand Down Expand Up @@ -127,7 +131,7 @@ jobs:
- name: Set PR body
run: |
if [ -z "${{ inputs.pr_body_file }}" ] || [ ! -f "main/${{ inputs.pr_body_file }}" ]; then
if [ -z "${{ inputs.pr_body_file }}" ] || [ ! -f "${{ inputs.pr_body_file }}" ]; then
PR_BODY_FILE=.tmp_pr-body_${{ github.run_id }}_${{ github.run_number }}_${{ github.run_attempt }}.txt
echo "PR_BODY_FILE=${PR_BODY_FILE}" >> $GITHUB_ENV
Expand Down
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ repos:
- id: pylint
name: pylint
entry: pylint
args:
- "--max-args=10"
- "--max-branches=15"
language: python
types: [python]
require_serial: true
# files: ^.*$
Loading

0 comments on commit 1b5dce8

Please sign in to comment.