Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate GH Pages build #28

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
444927f
Scaffold for automating GH Pages build
CasperWA Apr 23, 2021
9843053
Update versions
CasperWA Aug 18, 2021
25a9bac
Run pre-commit
CasperWA Aug 18, 2021
5eb2920
Update .gitignore
CasperWA Dec 3, 2021
02f0b71
Use SINTEF/ci-cd for workflows
CasperWA Jul 19, 2022
7df2998
Minor fix to workflow value
CasperWA Jul 19, 2022
b3e5a40
Update pre-commit hooks, add isort
CasperWA Jul 19, 2022
6815d16
Running isort and updating with black max line len
CasperWA Jul 19, 2022
649d226
Update pylint disable statements in codebase
CasperWA Jul 19, 2022
0d274d4
Fix typo
CasperWA Jul 19, 2022
4939fd0
Add `Word` to DDL and create full cif-core ontology
CasperWA Jul 21, 2022
beaa794
Remove auto-generated catalog file
CasperWA Jul 21, 2022
5c98deb
Fallback to online DDL ontology
CasperWA Jul 21, 2022
589a5b4
Add new MkDocs framework documentation
CasperWA Jul 21, 2022
e403a5a
Add documentation landing page
CasperWA Jul 21, 2022
cba0d38
Update documentation with proper links
CasperWA Jul 21, 2022
fcdbb96
Beginning version release overview docs page
CasperWA Jul 21, 2022
9cb4e3b
Create _utils.py to hold utility elements
CasperWA Jul 22, 2022
02944b3
Don't add private module to API docs
CasperWA Jul 22, 2022
f01a711
Implement auto-generation when building docs
CasperWA Jul 22, 2022
3bb1554
Remove ignoring NumPy safety issues
CasperWA Aug 19, 2022
b71bb0a
Fix tests according to updated Generator
CasperWA Aug 19, 2022
9301442
Revert "Remove ignoring NumPy safety issues"
CasperWA Aug 19, 2022
a6aee95
Fix API reference documentation
CasperWA Aug 23, 2022
1fced73
Build docs and dic2owl package in CI
CasperWA Aug 23, 2022
06c6b4b
Install the `build` package in CI
CasperWA Aug 23, 2022
b87b7f8
Ensure dependencies are installed for CI
CasperWA Aug 23, 2022
74c6e15
Fix installing dependencies
CasperWA Aug 23, 2022
42cd2c3
Set `create_dirs` configuration to True
CasperWA Aug 23, 2022
e8aa27f
Only create publish_dir in MkDocs plugin
CasperWA Aug 23, 2022
26a742d
Don't try to set `root_dir` in plugin
CasperWA Aug 23, 2022
2a0a0d4
Attempt at fixing plugin
CasperWA Aug 23, 2022
af3ed16
Update ci/cd hook and use `relative` option
CasperWA Aug 24, 2022
8cf4526
Fix API reference documentation
CasperWA Aug 24, 2022
0f666f8
Merge remote-tracking branch 'origin/main' into automate_gh-pages
CasperWA Feb 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .github/static/get_dic2owl_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Retrieve dependencies from a `requirements.txt`-style file.
"""
import argparse
from pathlib import Path
import re
from pathlib import Path
from typing import Set


Expand All @@ -24,22 +24,17 @@ def main(argv_input: list = None) -> Set[str]:
)
args = parser.parse_args(argv_input)

requirements_regex = re.compile(
r"^(?P<name>[A-Za-z0-9_-]+)(~=|>=|==).*\n$"
)
requirements_regex = re.compile(r"^(?P<name>[A-Za-z0-9_-]+)(~=|>=|==).*\n$")
dependencies = set()
for file in args.requirements_files:
if not file.exists():
raise FileNotFoundError(f"Could not find {file} !")
with open(file.resolve(), "r") as handle:
with open(file.resolve(), "r", encoding="utf8") as handle:
for line in handle.readlines():
match = requirements_regex.fullmatch(line)
if match is None:
raise ValueError(
(
"Couldn't determine package name from line:\n\n "
f"{line}"
)
("Couldn't determine package name from line:\n\n " f"{line}")
)
dependencies.add(match.group("name"))
return dependencies
Expand Down
44 changes: 27 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@ on: [push]

jobs:
pre-commit-basic:
runs-on: ubuntu-latest
name: External
uses: SINTEF/ci-cd/.github/workflows/[email protected]
with:
# general setup
python_version: "3.7"
install_extras: "/dic2owl[dev] && pip install -U --upgrade-strategy=eager -r requirements_docs.txt"
run_pylint: false
run_safety: false
run_build_package: false

steps:
- name: Checkout repository
uses: actions/checkout@v3
# pre-commit
run_pre-commit: true
skip_pre-commit_hooks: "pylint,mypy,black,bandit,requirements-txt-fixer"

- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install pre-commit

- name: Run pre-commit
run: SKIP=pylint,mypy,black,bandit,requirements-txt-fixer pre-commit run --all-files
# build docs
run_build_docs: true
package_dir: "dic2owl/dic2owl"
exclude_dirs: |
__pycache__
_mkdocs
exclude_files: |
__init__.py
_utils.py
landing_page_replacements: |
(LICENSE),(LICENSE.md)
(dic2owl/README.md),(dic2owl/index.md)
(ontology),(https://github.com/emmo-repo/CIF-ontology/tree/main/ontology)
(ontology/catalog-v001.xml),(https://github.com/emmo-repo/CIF-ontology/blob/main/ontology/catalog-v001.xml)
relative: true
27 changes: 5 additions & 22 deletions .github/workflows/ci_automerge_dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,9 @@ on:
branches: [ci/dependabot-updates]

jobs:
update-dependabot-branch:
name: Update permanent dependabot branch
automerge-dependency-prs:
name: External
uses: SINTEF/ci-cd/.github/workflows/[email protected]
if: github.repository_owner == 'emmo-repo' && 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: CIF-ontology Team
GIT_USER_EMAIL: "[email protected]"

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

- 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_CWA }}
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
59 changes: 10 additions & 49 deletions .github/workflows/ci_cd_updated_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,16 @@ on:
push:
branches: [main]

env:
DEPENDABOT_BRANCH: ci/dependabot-updates
GIT_USER_NAME: CIF-ontology Team
GIT_USER_EMAIL: "[email protected]"
DEFAULT_REPO_BRANCH: main

jobs:
update-dependabot-branch:
name: Update permanent dependabot branch
name: External
uses: SINTEF/ci-cd/.github/workflows/[email protected]
if: github.repository_owner == 'emmo-repo'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ env.DEPENDABOT_BRANCH }}
fetch-depth: 0

- name: Set up git config
run: |
git config --global user.name "${{ env.GIT_USER_NAME }}"
git config --global user.email "${{ env.GIT_USER_EMAIL }}"

- name: Update '${{ env.DEPENDABOT_BRANCH }}'
run: |
git fetch origin

LATEST_PR_BODY="$(gh api /repos/${{ github.repository}}/pulls -X GET -f state=closed -f per_page=1 -f sort=updated -f direction=desc --jq '.[].body')"
cat .github/static/single_dependency_pr_body.txt | head -8 > .tmp_file.txt
if [ -z "$(printf '%s\n' "${LATEST_PR_BODY}" | head -8 | diff - .tmp_file.txt --strip-trailing-cr)" ]; then
# The dependency branch has just been merged into `${{ env.DEFAULT_REPO_BRANCH }}`
# The dependency branch should be reset to `${{ env.DEFAULT_REPO_BRANCH }}`
echo "The dependencies have just been updated! Reset to ${{ env.DEFAULT_REPO_BRANCH }}."
git reset --hard origin/${{ env.DEFAULT_REPO_BRANCH }}
echo "FORCE_PUSH=yes" >> $GITHUB_ENV
else
# Normal procedure: Merge `${{ env.DEFAULT_REPO_BRANCH }}` into `${{ env.DEPENDABOT_BRANCH }}`
echo "Merge new updates to ${{ env.DEFAULT_REPO_BRANCH }} into ${{ env.DEPENDABOT_BRANCH }}"
git merge -m "Keep '${{ env.DEPENDABOT_BRANCH }}' up-to-date with '${{ env.DEFAULT_REPO_BRANCH }}'" origin/${{ env.DEFAULT_REPO_BRANCH }}
echo "FORCE_PUSH=no" >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Push to '${{ env.DEPENDABOT_BRANCH }}'
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.RELEASE_PAT_CWA }}
branch: ${{ env.DEPENDABOT_BRANCH }}
sleep: 15
force: ${{ env.FORCE_PUSH }}
with:
git_username: "TEAM 4.0[bot]"
git_email: "[email protected]"
permanent_dependencies_branch: ci/dependabot-updates
default_repo_branch: main
relative: true
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
101 changes: 15 additions & 86 deletions .github/workflows/ci_dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,90 +9,19 @@ on:

jobs:
create-collected-pr:
name: Single dependabot PR
name: External
uses: SINTEF/ci-cd/.github/workflows/[email protected]
if: github.repository_owner == 'emmo-repo'
runs-on: ubuntu-latest
env:
DEPENDABOT_BRANCH: ci/dependabot-updates
GIT_USER_NAME: CIF-ontology Team
GIT_USER_EMAIL: "[email protected]"
DEFAULT_REPO_BRANCH: main

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ env.DEFAULT_REPO_BRANCH }}

- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install `pre-commit` and dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel

while IFS="" read -r line || [ -n "${line}" ]; do
if [[ "${line}" =~ ^pre-commit.*$ ]]; then
pre_commit="${line}"
fi
done < dic2owl/requirements_dev.txt

pip install ${pre_commit}

- 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: Reset to '${{ env.DEPENDABOT_BRANCH }}'
run: |
git fetch origin ${{ env.DEPENDABOT_BRANCH }}:${{ env.DEPENDABOT_BRANCH }}
git reset --hard ${{ env.DEPENDABOT_BRANCH }}

- name: Auto-update `pre-commit` hooks
run: |
pre-commit autoupdate

if [ -n "$(git status --porcelain .pre-commit-config.yaml)" ]; then
# Set environment variable notifying next steps that the hooks changed
echo "Pre-commit hooks have been updated !"
echo "UPDATED_PRE_COMMIT_HOOKS=true" >> $GITHUB_ENV
else
echo "No pre-commit hooks have been updated."
echo "UPDATED_PRE_COMMIT_HOOKS=false" >> $GITHUB_ENV
fi

- name: Possibly run `pre-commit` with updated hooks
if: env.UPDATED_PRE_COMMIT_HOOKS == 'true'
continue-on-error: true # Still create the PR if this step fails
run: SKIP=pylint pre-commit run --all-files

- name: Possibly commit changes and updates
if: env.UPDATED_PRE_COMMIT_HOOKS == 'true'
run: git commit -am "Update \`pre-commit\` hooks"

- name: Fetch PR body
id: pr_body
uses: chuhlomin/[email protected]
with:
template: .github/static/single_dependency_pr_body.txt

- name: Create PR
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.RELEASE_PAT_CWA }}
commit-message: New @dependabot-fueled updates
committer: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>"
author: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>"
branch: ci/update-dependencies
delete-branch: true
title: "[Auto-generated] Update dependencies"
body: ${{ steps.pr_body.outputs.result }}
labels: dependencies,github_actions

- name: Information
run: 'echo "${{ steps.cpr.outputs.pull-request-operation }} PR #${{ steps.cpr.outputs.pull-request-number }}: ${{ steps.cpr.outputs.pull-request-url }}"'
with:
git_username: "TEAM 4.0[bot]"
git_email: "[email protected]"
permanent_dependencies_branch: ci/dependabot-updates
default_repo_branch: main
pr_labels: dependencies,github_actions
extra_to_dos: "- [ ] Make sure that the PR is **squash** merged, with a sensible commit message."
update_pre-commit: true
skip_pre-commit_hooks: pylint
python_version: "3.7"
install_extras: "/dic2owl[dev]"
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
81 changes: 32 additions & 49 deletions .github/workflows/dic2owl_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,46 @@ on:
- '.github/**'

jobs:
pre-commit-dic2owl:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install pre-commit

- name: Run pre-commit
run: SKIP=pylint pre-commit run --all-files

pylint-safety:
name: PyLint and safety
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel

pip install -U -r dic2owl/requirements.txt -r dic2owl/requirements_dev.txt
pip install safety

- name: Run PyLint
run: pylint --rcfile=dic2owl/pyproject.toml dic2owl/**/*.py

dic2owl-basic:
name: External
uses: SINTEF/ci-cd/.github/workflows/[email protected]
with:
# general setup
python_version: "3.7"
install_extras: "/dic2owl[dev]"
run_build_docs: false

# pre-commit
run_pre-commit: true
skip_pre-commit_hooks: pylint

# pylint
run_pylint: true
pylint_targets: "dic2owl/**/*.py"
pylint_options: "--rcfile=dic2owl/pyproject.toml"

# safety
run_safety: true
# Ignore ID 44715 for now.
# See this NumPy issue for more information: https://github.com/numpy/numpy/issues/19038
# Remove ignoring 48547 as soon as RDFLib/rdflib#1844 has been fixed and the fix
# has been released.
- name: Run safety
run: pip freeze | safety check --stdin --ignore 44715 --ignore 44716 --ignore 44717 --ignore 48547
safety_options: |
--ignore=44715
--ignore=44716
--ignore=44717
--ignore=48547

# build dist
run_build_package: true
build_libs: build
build_cmd: python -m build -o dist dic2owl

dic2owl-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9"]

steps:
- uses: actions/checkout@v3
Expand All @@ -78,7 +61,7 @@ jobs:
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install -e dic2owl[dev]
pip install -e ./dic2owl[dev]

- name: Run unit tests with PyTest
run: pytest -c dic2owl/pyproject.toml
Loading