From 7c4972807720e3207f56ca3b53b0193fa9744da9 Mon Sep 17 00:00:00 2001 From: Panos Vagenas <35837085+vagenas@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:57:29 +0100 Subject: [PATCH] chore: add CI/CD (#2) Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com> --- .github/actions/setup-poetry/action.yml | 19 ++++++ .github/mergify.yml | 16 +++++ .github/scripts/release.sh | 39 +++++++++++ .github/workflows/cd.yml | 64 +++++++++++++++++++ .github/workflows/checks.yml | 16 +++++ .github/workflows/ci.yml | 27 ++++++++ .github/workflows/pypi.yml | 21 ++++++ .../data/2408.09869v5_hs_docs_doc_chunks.json | 2 +- 8 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 .github/actions/setup-poetry/action.yml create mode 100644 .github/mergify.yml create mode 100755 .github/scripts/release.sh create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/pypi.yml diff --git a/.github/actions/setup-poetry/action.yml b/.github/actions/setup-poetry/action.yml new file mode 100644 index 0000000..853c517 --- /dev/null +++ b/.github/actions/setup-poetry/action.yml @@ -0,0 +1,19 @@ +name: 'Set up Poetry and install' +description: 'Set up a specific version of Poetry and install dependencies using caching.' +inputs: + python-version: + description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax." + default: '3.11' +runs: + using: 'composite' + steps: + - name: Install poetry + run: pipx install poetry==1.8.4 + shell: bash + - uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + cache: 'poetry' + - name: Install dependencies + run: poetry install --all-extras + shell: bash diff --git a/.github/mergify.yml b/.github/mergify.yml new file mode 100644 index 0000000..42c4449 --- /dev/null +++ b/.github/mergify.yml @@ -0,0 +1,16 @@ +merge_protections: + - name: Enforce conventional commit + description: Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/ + if: + - base = main + success_conditions: + - "title ~= + ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\\(.+\ + \\))?(!)?:" + - name: Require two reviewer for test updates + description: When test data is updated, we require two reviewers + if: + - base = main + - files ~= ^test + success_conditions: + - "#approved-reviews-by >= 2" diff --git a/.github/scripts/release.sh b/.github/scripts/release.sh new file mode 100755 index 0000000..6cac400 --- /dev/null +++ b/.github/scripts/release.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -e # trigger failure on error - do not remove! +set -x # display command on output + +if [ -z "${TARGET_VERSION}" ]; then + >&2 echo "No TARGET_VERSION specified" + exit 1 +fi +CHGLOG_FILE="${CHGLOG_FILE:-CHANGELOG.md}" + +# update package version +poetry version "${TARGET_VERSION}" + +# collect release notes +REL_NOTES=$(mktemp) +poetry run semantic-release changelog --unreleased >> "${REL_NOTES}" + +# update changelog +TMP_CHGLOG=$(mktemp) +TARGET_TAG_NAME="v${TARGET_VERSION}" +RELEASE_URL="$(gh repo view --json url -q ".url")/releases/tag/${TARGET_TAG_NAME}" +printf "## [${TARGET_TAG_NAME}](${RELEASE_URL}) - $(date -Idate)\n\n" >> "${TMP_CHGLOG}" +cat "${REL_NOTES}" >> "${TMP_CHGLOG}" +if [ -f "${CHGLOG_FILE}" ]; then + printf "\n" | cat - "${CHGLOG_FILE}" >> "${TMP_CHGLOG}" +fi +mv "${TMP_CHGLOG}" "${CHGLOG_FILE}" + +# push changes +git config --global user.name 'github-actions[bot]' +git config --global user.email 'github-actions[bot]@users.noreply.github.com' +git add pyproject.toml "${CHGLOG_FILE}" +COMMIT_MSG="chore: bump version to ${TARGET_VERSION} [skip ci]" +git commit -m "${COMMIT_MSG}" +git push origin main + +# create GitHub release (incl. Git tag) +gh release create "${TARGET_TAG_NAME}" -F "${REL_NOTES}" diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..9d2f5bb --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,64 @@ +name: "Run CD" + +on: + workflow_dispatch: + +env: + # disable keyring (https://github.com/actions/runner-images/issues/6185): + PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring + +jobs: + # To be enabled when we add docs + # docs: + # permissions: + # contents: write + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - uses: ./.github/actions/setup-poetry + # - name: Build and push docs + # run: poetry run mkdocs gh-deploy --force + + code-checks: + uses: ./.github/workflows/checks.yml + pre-release-check: + runs-on: ubuntu-latest + outputs: + TARGET_TAG_V: ${{ steps.version_check.outputs.TRGT_VERSION }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # for fetching tags, required for semantic-release + - uses: ./.github/actions/setup-poetry + - name: Check version of potential release + id: version_check + run: | + TRGT_VERSION=$(poetry run semantic-release print-version) + echo "TRGT_VERSION=${TRGT_VERSION}" >> $GITHUB_OUTPUT + echo "${TRGT_VERSION}" + - name: Check notes of potential release + run: poetry run semantic-release changelog --unreleased + release: + needs: [code-checks, pre-release-check] + if: needs.pre-release-check.outputs.TARGET_TAG_V != '' + environment: auto-release + runs-on: ubuntu-latest + concurrency: release + steps: + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ vars.CI_APP_ID }} + private-key: ${{ secrets.CI_PRIVATE_KEY }} + - uses: actions/checkout@v4 + with: + token: ${{ steps.app-token.outputs.token }} + fetch-depth: 0 # for fetching tags, required for semantic-release + - uses: ./.github/actions/setup-poetry + - name: Run release script + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + TARGET_VERSION: ${{ needs.pre-release-check.outputs.TARGET_TAG_V }} + CHGLOG_FILE: CHANGELOG.md + run: ./.github/scripts/release.sh + shell: bash diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..5fdb2e7 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,16 @@ +on: + workflow_call: + +jobs: + run-checks: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.9', '3.10', '3.11', '3.12'] + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-poetry + with: + python-version: ${{ matrix.python-version }} + - name: Run styling check + run: poetry run pre-commit run --all-files diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3b2e3e9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: "Run CI" + +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: + - "**" + - "!gh-pages" + +env: + # disable keyring (https://github.com/actions/runner-images/issues/6185): + PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring + +jobs: + code-checks: + if: ${{ github.event_name == 'push' || (github.event.pull_request.head.repo.full_name != 'DS4SD/docling-haystack' && github.event.pull_request.head.repo.full_name != 'ds4sd/docling-haystack') }} + uses: ./.github/workflows/checks.yml + + # To enable when we add the ./docs + # build-docs: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - uses: ./.github/actions/setup-poetry + # - name: Build docs + # run: poetry run mkdocs build --verbose --clean diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..395f34c --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,21 @@ +name: "Build and publish package" + +on: + release: + types: [published] + +permissions: + contents: read + +env: + # disable keyring (https://github.com/actions/runner-images/issues/6185): + PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-poetry + - name: Build and publish + run: poetry publish --build --no-interaction --username=__token__ --password=${{ secrets.PYPI_TOKEN }} diff --git a/test/data/2408.09869v5_hs_docs_doc_chunks.json b/test/data/2408.09869v5_hs_docs_doc_chunks.json index 2bcc613..4520e59 100644 --- a/test/data/2408.09869v5_hs_docs_doc_chunks.json +++ b/test/data/2408.09869v5_hs_docs_doc_chunks.json @@ -4633,4 +4633,4 @@ } } ] -} \ No newline at end of file +}