Skip to content

Commit d5473e6

Browse files
authored
Merge pull request #18 from generative-computing/test-ci-workflow
test: ci automation
2 parents c8bd9a1 + 49dd106 commit d5473e6

26 files changed

+2443
-447
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Free Disk Space'
2+
description: 'Frees disk space on the runner'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Print disk space before cleanup
7+
run: |
8+
df -h
9+
shell: bash
10+
- name: Free Disk Space Linux
11+
if: runner.os == 'Linux'
12+
run: |
13+
sudo docker rmi "$(docker image ls -aq)" >/dev/null 2>&1 || true
14+
sudo rm -rf \
15+
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
16+
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
17+
/usr/lib/jvm || true
18+
sudo apt install aptitude -y >/dev/null 2>&1
19+
sudo aptitude purge '~n ^mysql' -f -y >/dev/null 2>&1
20+
sudo aptitude purge '~n ^dotnet' -f -y >/dev/null 2>&1
21+
sudo apt-get autoremove -y >/dev/null 2>&1
22+
sudo apt-get autoclean -y >/dev/null 2>&1
23+
shell: bash
24+
- name: Print disk space after cleanup
25+
run: |
26+
df -h
27+
shell: bash

.mergify.yml renamed to .github/mergify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ merge_protections:
55
- base = main
66
success_conditions:
77
- "title ~=
8-
^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\\(.+\
8+
^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|release)(?:\\(.+\
99
\\))?:"

.github/scripts/release.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 mellea-contribs
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+
35+
# Configure the remote with the token
36+
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
37+
38+
git add pyproject.toml uv.lock "${CHGLOG_FILE}"
39+
COMMIT_MSG="chore: bump version to ${TARGET_VERSION} [skip ci]"
40+
git commit -m "${COMMIT_MSG}"
41+
git push origin main
42+
43+
# create GitHub release (incl. Git tag)
44+
gh release create "${TARGET_TAG_NAME}" -F "${REL_NOTES}"

.github/workflows/cd.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "Run CD"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
force_release:
7+
description: 'Force release even if previous checks fail.'
8+
type: boolean
9+
required: false
10+
default: false
11+
12+
env:
13+
UV_FROZEN: "1"
14+
CICD: 1
15+
16+
jobs:
17+
code-checks:
18+
uses: ./.github/workflows/quality.yml
19+
pre-release-check:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
TARGET_TAG_V: ${{ steps.version_check.outputs.TRGT_VERSION }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0 # for fetching tags, required for semantic-release
27+
- name: Install uv and set the python version
28+
uses: astral-sh/setup-uv@v5
29+
with:
30+
enable-cache: true
31+
- name: Install dependencies
32+
run: uv sync --only-dev
33+
- name: Check version of potential release
34+
id: version_check
35+
run: |
36+
TRGT_VERSION=$(uv run --no-sync 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: uv run --no-sync semantic-release changelog --unreleased
41+
release:
42+
needs: [code-checks, pre-release-check]
43+
# Run this job only if the `TARGET_TAG_V` is set AND (the previous jobs
44+
# were successful OR we are forcing the release).
45+
if: >-
46+
${{ needs.pre-release-check.outputs.TARGET_TAG_V != '' &&
47+
( success() || inputs.force_release ) }}
48+
environment: auto-release
49+
runs-on: ubuntu-latest
50+
concurrency: release
51+
steps:
52+
- uses: actions/create-github-app-token@v1
53+
id: app-token
54+
with:
55+
app-id: ${{ vars.CI_APP_ID }}
56+
private-key: ${{ secrets.CI_PRIVATE_KEY }}
57+
- uses: actions/checkout@v4
58+
with:
59+
token: ${{ steps.app-token.outputs.token }}
60+
fetch-depth: 0 # for fetching tags, required for semantic-release
61+
- name: Install uv and set the python version
62+
uses: astral-sh/setup-uv@v5
63+
with:
64+
enable-cache: true
65+
- name: Install dependencies
66+
run: uv sync --only-dev
67+
- name: Run release script
68+
env:
69+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
70+
TARGET_VERSION: ${{ needs.pre-release-check.outputs.TARGET_TAG_V }}
71+
CHGLOG_FILE: CHANGELOG.md
72+
GITHUB_REPOSITORY: ${{ github.repository }}
73+
run: ./.github/scripts/release.sh
74+
shell: bash

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "Run CI"
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
code-checks:
9+
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.12']
19+
environment:
20+
name: pypi
21+
url: https://pypi.org/project/mellea-contribs/
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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Verify Code Quality
2+
3+
on:
4+
workflow_call:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref_name }}
8+
cancel-in-progress: true
9+
10+
env:
11+
CICD: 1
12+
OLLAMA_HOST: "127.0.0.1:5000"
13+
14+
jobs:
15+
quality:
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 90
18+
strategy:
19+
matrix:
20+
python-version: ["3.10", "3.11", "3.12"]
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Free disk space
24+
uses: ./.github/actions/free-disk-space
25+
- name: Install uv and set the python version
26+
uses: astral-sh/setup-uv@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
enable-cache: true
30+
- name: Install mellea from main branch
31+
run: uv pip install git+https://github.com/generative-computing/mellea.git@main
32+
# TODO: Enable pre-commit once code quality issues are fixed
33+
# - name: pre-commit cache key
34+
# run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> "$GITHUB_ENV"
35+
# - uses: actions/cache@v4
36+
# with:
37+
# path: ~/.cache/pre-commit
38+
# key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
39+
- name: Install dependencies
40+
run: uv sync --frozen --all-extras --group dev
41+
# - name: Check style and run tests
42+
# run: pre-commit run --all-files
43+
# - name: Send failure message pre-commit
44+
# if: failure()
45+
# run: echo "The quality verification failed. Please run precommit "
46+
- name: Install Ollama
47+
run: curl -fsSL https://ollama.com/install.sh | sh
48+
- name: Start serving ollama
49+
run: nohup ollama serve &
50+
- name: Pull model granite4:micro
51+
run: ollama pull granite4:micro
52+
- name: Run Tests
53+
run: uv run -m pytest -v test
54+
- name: Send failure message tests
55+
if: failure()
56+
run: echo "Tests failed. Please verify that tests are working locally."

0 commit comments

Comments
 (0)