Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,24 @@ workflows:
- ensure_formatting
- linter
- test
- deploy:
# Manual only: the upload to PyPI waits for an approval in CircleCI
- approve_deploy:
type: approval
requires:
- build
filters:
tags:
only: /[0-9]+(\.[0-9]+)+(\.[0-9]+)?\.?(\w)*/
branches:
ignore: /.*/
- deploy:
requires:
- approve_deploy
filters:
tags:
only: /[0-9]+(\.[0-9]+)+(\.[0-9]+)?\.?(\w)*/
branches:
ignore: /.*/
- notify_rolling:
requires:
- build
Expand Down
9 changes: 9 additions & 0 deletions .github/actions/checkout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Checkout Repository
description: Checkout the repository using a pinned version of actions/checkout

runs:
using: composite
steps:
# https://github.com/actions/checkout/releases/#release-v7.0.1
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
27 changes: 27 additions & 0 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Setup Python Environment
description: Configure Python and install project development dependencies

inputs:
python-version:
description: Python version to use
required: false
default: "3.13"

runs:
using: composite
steps:
# https://github.com/actions/setup-python/releases#release-v7.1.0
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ inputs.python-version }}
cache: pip
cache-dependency-path: pyproject.toml

- name: Update pip
shell: bash
run: python -m pip install --upgrade pip certifi

- name: Install development dependencies
shell: bash
run: python -m pip install ".[dev]"
47 changes: 47 additions & 0 deletions .github/workflows/ci-lint-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Lint & Format

on:
workflow_call:

permissions:
contents: read

jobs:
ensure_formatting:
name: Ensure Formatting
runs-on: ubuntu-24.04
timeout-minutes: 5

steps:
- name: Checkout Repository
uses: $/.github/actions/checkout

- name: Setup Python Environment
uses: $/.github/actions/setup-python

- name: Confirm Black version
run: black --version

- name: Check isort
run: isort --check-only --diff .

- name: Check Black
run: black --check --diff .

linter:
name: Linter
runs-on: ubuntu-24.04
timeout-minutes: 5

steps:
- name: Checkout Repository
uses: $/.github/actions/checkout

- name: Setup Python Environment
uses: $/.github/actions/setup-python

- name: Install flake8
run: python -m pip install flake8

- name: Run Flake8
run: flake8 --ignore=E,W .
277 changes: 277 additions & 0 deletions .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
name: "[Client Python] CI"

on:
push:
branches:
- "main"
tags:
- "*"

pull_request:

workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# ──────────────────────────────────────────────────────────────────
# Lint & Format
# ──────────────────────────────────────────────────────────────────
lint-format:
name: Lint - Format
uses: $/.github/workflows/ci-lint-format.yml

# ──────────────────────────────────────────────────────────────────
# Tests
# ──────────────────────────────────────────────────────────────────
tests:
name: Tests
runs-on: ubuntu-24.04
timeout-minutes: 10

steps:
- name: Checkout Repository
uses: $/.github/actions/checkout

- name: Setup Python Environment
uses: $/.github/actions/setup-python

- name: Run Tests
run: python -m pytest

# ──────────────────────────────────────────────────────────────────
# Build
# ──────────────────────────────────────────────────────────────────
build:
name: Build
runs-on: ubuntu-24.04
timeout-minutes: 10

needs:
- lint-format
- tests

steps:
- name: Checkout Repository
uses: $/.github/actions/checkout

- name: Setup Python Environment
uses: $/.github/actions/setup-python

- name: Check Version
if: startsWith(github.ref, 'refs/tags/')
shell: bash
run: |
package_version="$(
python -c 'import pyoaev; print(pyoaev.__version__)'
)"

tag_version="${GITHUB_REF_NAME}"
if [ "${tag_version}" != "${package_version}" ]; then
echo "::error::Version mismatch: Git tag version '${tag_version}' does not match package version '${package_version}'."
exit 1
fi

- name: Build Package
run: |
SOURCE_DATE_EPOCH="$(git log -1 --pretty=%ct)" \
python -m build

# https://github.com/actions/upload-artifact/releases/tag/v7.0.2
- name: Upload Package
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: pyoaev-dist
path: dist/
if-no-files-found: error
retention-days: 14

# ──────────────────────────────────────────────────────────────────
# Pipeline Gate
# Required branch-protection check: "Pipeline Gate"
# Fails if any mandatory upstream job did not succeed.
# ──────────────────────────────────────────────────────────────────
pipeline-gate:
name: "Pipeline Gate"
needs:
- lint-format
- tests
- build
if: ${{ always() }}
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
actions: read

