Skip to content

Commit 19a97e1

Browse files
Merge branch 'main' of github.com:cozystack/cozystack into feat/tenant-quota-reservation-evaluator
Signed-off-by: Mattia Eleuteri <[email protected]> Assisted-by: LLM # Conflicts: # go.mod
2 parents ebcfc55 + 970191d commit 19a97e1

299 files changed

Lines changed: 13360 additions & 30317 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/renovate.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
"matchStrings": ["clastix/kubectl:(?<currentValue>v[0-9]+\\.[0-9]+(?:\\.[0-9]+)?)@(?<currentDigest>sha256:[a-f0-9]+)"],
3333
"datasourceTemplate": "docker",
3434
"depNameTemplate": "docker.io/clastix/kubectl"
35+
},
36+
{
37+
"customType": "regex",
38+
"description": "Track the BuildKit SBOM scanner pinned by tag and digest in hack/common-envs.mk. The dockerfile manager does not read Makefiles and the helm-values manager is disabled repo-wide (see enabledManagers above), so without this manager the pin would stay on the syft it was cut with: the floating stable-1 tag it replaced moved to a fixed syft on its own, a digest pin does not. Tag and digest move together here, as the comment above the pin asks.",
39+
"managerFilePatterns": ["/^hack/common-envs\\.mk$/"],
40+
"matchStrings": ["SBOM_SCANNER \\?= (?<depName>docker\\.io/docker/buildkit-syft-scanner):(?<currentValue>[0-9]+\\.[0-9]+\\.[0-9]+)@(?<currentDigest>sha256:[a-f0-9]+)"],
41+
"datasourceTemplate": "docker"
3542
}
3643
],
3744
"packageRules": [

‎.github/workflows/api-review-gate-fork.yaml‎

Lines changed: 413 additions & 0 deletions
Large diffs are not rendered by default.

‎.github/workflows/api-review-gate.yaml‎

Lines changed: 202 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,92 @@ name: API Review Gate
55
# API group, a new resource, or a breaking change to an existing resource's
66
# schema. Detection is deterministic (cmd/api-gate); no LLM or network calls.
77
#
8-
# The job runs on every PR (no path filter) so it can always report a status
9-
# and therefore be marked as a required check in branch protection without
10-
# leaving PRs that touch no API stuck in "pending". When nothing sizeable
11-
# changed it passes immediately.
8+
# The job runs on every PR (no path filter) so it can always reach a verdict
9+
# without leaving PRs that touch no API stuck in "pending". When nothing
10+
# sizeable changed it passes immediately.
11+
#
12+
# The merge gate is the COMMIT STATUS named "API Review Gate", posted by the
13+
# `api-gate-report` job for same-repo PRs and by api-review-gate-fork.yaml for
14+
# fork PRs — NOT by the evaluating job below. Same reasoning as the "E2E Tests"
15+
# gate (docs/agents/e2e-testing.md §10), and it is what makes the
16+
# `commented`-review skip below safe:
17+
# - A required *job* that skips counts as PASSED by branch protection, so any
18+
# path that skips the evaluating job would hand out a free pass (#3257). A
19+
# status is "success" only when a report step posts it, and a never-posted
20+
# required status stays "Expected", which blocks the merge.
21+
# - Check runs are NOT deduplicated per name: every workflow run gets its own
22+
# check suite, so `GET /commits/{sha}/check-runs?filter=latest` returns the
23+
# same set as `filter=all` and the rollup is worst-of. Two runs on one head
24+
# SHA leave two verdicts standing for the same name, and a cancelled run
25+
# then poisons the context for good. Commit statuses ARE deduplicated per
26+
# context, newest wins.
27+
#
28+
# Consequence, and the invariant every change here must preserve: declining to
29+
# post can only preserve a verdict some real run reached, never invent one. So
30+
# skipped and cancelled runs post no verdict. The one thing a run posts before it
31+
# has one is `pending`, which is not a pass and blocks the merge until a real
32+
# verdict replaces it.
33+
#
34+
# For the gate to actually block a merge, main branch protection must require
35+
# the "API Review Gate" status CONTEXT; without that it is advisory. Never wire
36+
# branch protection to a job name.
1237

1338
on:
1439
pull_request:
1540
types: [opened, synchronize, reopened]
1641
# Re-evaluate when a review is submitted or dismissed so an approval by an
17-
# API owner flips the check from failing to passing without a new push.
42+
# API owner flips the status from failing to passing without a new push. The
43+
# job-level `if` below drops the review-bot noise (plain `commented` reviews);
44+
# only reviews that can move the gate — approved, changes_requested,
45+
# dismissed — actually re-run it.
1846
pull_request_review:
1947
types: [submitted, dismissed]
2048

49+
# A run that computes a verdict must never be cancelled by a run that does not.
50+
# A plain `commented` review skips the evaluation (see the job `if`), so it gets
51+
# its own group and can only cancel other no-op runs, while pushes and
52+
# actionable reviews share the `eval` group and legitimately supersede each
53+
# other. Under a single shared group a review bot commenting during the ~30s
54+
# evaluation cancelled it and then contributed nothing — observed on real PRs
55+
# (41d1153c, 4b1966c5), leaving a cancelled run as that SHA's only verdict.
2156
concurrency:
22-
group: api-review-gate-${{ github.event.pull_request.number }}
57+
group: >-
58+
api-review-gate-${{ github.event.pull_request.number }}-${{
59+
github.event_name == 'pull_request_review'
60+
&& github.event.review.state == 'commented' && 'noop' || 'eval' }}
2361
cancel-in-progress: true
2462

2563
permissions:
2664
contents: read
2765
pull-requests: read
2866

67+
env:
68+
# Space-separated GitHub logins allowed to satisfy the gate. Edit here to
69+
# change who can approve sizeable API changes. Workflow-level so the
70+
# evaluating job and the published status description cannot drift apart.
71+
API_OWNERS: "lllamnyp kvaps"
72+
2973
jobs:
3074
api-review-gate:
31-
name: Require API owner review for sizeable API changes
75+
# Deliberately NOT named after the gate: the merge gate is the "API Review
76+
# Gate" commit status, and a required context that is also a job name
77+
# inherits the skip-to-green and no-dedup problems in the header.
78+
name: API review gate (evaluate)
79+
# A push always evaluates the gate. A review event re-runs it only when the
80+
# review can move the verdict: an approval can flip fail->pass, a dismissal
81+
# or changes_requested can flip pass->fail. Plain `commented` reviews — all
82+
# that the review bots (CodeRabbit, dosubot) ever post — cannot, so they skip
83+
# here instead of rebuilding the detector on every bot comment. Safe because
84+
# `api-gate-report` skips in lockstep and posts nothing, which leaves the
85+
# last real verdict standing.
86+
if: >-
87+
github.event_name != 'pull_request_review' ||
88+
github.event.review.state != 'commented'
3289
runs-on: ubuntu-22.04
90+
outputs:
91+
sizeable: ${{ steps.detect.outputs.sizeable }}
92+
verdict: ${{ steps.approve.outputs.verdict }}
3393
env:
34-
# Space-separated GitHub logins allowed to satisfy the gate. Edit here to
35-
# change who can approve sizeable API changes.
36-
API_OWNERS: "lllamnyp kvaps"
3794
BASE_REF: ${{ github.event.pull_request.base.ref }}
3895
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
3996
PR_NUMBER: ${{ github.event.pull_request.number }}
@@ -121,6 +178,7 @@ jobs:
121178
esac
122179
123180
- name: Check for an API owner approval
181+
id: approve
124182
if: steps.detect.outputs.sizeable == 'true'
125183
env:
126184
GH_TOKEN: ${{ github.token }}
@@ -135,14 +193,18 @@ jobs:
135193
# An APPROVED review by any API owner satisfies the gate, but only
136194
# each reviewer's *latest* review *on the current head commit* counts:
137195
# this drops approvals that a later commit invalidated, and approvals
138-
# an owner subsequently superseded with CHANGES_REQUESTED. GitHub
139-
# forbids self-approval, so a sizeable PR authored by an owner still
140-
# needs the other owner.
196+
# an owner subsequently superseded with CHANGES_REQUESTED or that was
197+
# dismissed. A COMMENTED review is dropped before picking the latest:
198+
# GitHub does not let a comment withdraw an approval, and the review
199+
# trigger skips comments, so counting one here would make the verdict
200+
# depend on which event happened to re-run the gate. GitHub forbids
201+
# self-approval, so a sizeable PR authored by an owner still needs the
202+
# other owner. api-review-gate-fork.yaml applies the same rule.
141203
approvals="$(
142204
gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews" --paginate |
143205
jq -rs --arg head "${HEAD_SHA}" '
144206
add
145-
| map(select(.commit_id == $head))
207+
| map(select(.commit_id == $head and .state != "COMMENTED"))
146208
| sort_by(.submitted_at // "")
147209
| group_by(.user.login)
148210
| map(last)
@@ -152,12 +214,138 @@ jobs:
152214
'
153215
)"
154216
217+
# The verdict is recorded as a step output so `api-gate-report` can tell
218+
# "sizeable change, no owner approval" apart from "the evaluation itself
219+
# broke" — both of which fail this job. Written before the exit in each
220+
# branch, since a step output set after exiting is never emitted.
155221
for owner in ${API_OWNERS}; do
156222
if grep -qxi "${owner}" <<<"${approvals}"; then
157223
echo "Sizeable API change approved by @${owner}."
224+
echo "verdict=pass-approved" >> "$GITHUB_OUTPUT"
158225
exit 0
159226
fi
160227
done
161228
229+
echo "verdict=fail-needs-approval" >> "$GITHUB_OUTPUT"
162230
echo "::error::This PR makes a sizeable API change (new group, new resource, or breaking change) and needs an approving review from one of: ${API_OWNERS}. See the job summary for details."
163231
exit 1
232+
233+
# A dismissal or a request for changes can turn a green head red, and until
234+
# the evaluation reports, about a minute later, the old `success` would still
235+
# let the PR merge. Same opener as the "E2E Tests" lane. Pushes need none: a
236+
# new head SHA starts with no status. Losing it to a transient API error only
237+
# reopens that window, so it must not fail the run.
238+
api-gate-pending:
239+
name: Mark API review gate as re-evaluating
240+
if: >-
241+
${{ github.event_name == 'pull_request_review'
242+
&& github.event.review.state != 'commented'
243+
&& !github.event.pull_request.head.repo.fork }}
244+
runs-on: ubuntu-latest
245+
continue-on-error: true
246+
permissions:
247+
statuses: write
248+
steps:
249+
- name: Report pending "API Review Gate" commit status
250+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
251+
env:
252+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
253+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
254+
with:
255+
script: |
256+
const { HEAD_SHA, RUN_URL } = process.env;
257+
const { owner, repo } = context.repo;
258+
await github.rest.repos.createCommitStatus({
259+
owner, repo, sha: HEAD_SHA, state: 'pending',
260+
context: 'API Review Gate', description: 're-evaluating after a review',
261+
target_url: RUN_URL,
262+
});
263+
264+
# Publish the required "API Review Gate" commit status. Separate from the
265+
# evaluating job for the reasons in the header: the gate must not be a job
266+
# name, and a run that reached no verdict must post none.
267+
#
268+
# The `if` guard stays in LOCKSTEP with the evaluating job's — this job runs if
269+
# and only if that one does. A `commented` review skips both, so the previous
270+
# real status stands untouched. `!cancelled()` rather than `always()`: a run
271+
# killed by the concurrency group has no verdict, and posting one anyway would
272+
# overwrite a green status with red — the exact failure #3262 hit twice with
273+
# "E2E Tests" (see its `e2e-report`).
274+
#
275+
# Fork PRs skip this job. Their GITHUB_TOKEN is read-only on BOTH the
276+
# `pull_request` and `pull_request_review` triggers, so no run of this workflow
277+
# can post a status for a fork, and its verdict could not be relayed anyway: a
278+
# fork's run executes the fork's copy of this file. api-review-gate-fork.yaml
279+
# evaluates fork PRs again from the default branch. Until it does, the required
280+
# status is unposted and the fork PR is not mergeable — fail-closed by
281+
# construction.
282+
api-gate-report:
283+
name: Report API review gate status
284+
needs: [api-gate-pending, api-review-gate]
285+
if: >-
286+
${{ !cancelled()
287+
&& !github.event.pull_request.head.repo.fork
288+
&& (github.event_name != 'pull_request_review'
289+
|| github.event.review.state != 'commented') }}
290+
runs-on: ubuntu-latest
291+
permissions:
292+
contents: read
293+
statuses: write
294+
steps:
295+
- name: Report "API Review Gate" commit status
296+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
297+
env:
298+
GATE_RESULT: ${{ needs.api-review-gate.result }}
299+
SIZEABLE: ${{ needs.api-review-gate.outputs.sizeable }}
300+
VERDICT: ${{ needs.api-review-gate.outputs.verdict }}
301+
# Inherited from the workflow-level env; passed explicitly so the
302+
# script's use of it is visible at the call site.
303+
API_OWNERS: ${{ env.API_OWNERS }}
304+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
305+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
306+
with:
307+
script: |
308+
const { GATE_RESULT, SIZEABLE, VERDICT, API_OWNERS, HEAD_SHA, RUN_URL } = process.env;
309+
const { owner, repo } = context.repo;
310+
311+
// No verdict to publish — say nothing and let the last real status
312+
// stand. Reachable when the evaluating job was skipped despite the
313+
// lockstep guard (a `needs` short-circuit), and defensive against a
314+
// future guard drift.
315+
if (GATE_RESULT !== 'success' && GATE_RESULT !== 'failure') {
316+
core.info(`evaluation result '${GATE_RESULT}' — posting nothing, previous status stands`);
317+
return;
318+
}
319+
320+
let state, description;
321+
if (GATE_RESULT === 'success') {
322+
state = 'success';
323+
description = SIZEABLE === 'true'
324+
? 'sizeable API change approved by an API owner'
325+
: 'no sizeable API change';
326+
} else if (VERDICT === 'fail-needs-approval') {
327+
state = 'failure';
328+
description = `sizeable API change needs an approving review from: ${API_OWNERS}`;
329+
} else {
330+
// Either the job failed before reaching a verdict (checkout, build or
331+
// the detector), or it reached `fail-needs-approval` but the output did
332+
// not survive the failing job — whether a failed job propagates its
333+
// outputs is not something the docs pin down. Only the description
334+
// degrades: the state is `failure` down both paths, so the gate itself
335+
// is unaffected. Fail-closed either way — an unverifiable gate is red.
336+
state = 'failure';
337+
description = 'gate evaluation did not complete — see the run for details';
338+
}
339+
340+
try {
341+
await github.rest.repos.createCommitStatus({
342+
owner, repo, sha: HEAD_SHA, state,
343+
context: 'API Review Gate', description, target_url: RUN_URL,
344+
});
345+
} catch (err) {
346+
// Fail loudly and fail-closed: setFailed keeps this job red and the
347+
// required status unposted ("Expected"), so the PR stays unmergeable.
348+
core.setFailed(`Failed to report API Review Gate status: ${err}`);
349+
return;
350+
}
351+
core.info(`API Review Gate → ${state}: ${description}`);

‎.github/workflows/changelog-generate.yaml‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,18 @@ jobs:
163163
# detached rc-tag checkout is exactly that, so a COMPLIANT agent would
164164
# silently decline to generate on every promotion of an existing rc.
165165
# Overlay the current instructions so the agent reads today's contract.
166+
# changelog.md sends the agent to the checks in docs/release.md and to
167+
# hack/validate-changelog.sh, so those are overlaid too: the rc tag's
168+
# copies predate any check added since. docs/release.md reaches
169+
# .release-tooling only because the sparse checkout above is in cone
170+
# mode (the action's default), which carries the files of every parent
171+
# directory of docs/agents.
166172
- name: Refresh agent instructions
167173
run: |
168174
cp .release-tooling/docs/agents/changelog.md docs/agents/changelog.md
169-
echo "Refreshed docs/agents/changelog.md from ${GITHUB_REF_NAME}."
175+
cp .release-tooling/docs/release.md docs/release.md
176+
cp .release-tooling/hack/validate-changelog.sh hack/validate-changelog.sh
177+
echo "Refreshed docs/agents/changelog.md, docs/release.md and hack/validate-changelog.sh from ${GITHUB_REF_NAME}."
170178
171179
# Skip-priority + validate-then-fall-through: use a pre-existing changelog
172180
# only if it is USABLE, so an invalid higher-priority source can never

‎.github/workflows/cut-prerelease.yaml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ concurrency:
4848
group: cut-prerelease
4949
cancel-in-progress: false
5050

51-
# The tag write happens via the app token, not GITHUB_TOKEN, so the job needs
52-
# only read scope on the default token.
51+
# Tag and branch writes use the app token so their push events trigger CI.
5352
permissions:
5453
contents: read
5554

@@ -58,6 +57,9 @@ jobs:
5857
name: Cut ${{ inputs.tag }}
5958
runs-on: ubuntu-latest
6059
timeout-minutes: 10
60+
permissions:
61+
contents: read
62+
actions: write
6163

6264
steps:
6365
# Pure-input validation first — no token minted, no checkout, so a bad tag
@@ -345,13 +347,14 @@ jobs:
345347
- name: Build the frozen line's packages artifact
346348
if: steps.freeze.outputs.created == 'true'
347349
env:
348-
GH_TOKEN: ${{ steps.app-token.outputs.token }}
350+
# workflow_dispatch can trigger a run with GITHUB_TOKEN.
351+
GH_TOKEN: ${{ github.token }}
349352
BRANCH: release-${{ steps.parse.outputs.line }}
350353
run: |
351354
if gh workflow run build-release.yaml --ref "$BRANCH"; then
352355
echo "Dispatched build-release.yaml for $BRANCH; it publishes cozystack-packages:$BRANCH."
353356
else
354-
echo "::warning::Could not dispatch build-release.yaml for $BRANCH (the CI app may lack 'actions: write')."
357+
echo "::warning::Could not dispatch build-release.yaml for $BRANCH."
355358
echo "::warning::Until it runs, cozystack-packages:$BRANCH does not exist, and PRs onto $BRANCH test the image refs committed in the tree rather than the line's own build."
356359
echo "::warning::Start it by hand: gh workflow run build-release.yaml --ref $BRANCH"
357360
fi

‎.github/workflows/e2e-proxmox.yaml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ jobs:
9191
cat "$RUNNER_TEMP/kubeconfig-check.err" >&2
9292
exit 1
9393
fi
94-
printf '%s' "$PVE_SSH_KEY" > "$COZY_PVE_SSH_KEY"
94+
# OpenSSH refuses a private key whose last line has no newline ("error
95+
# in libcrypto"), and `gh secret set` strips it from a key read from
96+
# stdin. A second newline, when the secret kept its own, is harmless.
97+
printf '%s\n' "$PVE_SSH_KEY" > "$COZY_PVE_SSH_KEY"
9598
9699
# The credentials the management-side CSI controller and CCM read. A
97100
# Secret rather than values so no token is ever written into a
@@ -157,4 +160,8 @@ jobs:
157160
158161
- name: Remove staged credentials
159162
if: always()
160-
run: rm -f "$GITHUB_WORKSPACE/.kubeconfig" "$COZY_PVE_SSH_KEY"
163+
# The tenant kubeconfig is the suite's, fetched by run-proxmox.sh into
164+
# RUNNER_TEMP, which the runner exports into every step (the runner
165+
# context is not allowed in job-level env); its finally removes it too,
166+
# but a run killed mid-step never reaches that.
167+
run: rm -f "$GITHUB_WORKSPACE/.kubeconfig" "$COZY_PVE_SSH_KEY" "$RUNNER_TEMP/proxmox-e2e-tenant.kubeconfig"

0 commit comments

Comments
 (0)