From 01cc603be2c256bb8cba70061c5f2ca266268bff Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:46:55 +0100 Subject: [PATCH] Create dedicated workflow for rdflib test files (#238) * Create dedicated workflow for rdflib test files * Skip local pre-commit hook in pre-commit.ci --- .github/utils/canonize_rdflib_test_file.sh | 50 ------------- .github/workflows/ci_automerge_dependabot.yml | 7 +- .github/workflows/ci_update_test_files.yml | 74 +++++++++++++++++++ .pre-commit-config.yaml | 2 +- 4 files changed, 76 insertions(+), 57 deletions(-) delete mode 100755 .github/utils/canonize_rdflib_test_file.sh create mode 100644 .github/workflows/ci_update_test_files.yml diff --git a/.github/utils/canonize_rdflib_test_file.sh b/.github/utils/canonize_rdflib_test_file.sh deleted file mode 100755 index 7205ad9..0000000 --- a/.github/utils/canonize_rdflib_test_file.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -if [ -z "${CI}" ]; then - echo "This script is intended to be run in a GitHub Actions environment." - exit 1 -else - echo "Running in CI environment" - echo "GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}" - echo "GITHUB_ACTOR: ${GITHUB_ACTOR}" -fi - -# Only run if the PR is from dependabot -if [ "${GITHUB_ACTOR}" != "dependabot[bot]" ]; then - echo "This PR is not from dependabot, exiting early..." - exit 0 -fi - -pip install --upgrade pip -pip install -U setuptools wheel -pip install -U ${GITHUB_WORKSPACE} - -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/turtle_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 -else - echo "No canonized test file for RDFlib version ${RDFLIB_VERSION} found, creating it..." - - cp "${CORE_TEST_ONTOLOGY_FILE}" "${CANONIZED_FILEPATH}" - turtle-canon "${CANONIZED_FILEPATH}" - exit 0 -fi diff --git a/.github/workflows/ci_automerge_dependabot.yml b/.github/workflows/ci_automerge_dependabot.yml index 8bbdde2..067d7cc 100644 --- a/.github/workflows/ci_automerge_dependabot.yml +++ b/.github/workflows/ci_automerge_dependabot.yml @@ -1,4 +1,4 @@ -name: CI - Activate auto-merging for dependencies PRs +name: CI - Activate auto-merging for bot PRs on: pull_request_target: @@ -10,12 +10,7 @@ jobs: uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.8.2 if: github.repository_owner == 'CasperWA' && ( ( startsWith(github.event.pull_request.head.ref, 'dependabot/') && github.actor == 'dependabot[bot]' ) || ( github.event.pull_request.head.ref == 'pre-commit-ci-update-config' && github.actor == 'pre-commit-ci[bot]' ) ) with: - perform_changes: true git_username: CasperWA git_email: "casper.w.andersen@sintef.no" - changes: | - #!/bin/bash - - ./.github/utils/canonize_rdflib_test_file.sh secrets: PAT: ${{ secrets.RELEASE_PAT }} diff --git a/.github/workflows/ci_update_test_files.yml b/.github/workflows/ci_update_test_files.yml new file mode 100644 index 0000000..54dbcbd --- /dev/null +++ b/.github/workflows/ci_update_test_files.yml @@ -0,0 +1,74 @@ +name: CI - Update RDFLib canonized test files + +on: + pull_request: + branches: [main] + paths: + - 'pyproject.toml' + +jobs: + check-rdflib-test-files: + name: Update RDFLib canonized test files + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U setuptools wheel + pip install -U . + + - name: Configuration + id: config + run: | + RDFLIB_VERSION=$(python -c 'import rdflib; print(rdflib.__version__)') + CANONIZED_FILENAME="turtle_canon_tests_canonized_${RDFLIB_VERSION}.ttl" + + echo "rdflib_version=${RDFLIB_VERSION}" >> $GITHUB_OUTPUT + echo "canonized_filepath=${{ github.workspace }}/tests/static/rdflib_canonized/${CANONIZED_FILENAME}" >> $GITHUB_OUTPUT + echo "core_test_ontology_file=${{ github.workspace }}/tests/static/turtle_canon_tests.ttl" >> $GITHUB_OUTPUT + + echo "temp_filepath="/tmp/${CANONIZED_FILENAME}" >> $GITHUB_OUTPUT + + - name: Check if canonized file exists + id: file_exists + run: | + if [ -f "${{ steps.config.outputs.canonized_filepath }}" ]; then + CANONIZED_FILE_EXISTS=true + else + CANONIZED_FILE_EXISTS=false + fi + + echo "Canonized file exists: ${CANONIZED_FILE_EXISTS}" + echo "canonized_file_exists=${CANONIZED_FILE_EXISTS}" >> $GITHUB_OUTPUT + + - name: Check content of canonized file + if: steps.file_exists.outputs.canonized_file_exists == 'true' + run: | + cp ${{ steps.config.outputs.core_test_ontology_file }} ${{ steps.config.outputs.temp_filepath }} + turtle-canon "${{ steps.config.outputs.temp_filepath }}" + + DIFF=$(diff ${TEMP_FILEPATH} ${CANONIZED_FILEPATH}) + if [ "$DIFF" != "" ]; then + echo "The existing canonized test file for RDFlib version ${{ steps.config.outputs.rdflib_version }} differs from the currently generated one using the same version !" + echo -e "Diff:\n${DIFF}" + rm -f "${{ steps.config.outputs.temp_filepath }}" + exit 1 + else + echo "Canonized test file for RDFlib version ${{ steps.config.outputs.rdflib_version }} is up-to-date, nothing to do." + rm -f "${{ steps.config.outputs.temp_filepath }}" + fi + + - name: Generate new canonized file + if: steps.file_exists.outputs.canonized_file_exists == 'false' + run: | + cp ${{ steps.config.outputs.core_test_ontology_file }} ${{ steps.config.outputs.canonized_filepath }} + turtle-canon "${{ steps.config.outputs.canonized_filepath }}" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc7af55..e15c8d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: autoupdate_branch: 'main' autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' autoupdate_schedule: 'weekly' - skip: [] + skip: [codecov-validator] submodules: false # hooks