steps:
- name: Check all upstream job results
env:
NEEDS_JSON: ${{ toJSON(needs) }}
GH_TOKEN: ${{ github.token }}
GH_REPOSITORY: ${{ github.repository }}
GH_RUN_ID: ${{ github.run_id }}
GH_API_URL: ${{ github.api_url }}
run: |
set -euo pipefail

FAILED=0
TOTAL=0

echo "══════════════════════════════════════════════════"
echo " 🔎 Upstream Job Results"
echo "══════════════════════════════════════════════════"
echo ""

# Retrieve actual job timestamps from GitHub API
JOBS_JSON=$(curl -fsSL \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"$GH_API_URL/repos/$GH_REPOSITORY/actions/runs/$GH_RUN_ID/jobs?per_page=100")

# Initialize GitHub Actions Summary
{
echo "## Upstream Job Results"
echo ""
echo "| Job | Started | Finished | Duration | Status |"
echo "|---|---|---|---|---|"
} >> "$GITHUB_STEP_SUMMARY"

# Dynamically iterate over all jobs declared in needs
for job in $(jq -r 'keys[]' <<< "$NEEDS_JSON"); do
result=$(jq -r --arg j "$job" '.[$j].result' <<< "$NEEDS_JSON")
TOTAL=$((TOTAL + 1))

case "$result" in
success)
icon="✅"
status="Passed"
;;
skipped)
icon="⏭️"
status="Skipped"
FAILED=$((FAILED + 1))
;;
failure)
icon="❌"
status="Failed"
FAILED=$((FAILED + 1))
;;
cancelled)
icon="🚫"
status="Cancelled"
FAILED=$((FAILED + 1))
;;
*)
icon="❓"
status="Unknown"
FAILED=$((FAILED + 1))
;;
esac

started_at=""
finished_at=""
started="—"
finished="—"
duration="—"

job_data=$(jq -c \
--arg name "$job" \
'
def normalize:
ascii_downcase
| gsub("[^a-z0-9]+"; "-")
| gsub("(^-+|-+$)"; "");

($name | normalize) as $target |

[
.jobs[]
| select(
(.name | normalize) == $target
or
(.name | normalize | startswith($target + "-"))
)
] as $matches |

if ($matches | length) == 0 then
empty
else
{
started_at: (
[$matches[].started_at | select(. != null)]
| sort
| first // null
),
completed_at: (
[$matches[].completed_at | select(. != null)]
| sort
| last // null
)
}
end
' <<< "$JOBS_JSON")

if [[ -n "$job_data" ]]; then
started_at=$(jq -r '.started_at // empty' <<< "$job_data")
finished_at=$(jq -r '.completed_at // empty' <<< "$job_data")
fi

# Format start timestamp
if [[ -n "$started_at" ]]; then
started=$(date -u -d "$started_at" '+%Y-%m-%d %H:%M:%S UTC')
fi

# Format finish timestamp
if [[ -n "$finished_at" ]]; then
finished=$(date -u -d "$finished_at" '+%Y-%m-%d %H:%M:%S UTC')
fi

# Calculate job duration
if [[ -n "$started_at" && -n "$finished_at" ]]; then
start_epoch=$(date -u -d "$started_at" +%s)
finish_epoch=$(date -u -d "$finished_at" +%s)
duration_seconds=$((finish_epoch - start_epoch))

duration=$(printf '%02dm %02ds' \
$((duration_seconds / 60)) \
$((duration_seconds % 60)))
fi

# Display result in workflow logs
printf " %s %-30s %s\n" "$icon" "$job" "$result"

# Add result to GitHub Actions Summary
printf "| %s %s | %s | %s | %s | %s |\n" \
"$icon" "$job" "$started" "$finished" "$duration" "$status" \
>> "$GITHUB_STEP_SUMMARY"

done

echo ""
echo "══════════════════════════════════════════════════"

if [[ "$FAILED" -gt 0 ]]; then
echo "❌ Gate failed: $FAILED/$TOTAL job(s) did not succeed."

{
echo ""
echo "**❌ Gate failed: $FAILED/$TOTAL required job(s) did not succeed.**"
} >> "$GITHUB_STEP_SUMMARY"

exit 1
fi

echo "✅ All $TOTAL upstream jobs succeeded."
echo "✅ Pipeline Gate passed."

{
echo ""
echo "**✅ All $TOTAL upstream jobs succeeded.**"
echo ""
echo "### Pipeline Gate: Passed"
} >> "$GITHUB_STEP_SUMMARY"
Loading
Loading