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
52 changes: 52 additions & 0 deletions .github/workflows/e2e-images-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Cleanup E2E GHCR Images

on:
schedule:
- cron: "30 4 * * 0" # weekly, after rebuild
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
cleanup:
name: Prune old sha-tagged images
runs-on: ubuntu-latest
steps:
- name: Delete old sha-tagged package versions
env:
GH_TOKEN: ${{ github.token }}
PACKAGE_NAME: banmanager-e2e-tests
KEEP_SHA_VERSIONS: "20"
run: |
set -euo pipefail

OWNER="${GITHUB_REPOSITORY_OWNER}"
API_PATH="/orgs/${OWNER}/packages/container/${PACKAGE_NAME}/versions?per_page=100"

VERSIONS="$(gh api "$API_PATH")"

DELETE_IDS="$(echo "$VERSIONS" | jq -r --argjson keep "$KEEP_SHA_VERSIONS" '
map(
. as $v
| ($v.metadata.container.tags // []) as $tags
| select(($tags | index("main")) | not)
| select(($tags | length) > 0)
| select(($tags | all(test("^sha-"))))
)
| sort_by(.created_at) | reverse
| .[$keep:]
| .[].id
')"

if [[ -z "$DELETE_IDS" ]]; then
echo "No old sha-tagged versions to delete."
exit 0
fi

while read -r version_id; do
[[ -z "$version_id" ]] && continue
echo "Deleting package version ${version_id}"
gh api --method DELETE "/orgs/${OWNER}/packages/container/${PACKAGE_NAME}/versions/${version_id}"
done <<< "$DELETE_IDS"
57 changes: 57 additions & 0 deletions .github/workflows/e2e-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Publish E2E Test Runner Image

on:
push:
branches:
- master
paths:
- "e2e/Dockerfile.tests"
- "e2e/tests/package.json"
- "e2e/tests/package-lock.json"
- ".github/workflows/e2e-images.yml"
schedule:
- cron: "0 4 * * 0" # weekly rebuild
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish:
name: Publish GHCR E2E test image
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Compute image repository
id: vars
run: echo "image_repo=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/banmanager-e2e-tests" >> "$GITHUB_OUTPUT"

- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.vars.outputs.image_repo }}
tags: |
type=raw,value=main
type=sha,format=short,prefix=sha-

- name: Build and push test runner image
uses: docker/build-push-action@v6
with:
context: e2e
file: e2e/Dockerfile.tests
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=e2e-tests-runner
cache-to: type=gha,mode=max,scope=e2e-tests-runner
91 changes: 91 additions & 0 deletions .github/workflows/e2e-metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: E2E Metrics Snapshot

on:
workflow_dispatch:

permissions:
actions: read
contents: read

jobs:
snapshot:
name: Capture PR E2E metrics
runs-on: ubuntu-latest

steps:
- name: Collect latest 20 completed PR runs
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail

RUNS_JSON="$(gh api \
"repos/${GITHUB_REPOSITORY}/actions/workflows/e2e.yml/runs?event=pull_request&status=completed&per_page=100")"

SELECTED_RUNS="$(echo "$RUNS_JSON" | jq '
.workflow_runs
| map({
id,
html_url,
head_sha,
conclusion,
run_started_at,
updated_at,
duration_seconds: ((.updated_at | fromdateiso8601) - (.run_started_at | fromdateiso8601))
})
| sort_by(.run_started_at) | reverse
| .[:20]
')"

RUN_COUNT="$(echo "$SELECTED_RUNS" | jq 'length')"
if [[ "$RUN_COUNT" -lt 20 ]]; then
echo "Expected at least 20 completed pull_request runs for e2e.yml, found $RUN_COUNT." >&2
exit 1
fi

FAILURE_RATE="$(echo "$SELECTED_RUNS" | jq '
(map(select(.conclusion != "success")) | length) as $failures
| ($failures / length) * 100
')"

MEDIAN_DURATION="$(echo "$SELECTED_RUNS" | jq '
[.[].duration_seconds] | sort
| if (length % 2) == 1
then .[length / 2]
else ((.[(length / 2) - 1] + .[length / 2]) / 2)
end
')"

AVG_DURATION="$(echo "$SELECTED_RUNS" | jq '[.[].duration_seconds] | add / length')"

SNAPSHOT_FILE="e2e-metrics-snapshot.json"
jq -n \
--arg generated_at "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--argjson run_count "$RUN_COUNT" \
--argjson median_duration_seconds "$MEDIAN_DURATION" \
--argjson average_duration_seconds "$AVG_DURATION" \
--argjson failure_rate_percent "$FAILURE_RATE" \
--argjson runs "$SELECTED_RUNS" \
'{
generated_at,
run_count,
median_duration_seconds,
average_duration_seconds,
failure_rate_percent,
runs
}' > "$SNAPSHOT_FILE"

{
echo "## E2E PR Metrics (Latest 20 Runs)"
echo ""
echo "- Median duration: ${MEDIAN_DURATION}s"
echo "- Average duration: ${AVG_DURATION}s"
echo "- Failure rate: ${FAILURE_RATE}%"
} >> "$GITHUB_STEP_SUMMARY"

- name: Upload metrics snapshot
uses: actions/upload-artifact@v4
with:
name: e2e-metrics-snapshot
path: e2e-metrics-snapshot.json
retention-days: 30
Loading
Loading