Skip to content

Commit 76720ab

Browse files
committed
ci: add CI/CD pipeline
Signed-off-by: Panos Vagenas <[email protected]>
1 parent 3038b4e commit 76720ab

File tree

7 files changed

+202
-0
lines changed

7 files changed

+202
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'Set up Poetry and install'
2+
description: 'Set up a specific version of Poetry and install dependencies using caching.'
3+
inputs:
4+
python-version:
5+
description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax."
6+
default: '3.11'
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: Install poetry
11+
run: pipx install poetry==1.8.4
12+
shell: bash
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: ${{ inputs.python-version }}
16+
cache: 'poetry'
17+
- name: Install dependencies
18+
run: poetry install --all-extras
19+
shell: bash

.github/mergify.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
merge_protections:
2+
- name: Enforce conventional commit
3+
description: Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
4+
if:
5+
- base = main
6+
success_conditions:
7+
- "title ~=
8+
^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\\(.+\
9+
\\))?(!)?:"
10+
- name: Require two reviewer for test updates
11+
description: When test data is updated, we require two reviewers
12+
if:
13+
- base = main
14+
- files ~= ^test
15+
success_conditions:
16+
- "#approved-reviews-by >= 2"

.github/scripts/release.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -e # trigger failure on error - do not remove!
4+
set -x # display command on output
5+
6+
if [ -z "${TARGET_VERSION}" ]; then
7+
>&2 echo "No TARGET_VERSION specified"
8+
exit 1
9+
fi
10+
CHGLOG_FILE="${CHGLOG_FILE:-CHANGELOG.md}"
11+
12+
# update package version
13+
poetry version "${TARGET_VERSION}"
14+
15+
# collect release notes
16+
REL_NOTES=$(mktemp)
17+
poetry run semantic-release changelog --unreleased >> "${REL_NOTES}"
18+
19+
# update changelog
20+
TMP_CHGLOG=$(mktemp)
21+
TARGET_TAG_NAME="v${TARGET_VERSION}"
22+
RELEASE_URL="$(gh repo view --json url -q ".url")/releases/tag/${TARGET_TAG_NAME}"
23+
printf "## [${TARGET_TAG_NAME}](${RELEASE_URL}) - $(date -Idate)\n\n" >> "${TMP_CHGLOG}"
24+
cat "${REL_NOTES}" >> "${TMP_CHGLOG}"
25+
if [ -f "${CHGLOG_FILE}" ]; then
26+
printf "\n" | cat - "${CHGLOG_FILE}" >> "${TMP_CHGLOG}"
27+
fi
28+
mv "${TMP_CHGLOG}" "${CHGLOG_FILE}"
29+
30+
# push changes
31+
git config --global user.name 'github-actions[bot]'
32+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
33+
git add pyproject.toml "${CHGLOG_FILE}"
34+
COMMIT_MSG="chore: bump version to ${TARGET_VERSION} [skip ci]"
35+
git commit -m "${COMMIT_MSG}"
36+
git push origin main
37+
38+
# create GitHub release (incl. Git tag)
39+
gh release create "${TARGET_TAG_NAME}" -F "${REL_NOTES}"

.github/workflows/cd.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "Run CD"
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
# disable keyring (https://github.com/actions/runner-images/issues/6185):
8+
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
9+
10+
jobs:
11+
# To be enabled when we add docs
12+
# docs:
13+
# permissions:
14+
# contents: write
15+
# runs-on: ubuntu-latest
16+
# steps:
17+
# - uses: actions/checkout@v4
18+
# - uses: ./.github/actions/setup-poetry
19+
# - name: Build and push docs
20+
# run: poetry run mkdocs gh-deploy --force
21+
22+
code-checks:
23+
uses: ./.github/workflows/checks.yml
24+
pre-release-check:
25+
runs-on: ubuntu-latest
26+
outputs:
27+
TARGET_TAG_V: ${{ steps.version_check.outputs.TRGT_VERSION }}
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0 # for fetching tags, required for semantic-release
32+
- uses: ./.github/actions/setup-poetry
33+
- name: Check version of potential release
34+
id: version_check
35+
run: |
36+
TRGT_VERSION=$(poetry run semantic-release print-version)
37+
echo "TRGT_VERSION=${TRGT_VERSION}" >> $GITHUB_OUTPUT
38+
echo "${TRGT_VERSION}"
39+
- name: Check notes of potential release
40+
run: poetry run semantic-release changelog --unreleased
41+
release:
42+
needs: [code-checks, pre-release-check]
43+
if: needs.pre-release-check.outputs.TARGET_TAG_V != ''
44+
environment: auto-release
45+
runs-on: ubuntu-latest
46+
concurrency: release
47+
steps:
48+
- uses: actions/create-github-app-token@v1
49+
id: app-token
50+
with:
51+
app-id: ${{ vars.CI_APP_ID }}
52+
private-key: ${{ secrets.CI_PRIVATE_KEY }}
53+
- uses: actions/checkout@v4
54+
with:
55+
token: ${{ steps.app-token.outputs.token }}
56+
fetch-depth: 0 # for fetching tags, required for semantic-release
57+
- uses: ./.github/actions/setup-poetry
58+
- name: Run release script
59+
env:
60+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
61+
TARGET_VERSION: ${{ needs.pre-release-check.outputs.TARGET_TAG_V }}
62+
CHGLOG_FILE: CHANGELOG.md
63+
run: ./.github/scripts/release.sh
64+
shell: bash

.github/workflows/checks.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
on:
2+
workflow_call:
3+
4+
jobs:
5+
run-checks:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/setup-poetry
13+
with:
14+
python-version: ${{ matrix.python-version }}
15+
- name: Run styling check
16+
run: poetry run pre-commit run --all-files

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Run CI"
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
push:
7+
branches:
8+
- "**"
9+
- "!gh-pages"
10+
11+
env:
12+
# disable keyring (https://github.com/actions/runner-images/issues/6185):
13+
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
14+
15+
jobs:
16+
code-checks:
17+
if: ${{ github.event_name == 'push' || (github.event.pull_request.head.repo.full_name != 'DS4SD/docling-langchain' && github.event.pull_request.head.repo.full_name != 'ds4sd/docling-langchain') }}
18+
uses: ./.github/workflows/checks.yml
19+
20+
# To enable when we add the ./docs
21+
# build-docs:
22+
# runs-on: ubuntu-latest
23+
# steps:
24+
# - uses: actions/checkout@v4
25+
# - uses: ./.github/actions/setup-poetry
26+
# - name: Build docs
27+
# run: poetry run mkdocs build --verbose --clean

.github/workflows/pypi.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "Build and publish package"
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
10+
env:
11+
# disable keyring (https://github.com/actions/runner-images/issues/6185):
12+
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
13+
14+
jobs:
15+
build-and-publish:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: ./.github/actions/setup-poetry
20+
- name: Build and publish
21+
run: poetry publish --build --no-interaction --username=__token__ --password=${{ secrets.PYPI_TOKEN }}

0 commit comments

Comments
 (0)