Skip to content

Commit

Permalink
Upgrade code base (#179)
Browse files Browse the repository at this point in the history
Use pyproject.toml and upgrade to Python 3.10.
Only support Python 3.10.

Use SINTEF/ci-cd throughout where possible.
More info: https://SINTEF.github.io/ci-cd
Still use dependabot to update dependencies though.

Update code base according to ruff and pyupgrade.
Use ruff instead of pylint.
  • Loading branch information
CasperWA committed Jan 12, 2024
1 parent 898807b commit 86fbf80
Show file tree
Hide file tree
Showing 32 changed files with 491 additions and 1,185 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ coverage:

status:
project:
default: off
default: false
turtle-canon:
threshold: 1%
flags:
Expand Down
7 changes: 5 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ updates:
interval: weekly
day: monday
time: "05:00"
# Should be bigger than or equal to the total number of dependencies (currently 18)
open-pull-requests-limit: 30
# Should be bigger than or equal to the total number of dependencies (currently 11)
open-pull-requests-limit: 15
target-branch: ci/dependabot-updates
labels:
- dependencies
- "CI/CD"
- skip_changelog
- package-ecosystem: github-actions
directory: "/"
schedule:
Expand All @@ -19,3 +21,4 @@ updates:
target-branch: ci/dependabot-updates
labels:
- "CI/CD"
- skip_changelog
6 changes: 0 additions & 6 deletions .github/utils/release_tag_msg.txt

This file was deleted.

5 changes: 0 additions & 5 deletions .github/utils/single_dependency_pr_body.txt

This file was deleted.

32 changes: 0 additions & 32 deletions .github/utils/update_docs.sh

This file was deleted.

142 changes: 30 additions & 112 deletions .github/workflows/cd_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,117 +5,35 @@ on:
types:
- published

env:
PUBLISH_UPDATE_BRANCH: main
GIT_USER_NAME: CasperWA
GIT_USER_EMAIL: "casper+github@welzel.nu"

jobs:

update-and-publish:
name: Update CHANGELOG and documentation
runs-on: ubuntu-latest
publish-docs:
name: External
uses: SINTEF/ci-cd/.github/workflows/cd_release.yml@v2.7.1
if: github.repository == 'CasperWA/turtle-canon' && startsWith(github.ref, 'refs/tags/v')

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install Python dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install -U -e .[dev]
- name: Update changelog
uses: CharMixer/auto-changelog-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }}

- name: Update documentation and version - Commit changes and update tag
run: .github/utils/update_docs.sh

- name: Push updates to '${{ env.PUBLISH_UPDATE_BRANCH }}'
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.RELEASE_PAT }}
branch: ${{ env.PUBLISH_UPDATE_BRANCH }}
force: true
tags: true

- name: Get tagged versions
run: echo "PREVIOUS_VERSION=$(git tag -l --sort -version:refname | sed -n 2p)" >> $GITHUB_ENV

- name: Create release-specific changelog
uses: CharMixer/auto-changelog-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }}
since_tag: "${{ env.PREVIOUS_VERSION }}"
output: "release_changelog.md"

- name: Append changelog to release body
run: |
gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} --jq '.body' > release_body.md
cat release_changelog.md >> release_body.md
gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} -X PATCH -F body='@release_body.md'
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}

# - name: Build source distribution
# run: python ./setup.py sdist

# - name: Publish package to TestPyPI
# uses: pypa/gh-action-pypi-publish@master
# with:
# user: __token__
# password: ${{ secrets.TEST_PYPI_TOKEN }}
# repository_url: "https://test.pypi.org/legacy"

# - name: Publish package to PyPI
# uses: pypa/gh-action-pypi-publish@master
# with:
# user: __token__
# password: ${{ secrets.PYPI_TOKEN }}

docs:
name: Build and deploy documentation
needs: update-and-publish
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.PUBLISH_UPDATE_BRANCH }}
token: ${{ secrets.RELEASE_PAT }}

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install Python dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install -U -e .[docs]
- name: Set up git user
run: |
git config --global user.name "${{ env.GIT_USER_NAME }}"
git config --global user.email "${{ env.GIT_USER_EMAIL }}"
- name: Deploy documentation
run: |
mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml ${GITHUB_REF#refs/tags/v} stable
mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ env.PUBLISH_UPDATE_BRANCH }}
with:
# General
git_username: CasperWA
git_email: "casper.w.andersen@sintef.no"
release_branch: main

# Python package
python_package: true
package_dirs: turtle_canon
install_extras: "[dev]"
python_version_build: "3.10"
version_update_changes: |
"README.md,latest stable version is \*\*.*\*\*\.,latest stable version is **{version}**."
build_libs: build
build_cmd: "python -m build"
changelog_exclude_labels: "skip_changelog,duplicate,question,invalid,wontfix"
publish_on_pypi: false

# Documentation
update_docs: true
python_version_docs: "3.10"
doc_extras: "[docs]"
docs_framework: "mkdocs"
mkdocs_update_latest: true

