Skip to content
Closed
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
108 changes: 108 additions & 0 deletions .github/scripts/publish-preflight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash
# Publish preflight (#922): refuse to release a commit unless every required
# lane passed on it.
#
# A lane is a workflow, named as GitHub shows it (e.g. "Go Build CI"). Workflow
# names are used rather than job names because job names are not unique: both
# go.yml and the cluster lane have a job called "build".
#
# For each lane, the most recent run of that workflow on SHA that actually ran
# its jobs must have completed with conclusion "success". Release-gate lanes
# skip their job on ordinary PRs, so a run with a skipped job is passed over
# and an older run on SHA decides. A lane with no such run on SHA, or with any
# other conclusion, refuses the release. A lane still running is waited for,
# since releases are usually created right after the merge whose lanes are
# still running; if it has not finished within PREFLIGHT_WAIT_SECONDS the
# release is refused.
#
# REPO owner/name, e.g. metrico/gigapipe
# SHA the commit being released
# PUBLISH_REQUIRED_LANES workflow names, one per line
# GH_TOKEN token for the GitHub API (actions: read)
# PREFLIGHT_WAIT_SECONDS how long to wait for running lanes (default 1800)
# PREFLIGHT_POLL_SECONDS how often to check them (default 30)
set -euo pipefail

: "${REPO:?}" "${SHA:?}" "${PUBLISH_REQUIRED_LANES:?no lanes configured}"
wait_seconds="${PREFLIGHT_WAIT_SECONDS:-1800}"
poll_seconds="${PREFLIGHT_POLL_SECONDS:-30}"

