Skip to content

Commit 4e5dbdf

Browse files
dolfim-ibmvagenas
andauthored
ci: add cicd (#1)
* single source of version Signed-off-by: Michele Dolfi <[email protected]> * add cicd Signed-off-by: Michele Dolfi <[email protected]> * apply pre-commit validators Signed-off-by: Michele Dolfi <[email protected]> * Update pyproject.toml Co-authored-by: Panos Vagenas <[email protected]> Signed-off-by: Michele Dolfi <[email protected]> * update lock Signed-off-by: Michele Dolfi <[email protected]> --------- Signed-off-by: Michele Dolfi <[email protected]> Signed-off-by: Michele Dolfi <[email protected]> Co-authored-by: Panos Vagenas <[email protected]>
1 parent 656f563 commit 4e5dbdf

File tree

9 files changed

+464
-2
lines changed

9 files changed

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

.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@v3
19+
- uses: ./.github/actions/setup-poetry
20+
- name: Build and publish
21+
run: poetry publish --build --no-interaction --username=__token__ --password=${{ secrets.PYPI_TOKEN }}

docling_core/search/package.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"""Models and methods to define a package model."""
77

8+
import importlib.metadata
89
import re
910
from typing import Final
1011

@@ -27,7 +28,7 @@ class Package(BaseModel, extra="forbid"):
2728

2829
name: StrictStr
2930
version: Annotated[str, StringConstraints(strict=True, pattern=VERSION_PATTERN)] = (
30-
"0.3.0"
31+
importlib.metadata.version("docling-core")
3132
)
3233

3334
def __hash__(self):

0 commit comments

Comments
 (0)