Skip to content

Commit 52c20e2

Browse files
committed
ci: Adding ci/cd scripts
1 parent b6235c4 commit 52c20e2

File tree

5 files changed

+171
-7
lines changed

5 files changed

+171
-7
lines changed

.github/scripts/release.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version "${TARGET_VERSION}"
14+
UV_FROZEN=0 uv lock --upgrade-package docling
15+
16+
# collect release notes
17+
REL_NOTES=$(mktemp)
18+
uv run --no-sync semantic-release changelog --unreleased >> "${REL_NOTES}"
19+
20+
# update changelog
21+
TMP_CHGLOG=$(mktemp)
22+
TARGET_TAG_NAME="v${TARGET_VERSION}"
23+
RELEASE_URL="$(gh repo view --json url -q ".url")/releases/tag/${TARGET_TAG_NAME}"
24+
printf "## [${TARGET_TAG_NAME}](${RELEASE_URL}) - $(date -Idate)\n\n" >> "${TMP_CHGLOG}"
25+
cat "${REL_NOTES}" >> "${TMP_CHGLOG}"
26+
if [ -f "${CHGLOG_FILE}" ]; then
27+
printf "\n" | cat - "${CHGLOG_FILE}" >> "${TMP_CHGLOG}"
28+
fi
29+
mv "${TMP_CHGLOG}" "${CHGLOG_FILE}"
30+
31+
# push changes
32+
git config --global user.name 'github-actions[bot]'
33+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
34+
git add pyproject.toml uv.lock "${CHGLOG_FILE}"
35+
COMMIT_MSG="chore: bump version to ${TARGET_VERSION} [skip ci]"
36+
git commit -m "${COMMIT_MSG}"
37+
git push origin main
38+
39+
# create GitHub release (incl. Git tag)
40+
gh release create "${TARGET_TAG_NAME}" -F "${REL_NOTES}"

.github/workflows/cd.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Run CD"
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
UV_FROZEN: "1"
8+
CICD: 1
9+
10+
jobs:
11+
code-checks:
12+
uses: ./.github/workflows/quality.yml
13+
# with:
14+
# push_coverage: false
15+
pre-release-check:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
TARGET_TAG_V: ${{ steps.version_check.outputs.TRGT_VERSION }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0 # for fetching tags, required for semantic-release
23+
- name: Install uv and set the python version
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
enable-cache: true
27+
- name: Install dependencies
28+
run: uv sync --only-dev
29+
- name: Check version of potential release
30+
id: version_check
31+
run: |
32+
TRGT_VERSION=$(uv run --no-sync semantic-release print-version)
33+
echo "TRGT_VERSION=${TRGT_VERSION}" >> "$GITHUB_OUTPUT"
34+
echo "${TRGT_VERSION}"
35+
- name: Check notes of potential release
36+
run: uv run --no-sync semantic-release changelog --unreleased
37+
release:
38+
needs: [code-checks, pre-release-check]
39+
if: needs.pre-release-check.outputs.TARGET_TAG_V != ''
40+
environment: auto-release
41+
runs-on: ubuntu-latest
42+
concurrency: release
43+
steps:
44+
- uses: actions/create-github-app-token@v1
45+
id: app-token
46+
with:
47+
app-id: ${{ vars.CI_APP_ID }}
48+
private-key: ${{ secrets.CI_PRIVATE_KEY }}
49+
- uses: actions/checkout@v4
50+
with:
51+
token: ${{ steps.app-token.outputs.token }}
52+
fetch-depth: 0 # for fetching tags, required for semantic-release
53+
- name: Install uv and set the python version
54+
uses: astral-sh/setup-uv@v5
55+
with:
56+
enable-cache: true
57+
- name: Install dependencies
58+
run: uv sync --only-dev
59+
- name: Run release script
60+
env:
61+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
62+
TARGET_VERSION: ${{ needs.pre-release-check.outputs.TARGET_TAG_V }}
63+
CHGLOG_FILE: CHANGELOG.md
64+
run: ./.github/scripts/release.sh
65+
shell: bash

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "Run CI"
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
push:
7+
branches:
8+
- "**"
9+
- "!main"
10+
- "!gh-pages"
11+
12+
jobs:
13+
code-checks:
14+
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'generative-computing/mellea' || github.event.pull_request.head.repo.full_name == 'generative-computing/mellea' }}
15+
uses: ./.github/workflows/quality.yml

.github/workflows/pypi.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Build and publish package"
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
UV_FROZEN: "1"
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
build-and-publish:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ['3.10','3.11','3.12']
19+
environment:
20+
name: pypi
21+
url: https://pypi.org/project/mellea/
22+
permissions:
23+
id-token: write # IMPORTANT: mandatory for trusted publishing
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Install uv and set the python version
27+
uses: astral-sh/setup-uv@v5
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
enable-cache: true
31+
- name: Install dependencies
32+
run: uv sync --all-extras
33+
- name: Build package
34+
run: uv build
35+
- name: Publish distribution 📦 to PyPI
36+
uses: pypa/gh-action-pypi-publish@release/v1
37+
with:
38+
attestations: true

.github/workflows/quality.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
name: Verify Code Quality
22

33
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
4+
workflow_call:
5+
# inputs:
6+
# push_coverage:
7+
# type: boolean
8+
# description: "If true, the coverage results are pushed to codecov.io."
9+
# default: true
10+
# secrets:
11+
# CODECOV_TOKEN:
12+
# required: false
813

914
concurrency:
1015
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref_name }}
1116
cancel-in-progress: true
1217

18+
env:
19+
CICD: 1
20+
OLLAMA_HOST: "127.0.0.1:5000"
21+
1322
jobs:
1423
quality:
1524
runs-on: ubuntu-latest
1625
timeout-minutes: 30
1726
strategy:
1827
matrix:
1928
python-version: ['3.10', '3.11', '3.12'] # Need to add 3.13 once we resolve outlines issues.
20-
env:
21-
CICD: 1
22-
OLLAMA_HOST: "127.0.0.1:5000"
2329
steps:
2430
- uses: actions/checkout@v4
2531
- name: Install uv and set the python version

0 commit comments

Comments
 (0)