secrets:
PAT: ${{ secrets.RELEASE_PAT }}
110 changes: 41 additions & 69 deletions .github/workflows/ci_automerge_dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,51 @@
name: CI - Activate auto-merging for Dependabot PRs
name: CI - Activate auto-merging for dependencies PRs

on:
pull_request_target:
branches: [ci/dependabot-updates]
branches: [ci/dependency-updates]

jobs:
update-dependabot-branch:
name: Update permanent dependabot branch
update-dependencies-branch:
name: External
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.7.1
if: github.repository_owner == 'CasperWA' && startsWith(github.event.pull_request.head.ref, 'dependabot/') && github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest

env:
DEPENDABOT_BRANCH: ci/dependabot-updates
GIT_USER_NAME: CasperWA
GIT_USER_EMAIL: "casper+github@welzel.nu"

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: false

- name: Setup Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Set up git user info
run: |
git config --global user.name "${{ env.GIT_USER_NAME }}"
git config --global user.email "${{ env.GIT_USER_EMAIL }}"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
with:
perform_changes: true
git_username: CasperWA
git_email: "casper.w.andersen@sintef.no"
changes: |
pip install --upgrade pip
pip install -U setuptools wheel
while IFS="" read -r line || [ -n "${line}" ]; do
if [[ "${line}" =~ ^invoke.*$ ]]; then
invoke="${line}"
pip install -U .
RDFLIB_VERSION="$(python -c 'import rdflib; print(rdflib.__version__)')"
CANONIZED_FILENAME="turtle_canon_tests_canonized_${RDFLIB_VERSION}.ttl"
CANONIZED_FILEPATH="${{ github.workspace }}/tests/static/rdflib_canonized/${CANONIZED_FILENAME}"
CORE_TEST_ONTOLOGY_FILE="${{ github.workspace }}/tests/static/rdflib_canon_tests.ttl"
if [ -f "${CANONIZED_FILEPATH}" ]; then
echo "Canonized test file for RDFlib version ${RDFLIB_VERSION} already exists, checking contents..."
# Copy core test ontology file into a temporary file and canonize it
TEMP_FILEPATH="/tmp/${CANONIZED_FILENAME}.ttl"
cp "${CORE_TEST_ONTOLOGY_FILE}" "${TEMP_FILEPATH}"
turtle-canon "${TEMP_FILEPATH}"
if [ "$(diff "${TEMP_FILEPATH}" "${CANONIZED_FILEPATH}")" ]; then
echo "The existing canonized test file for RDFlib version ${RDFLIB_VERSION} differs from the currently generated one using the same version !"
rm -f "${TEMP_FILEPATH}"
exit 1
else
echo "Canonized test file for RDFlib version ${RDFLIB_VERSION} is up-to-date, nothing to do."
rm -f "${TEMP_FILEPATH}"
exit 0
fi
done < requirements_docs.txt
pip install ${invoke}
pip install -r requirements.txt
pip install .
- name: Run tasks (and commit)
run: |
invoke update-pytest-reqs
invoke create-canonized-test-file
git add pyproject.toml tests/static/rdflib_canonized
if [ -n "$(git status --porcelain pyproject.toml tests/static/rdflib_canonized)" ]; then
# Only commit if there's something to commit (git will return non-zero otherwise)
echo "Committing update to pytest dependency config and/or RDFlib version-specific canonized test file !"
git commit -m "Update version-specific parts\n\nUpdate pytest dependency config and/or\nRDFlib version-specific canonized test file"
echo "PUSH_BACK_TO_BRANCH=true" >> $GITHUB_ENV
else
echo "No changes to pytest dependency config and/or RDFlib version-specific canonized test file."
echo "PUSH_BACK_TO_BRANCH=false" >> $GITHUB_ENV
fi
- name: Update Dependabot branch
if: env.PUSH_BACK_TO_BRANCH == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.RELEASE_PAT }}
branch: ${{ github.event.pull_request.head.ref }}
echo "No canonized test file for RDFlib version ${RDFLIB_VERSION} found, creating it..."
- name: Activate auto-merge
run: |
PR_ID="$(gh api graphql -F owner='{owner}' -F name='{repo}' -f query='query($owner: String!, $name: String!) {repository(owner: $owner, name: $name) {pullRequest(number: ${{ github.event.pull_request.number }}) {id}}}' --jq '.data.repository.pullRequest.id')"
gh api graphql -f pr_id="$PR_ID" -f query='mutation($pr_id: ID!) {enablePullRequestAutoMerge(input:{mergeMethod:SQUASH,pullRequestId:$pr_id }) {pullRequest {number}}}'
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
cp "${CORE_TEST_ONTOLOGY_FILE}" "${CANONIZED_FILEPATH}"
turtle-canon "${CANONIZED_FILEPATH}"
exit 0
fi
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
Loading

0 comments on commit 86fbf80

Please sign in to comment.