GRM-51: refactor: convert shell scripts and inline workflow scripts to Python

This commit is contained in:
2026-06-22 05:53:31 +00:00
parent bec7b59671
commit b6e87a519b
28 changed files with 1582 additions and 219 deletions
+14 -65
View File
@@ -13,12 +13,6 @@ jobs:
- uses: actions/checkout@v4
- name: Set up environment
run: make setup
- name: Install actionlint
run: |
set -euo pipefail
mkdir -p "$HOME/.local/bin"
bash <(curl -sL https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) latest "$HOME/.local/bin"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Lint all
run: |
. .venv/bin/activate
@@ -48,21 +42,10 @@ jobs:
fetch-depth: 0
- name: Set up environment
run: make setup
- name: Install git-cliff
run: |
set -euo pipefail
GIT_CLIFF_VERSION="2.13.0"
URL="https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
TMPDIR="$(mktemp -d)"
curl -sL "$URL" | tar xz -C "$TMPDIR"
mkdir -p "$HOME/.local/bin"
mv "$TMPDIR/git-cliff-${GIT_CLIFF_VERSION}/git-cliff" "$HOME/.local/bin/git-cliff"
chmod +x "$HOME/.local/bin/git-cliff"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Release dry-run validation
run: |
set -euo pipefail
. .venv/bin/activate
export PATH="$HOME/.local/bin:$PATH"
PYTHONPATH=. python3 scripts/ci/release.py --dry-run || true
detect-changes:
@@ -82,27 +65,11 @@ jobs:
env:
PYTHONPATH: src
run: |
set -euo pipefail
. .venv/bin/activate
BASE="origin/master"
HEAD="${{ github.event.pull_request.head.sha || github.sha }}"
# Use classify_changes.py for consistent file classification
ANSIBLE_RESULT=$(python3 scripts/ci/classify_changes.py --base "$BASE" --head "$HEAD" --check ansible --quiet)
if [ "$ANSIBLE_RESULT" = "true" ]; then
echo "ansible-changed=true" >> "$GITHUB_OUTPUT"
echo "Ansible files changed — molecule tests will run."
else
echo "ansible-changed=false" >> "$GITHUB_OUTPUT"
echo "No Ansible files changed — skipping molecule tests."
fi
USER_FACING_RESULT=$(python3 scripts/ci/classify_changes.py --base "$BASE" --head "$HEAD" --check user-facing --quiet)
if [ "$USER_FACING_RESULT" = "true" ]; then
echo "user-facing-changed=true" >> "$GITHUB_OUTPUT"
echo "User-facing files changed — release dry-run will run."
else
echo "user-facing-changed=false" >> "$GITHUB_OUTPUT"
echo "No user-facing files changed — skipping release dry-run."
fi
python3 scripts/ci/classify_changes.py \
--base "origin/master" \
--head "${{ github.event.pull_request.head.sha || github.sha }}" \
--github-output
discover-runners:
needs: [detect-changes]
@@ -123,15 +90,11 @@ jobs:
MOLECULE_RUNNERS: ${{ vars.MOLECULE_RUNNERS }}
PYTHONPATH: src
run: |
set -euo pipefail
. .venv/bin/activate
OUTPUT=$(python3 scripts/ci/discover_runners.py --owner "${{ github.repository_owner }}" --repo "${{ github.event.repository.name }}")
echo "$OUTPUT"
# Parse outputs
RUNNER_COUNT=$(echo "$OUTPUT" | grep '^count=' | cut -d= -f2)
RUNNER_INDICES=$(echo "$OUTPUT" | grep '^indices=' | cut -d= -f2)
echo "runner-count=$RUNNER_COUNT" >> "$GITHUB_OUTPUT"
echo "runner-indices=$RUNNER_INDICES" >> "$GITHUB_OUTPUT"
python3 scripts/ci/discover_runners.py \
--owner "${{ github.repository_owner }}" \
--repo "${{ github.event.repository.name }}" \
--github-output
molecule-tests:
needs: [quality, detect-changes, discover-runners]
@@ -150,30 +113,16 @@ jobs:
RUNNER_INDEX: ${{ matrix.runner-index }}
MAX_RUNNERS: ${{ needs.discover-runners.outputs.runner-count }}
run: |
set -euo pipefail
. .venv/bin/activate
echo "Runner index: $RUNNER_INDEX"
echo "Max runners: $MAX_RUNNERS"
# Skip if runner index exceeds available runners
if [ "$RUNNER_INDEX" -gt "$MAX_RUNNERS" ]; then
echo "Skipping — runner index $RUNNER_INDEX > max runners $MAX_RUNNERS"
echo "TEST_PAIRS=" >> "$GITHUB_ENV"
echo "SKIP=true" >> "$GITHUB_ENV"
exit 0
fi
PAIRS=$(python3 scripts/ci/distribute_molecule.py --runner-index "$RUNNER_INDEX" --max-runners "$MAX_RUNNERS")
echo "Assigned pairs: $PAIRS"
echo "TEST_PAIRS=$PAIRS" >> "$GITHUB_ENV"
echo "SKIP=false" >> "$GITHUB_ENV"
python3 scripts/ci/distribute_molecule.py \
--runner-index "$RUNNER_INDEX" \
--max-runners "$MAX_RUNNERS" \
--github-env --skip-if-excess
- name: Run molecule tests
if: env.SKIP != 'true'
run: |
set -euo pipefail
. .venv/bin/activate
if [ -z "$TEST_PAIRS" ]; then
echo "No test pairs assigned — skipping"
exit 0
fi
if [ -z "$TEST_PAIRS" ]; then exit 0; fi
# shellcheck disable=SC2086 # intentional word splitting for argument expansion
python3 scripts/ci/molecule_ci_guard.py $TEST_PAIRS
env:
+6 -55
View File
@@ -30,17 +30,7 @@ jobs:
fetch-depth: 1
- name: Check if this is a release commit
id: check
run: |
set -euo pipefail
MSG=$(git log -1 --pretty=%s)
echo "Commit message: $MSG"
if echo "$MSG" | grep -qE '^release: v[0-9]+\.[0-9]+\.[0-9]+'; then
echo "is-release=true" >> "$GITHUB_OUTPUT"
echo "Release commit — skipping all post-merge jobs."
else
echo "is-release=false" >> "$GITHUB_OUTPUT"
echo "Regular merge commit — running all post-merge jobs."
fi
run: python3 scripts/ci/detect_release_commit.py
release:
needs: [detect-type]
@@ -54,29 +44,16 @@ jobs:
token: ${{ secrets.REPO_TOKEN }}
- name: Set up environment
run: make setup
- name: Install git-cliff
run: |
set -euo pipefail
GIT_CLIFF_VERSION="2.13.0"
URL="https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
TMPDIR="$(mktemp -d)"
curl -sL "$URL" | tar xz -C "$TMPDIR"
mkdir -p "$HOME/.local/bin"
mv "$TMPDIR/git-cliff-${GIT_CLIFF_VERSION}/git-cliff" "$HOME/.local/bin/git-cliff"
chmod +x "$HOME/.local/bin/git-cliff"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
"$HOME/.local/bin/git-cliff" --version
- name: Configure git
run: |
set -euo pipefail
git config user.name "grm-ci-bot"
git config user.email "grm-ci-bot@oblachno.fyi"
- name: Run release
env:
PYTHONPATH: .
run: |
set -euo pipefail
. .venv/bin/activate
export PATH="$HOME/.local/bin:$PATH"
python3 scripts/ci/release.py
- name: Notify on failure
if: failure()
@@ -84,7 +61,6 @@ jobs:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
python3 scripts/ci/notify_failure.py \
--repo "${{ github.repository }}" \
--run-id "${{ github.run_id }}" \
@@ -107,7 +83,6 @@ jobs:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
. .venv/bin/activate
python3 scripts/ci/sync_wiki.py --repo "${{ github.repository }}" --strict
- name: Notify on failure
@@ -116,7 +91,6 @@ jobs:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
python3 scripts/ci/notify_failure.py \
--repo "${{ github.repository }}" \
--run-id "${{ github.run_id }}" \
@@ -135,36 +109,18 @@ jobs:
token: ${{ secrets.REPO_TOKEN }}
- name: Set up environment
run: make setup
- name: Generate badge SVG files
run: |
set -euo pipefail
. .venv/bin/activate
python3 scripts/generate_badges.py --output-dir .badges/
# Verify badges were generated
if [ -z "$(ls -A .badges/ 2>/dev/null)" ]; then
echo "::error::No badge SVG files generated"
exit 1
fi
- name: Push badges to badges branch
- name: Generate and push badges
env:
PRE_COMMIT_ALLOW_NO_CONFIG: "1"
run: |
set -euo pipefail
git config user.name "gitea-actions-bot"
git config user.email "actions@oblachno.fyi"
git checkout --orphan badges
git rm -rf .
cp -r .badges/* .
git add ./*.svg
git commit --no-verify -m "Update badges [skip ci]"
git push origin badges --force
. .venv/bin/activate
python3 scripts/ci/push_badges.py
- name: Notify on failure
if: failure()
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
python3 scripts/ci/notify_failure.py \
--repo "${{ github.repository }}" \
--run-id "${{ github.run_id }}" \
@@ -186,18 +142,13 @@ jobs:
env:
VIKUNJA_TOKEN: ${{ secrets.VIKUNJA_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
python3 scripts/ci/post_merge.py \
"$(git log -1 --pretty=%B)" \
--commit-sha "$(git rev-parse HEAD)"
run: python3 scripts/ci/post_merge.py --from-git
- name: Notify on failure
if: failure()
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
python3 scripts/ci/notify_failure.py \
--repo "${{ github.repository }}" \
--run-id "${{ github.run_id }}" \
+4 -23
View File
@@ -13,35 +13,17 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install git-cliff
run: |
set -euo pipefail
GIT_CLIFF_VERSION="2.13.0"
URL="https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
TMPDIR="$(mktemp -d)"
curl -sL "$URL" | tar xz -C "$TMPDIR"
mkdir -p "$HOME/.local/bin"
mv "$TMPDIR/git-cliff-${GIT_CLIFF_VERSION}/git-cliff" "$HOME/.local/bin/git-cliff"
chmod +x "$HOME/.local/bin/git-cliff"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
"$HOME/.local/bin/git-cliff" --version
- name: Install CI tools
run: python3 scripts/install_tools.py --tool git-cliff
- name: Install build tools
run: |
set -euo pipefail
python3 -m pip install --break-system-packages build twine requests python-dotenv click
- name: Validate PYPI_TOKEN
run: |
set -euo pipefail
if [ -z "${{ secrets.PYPI_TOKEN }}" ]; then
echo "::warning::PYPI_TOKEN is not set — package will be built but not published to PyPI."
fi
run: python3 -m pip install --break-system-packages build twine requests python-dotenv click
- name: Build and publish release
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
export PATH="$HOME/.local/bin:$PATH"
python3 scripts/ci/publish.py \
"${{ github.ref_name }}" \
"${{ github.repository }}"
@@ -51,7 +33,6 @@ jobs:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PYTHONPATH: src
run: |
set -euo pipefail
python3 scripts/ci/notify_failure.py \
--repo "${{ github.repository }}" \
--run-id "${{ github.run_id }}" \