lanes=()
while IFS= read -r lane; do
lane="${lane#"${lane%%[![:space:]]*}"}"
lane="${lane%"${lane##*[![:space:]]}"}"
[ -n "$lane" ] && lanes+=("$lane")
done <<<"$PUBLISH_REQUIRED_LANES"
if [ "${#lanes[@]}" -eq 0 ]; then
echo "::error::refusing to publish ${SHA}: no lanes configured"
exit 1
fi

# check_lanes prints one line per lane and sets failed (a lane is missing or
# did not pass) and running (a lane has not finished yet).
check_lanes() {
local runs lane_runs latest run status conclusion url skipped
runs=$(gh api --paginate "repos/${REPO}/actions/runs?head_sha=${SHA}&per_page=100" \
--jq '.workflow_runs[] | {id, name, status, conclusion, created_at, html_url}' | jq -s .)
failed=0
running=0
for lane in "${lanes[@]}"; do
# Newest first; the first run that isn't a skipped no-op decides.
lane_runs=$(jq -c --arg lane "$lane" \
'[.[] | select(.name == $lane)] | sort_by(.created_at) | reverse | .[]' <<<"$runs")
latest=""
while IFS= read -r run; do
[ -n "$run" ] || continue
if [ "$(jq -r .status <<<"$run")" = "completed" ]; then
skipped=$(gh api --paginate "repos/${REPO}/actions/runs/$(jq -r .id <<<"$run")/jobs?per_page=100" \
--jq '.jobs[] | select(.conclusion == "skipped") | .name' | wc -l)
if [ "$skipped" -gt 0 ]; then
echo "lane \"$lane\": skipping $(jq -r .html_url <<<"$run") (its job was skipped, not run)"
continue
fi
fi
latest=$run
break
done <<<"$lane_runs"
if [ -z "$latest" ]; then
echo "::error::lane \"$lane\" has no run on ${SHA} that ran its jobs; start it by hand (Actions, \"$lane\", Run workflow) on the released branch"
failed=1
continue
fi
status=$(jq -r .status <<<"$latest")
conclusion=$(jq -r .conclusion <<<"$latest")
url=$(jq -r .html_url <<<"$latest")
if [ "$status" != "completed" ]; then
echo "lane \"$lane\" is still running on ${SHA} (status=${status}): ${url}"
running=1
elif [ "$conclusion" = "cancelled" ]; then
# A push run that a newer push replaced while it waited ends cancelled.
echo "::error::lane \"$lane\" was cancelled on ${SHA}, so it never ran; start it by hand (Actions, \"$lane\", Run workflow) on the released branch: ${url}"
failed=1
elif [ "$conclusion" != "success" ]; then
echo "::error::lane \"$lane\" did not pass on ${SHA} (conclusion=${conclusion}): ${url}"
failed=1
else
echo "lane \"$lane\" passed on ${SHA}: ${url}"
fi
done
}

deadline=$((SECONDS + wait_seconds))
while true; do
check_lanes
if [ "$failed" -ne 0 ]; then
echo "::error::refusing to publish ${SHA}: required lanes did not pass"
exit 1
fi
if [ "$running" -eq 0 ]; then
echo "all required lanes passed on ${SHA}"
exit 0
fi
if [ "$SECONDS" -ge "$deadline" ]; then
echo "::error::refusing to publish ${SHA}: required lanes still running after ${wait_seconds}s"
exit 1
fi
echo "waiting ${poll_seconds}s for running lanes..."
sleep "$poll_seconds"
done
23 changes: 23 additions & 0 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,30 @@ on:
types: [created]

jobs:
# Refuses to publish unless every lane in PUBLISH_REQUIRED_LANES passed on
# the commit being released. Lanes are workflow names.
preflight:
runs-on: ubuntu-latest
name: 'Publish preflight'
permissions:
actions: read
contents: read
env:
PUBLISH_REQUIRED_LANES: |
Go Build CI
Gigapipe CI Cluster
steps:
- uses: actions/checkout@v4.1.1
with:
ref: ${{ (github.event_name == 'workflow_dispatch') && github.event.inputs.branch || github.ref }}
- name: Check required lanes on the released commit
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: SHA=$(git rev-parse HEAD) .github/scripts/publish-preflight.sh

validate_module_path:
needs: preflight
runs-on: ubuntu-latest
name: 'Validate go.mod major version'
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Go Build CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/k6_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# TODO! Change the way gigapipe runs
#
# Release-gate lane (#922): it starts on every PR but only does its work on a
# push to master, the nightly run, a manual run or a PR from a release/* branch.
# On any other PR the job below is skipped: the check shows as skipped, which
# counts as passing for required checks. The publish preflight doesn't accept
# a run whose job was skipped.
name: K6 Test metrico/gigapipe
on:
push:
Expand All @@ -24,9 +30,19 @@ on:
clickhouse_image:
description: 'Image for ClickHouse (clickhouse/clickhouse-server)'
required: false
schedule:
- cron: '47 2 * * *'

# Pushes queue instead of piling up: one push run runs, the newest waits, and a
# newer push replaces the waiting one. Every other run has its own group, so a
# push never cancels a nightly, manual or PR run.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.ref || github.run_id }}
cancel-in-progress: false

jobs:
build:
if: github.event_name != 'pull_request' || startsWith(github.head_ref, 'release/')
name: Run k6 on qryn:latest
runs-on: ubuntu-latest
continue-on-error: true
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/node-clickhouse-cluster.js.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# This workflow will validate gigapipe using nodejs + clickhouse
#
# Release-gate lane (#922): it starts on every PR but only does its work on a
# push to master, the nightly run, a manual run or a PR from a release/* branch.
# On any other PR the job below is skipped: the check shows as skipped, which
# counts as passing for required checks. The publish preflight doesn't accept
# a run whose job was skipped.

name: Gigapipe CI Cluster

Expand All @@ -7,17 +13,26 @@ on:
branches: [ master, beta ]
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
pull_request:
branches: [ master, beta ]
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
schedule:
- cron: '17 2 * * *'
workflow_dispatch:

# Pushes queue instead of piling up: one push run runs, the newest waits, and a
# newer push replaces the waiting one. Every other run has its own group, so a
# push never cancels a nightly, manual or PR run.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.ref || github.run_id }}
cancel-in-progress: false

jobs:
build:
if: github.event_name != 'pull_request' || startsWith(github.head_ref, 'release/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
Expand Down
8 changes: 8 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ For end-to-end tests:
make e2e-full
```

In CI the end-to-end lane ("Gigapipe CI Cluster") and the k6 lane are release
gates: on an ordinary PR their job is skipped (shown as skipped, which counts
as passing). They run on every push to `master`, nightly, when started by hand
from the Actions tab, and on PRs from a `release/*` branch. Run `make e2e-full`
locally, or start the lane by hand on your branch, when your change can affect
them. A release is refused unless the lane ran and passed on the released
commit.

The Makefile is the entry point for every lane CI runs (CI calls these same
recipes), plus parser-fuzz helpers for the query transpilers:

Expand Down
Loading