feat(actions)!: improve support for reusable workflows (#37478)

## Summary

This PR improves reusable workflow support for Gitea Actions. The
parsing of the called workflow now happens on Gitea side, not on the
runner. When the caller becomes ready, Gitea fetches the called workflow
source, parses it, and inserts each child job into the database as a
`ActionRunJob` linked to the caller via `ParentCallJobID`. As a result,
every callee job is dispatched as its own task and its logs surface as
an independent job entry in the UI, rather than being inlined into the
caller's "Set up job" step.

This PR supports two kinds of `uses` : 
- same-repo call: `uses: ./.gitea/workflows/foo.yaml`
- cross-repo call: `uses: OWNER/REPO/.gitea/workflows/foo.yaml@REF`

## **⚠️ BREAKING ⚠️**
External reusable workflows (`uses:
https://other-gitea-instance/OWNER/REPO/.gitea/workflows/test.yaml@REF`)
are no longer supported. To keep using them, clone the repositories to
the local instance.

## Main changes

### Execution model

- Each caller job carries `IsReusableCaller=true` and won't be fetched
by runners.
- `ParentCallJobID` can link a called job to its caller.
- Caller status is derived from its direct children.


### Workflow syntax

- `jobparser` now supports parsing `on: workflow_call` trigger with
`inputs:`, `outputs:`, and `secrets:` declarations.
- **Max nesting depth**: capped at `MaxReusableCallLevels = 9`, which
means a top-level caller may have at most 9 nested callers below it.
- **Cycle prevention**: at expansion time, `checkCallerChain` walks the
caller's ancestor chain via `ParentCallJobID` and rejects if the same
`uses:` string appears anywhere upstream (`reusable workflow call cycle
detected`). This catches both direct (`A -> A`) and indirect (`A -> B ->
A`) cycles.

### Cross-repo access

- To share reusable workflows from private repos, use `Collaborative
Owners` introduced by #32562

### Rerun semantics

- `expandRerunJobIDs` partitions the latest attempt's jobs into:
- a **rerun set**: jobs being rerun + downstream siblings within the
same scope.
- an **ancestor set**: reusable callers whose only *some* descendants
are being rerun (the caller itself is not).
- Cloning behavior for callers in `execRerunPlan`:
- **Caller is fully rerun** (caller's `AttemptJobID` in `rerunSet`):
none of its descendants are cloned. The caller is cloned with
`IsCallerExpanded=false`, and re-expansion (which reinserts the children
fresh) happens later when the resolver brings the caller to `Waiting`
again.
- **Caller is in ancestor set** (only some descendants rerun): the
caller is pass-through (`Status` will be updated by its fresh children).
Its non-rerun descendants are also pass-through clones (point
`SourceTaskID` at the original task). Their `ParentCallJobID` is
remapped to the new attempt's caller row.

### UI

- Job list in `RepoActionView.vue` is now tree-shaped: callers indent
their children. Callers default to collapsed.
- New caller detail page using `WorkflowGraph` to show direct children
only; the run summary's `WorkflowGraph` shows top-level callers and
their immediate descendants.

### Known trade-offs

- **Caller expansion runs inside the enclosing write transaction.**
`expandReusableWorkflowCaller` performs a git read of the called
workflow while holding the row locks that update the caller and insert
its children. This is intentional: the caller-row update and child-row
inserts must commit atomically. None of the call sites is hot (each
caller is expanded once per attempt), so the trade-off is acceptable.

- **A malformed `if:` expression on a job leaves it `Blocked`
silently.** `evaluateJobIf` now runs server-side as part of resolver
passes; deterministic expression errors (typos, undefined context
fields) are logged but do not surface in the UI. This is the same
behavior the resolver already had for concurrency-expression errors.
Distinguishing transient DB errors from user-authored expression errors
and writing the latter back as `StatusFailure` is a follow-up.


#### Screenshots

<img width="1600" alt="image"
src="https://github.com/user-attachments/assets/bfaa9b7a-07e9-4127-8de9-a81f86e82828"
/>

<img width="1600" alt="image"
src="https://github.com/user-attachments/assets/8af109b3-ef28-4b53-aaad-d4632b923224"
/>


## References

-
https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows
-
https://docs.github.com/en/actions/reference/workflows-and-actions/reusing-workflow-configurations

---

Replace #36388

---------

Signed-off-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
Zettat123
2026-05-30 08:31:14 +02:00
committed by GitHub
co-authored by Copilot Autofix powered by AI silverwind Claude
parent 2960d6889c
commit 0359746abe
41 changed files with 4692 additions and 363 deletions
+65 -52
View File
@@ -115,7 +115,8 @@ const jobsWithLayout = computed<JobNode[]>(() => {
let maxJobsPerLevel = 0;
props.jobs.forEach(job => {
const level = levels.get(job.name) || levels.get(job.jobId) || 0;
// `?? 0`, not `|| 0`: a root job's level is 0, which `||` would wrongly discard.
const level = levels.get(scopedKey(job)) ?? 0;
if (!jobsByLevel[level]) {
jobsByLevel[level] = [];
@@ -164,75 +165,87 @@ const jobsWithLayout = computed<JobNode[]>(() => {
}
});
// scopedKey identifies a job within its reusable-workflow call scope so that the same
// JobID in different reusable calls does not collide.
function scopedKey(job: {parentJobID: number; jobId: string}): string {
return `${job.parentJobID || 0}:${job.jobId}`;
}
function buildDirectNeedsMap(jobs: ActionsJob[]): Map<string, string[]> {
const directNeedsByJobId = new Map<string, string[]>();
const dependentsByJobId = new Map<string, Set<string>>();
// The map keys/values are scoped keys, not bare jobIds, so we keep edge construction
// accurate when reusable workflows reuse common job names like "build" / "test".
const directNeedsByScopedKey = new Map<string, string[]>();
const dependentsByScopedKey = new Map<string, Set<string>>();
for (const job of jobs) {
const needs = job.needs || [];
directNeedsByJobId.set(job.jobId, needs);
const fromKey = scopedKey(job);
const needKeys = (job.needs || []).map((n) => `${job.parentJobID || 0}:${n}`);
directNeedsByScopedKey.set(fromKey, needKeys);
for (const need of needs) {
if (!dependentsByJobId.has(need)) {
dependentsByJobId.set(need, new Set());
for (const needKey of needKeys) {
if (!dependentsByScopedKey.has(needKey)) {
dependentsByScopedKey.set(needKey, new Set());
}
dependentsByJobId.get(need)!.add(job.jobId);
dependentsByScopedKey.get(needKey)!.add(fromKey);
}
}
const reachabilityCache = new Map<string, boolean>();
function canReach(fromJobId: string, toJobId: string): boolean {
const cacheKey = `${fromJobId}->${toJobId}`;
function canReach(fromKey: string, toKey: string): boolean {
const cacheKey = `${fromKey}->${toKey}`;
if (reachabilityCache.has(cacheKey)) {
return reachabilityCache.get(cacheKey)!;
}
const visited = new Set<string>();
const stack = [...(dependentsByJobId.get(fromJobId) || [])];
const stack = [...(dependentsByScopedKey.get(fromKey) || [])];
while (stack.length > 0) {
const current = stack.pop()!;
if (current === toJobId) {
if (current === toKey) {
reachabilityCache.set(cacheKey, true);
return true;
}
if (visited.has(current)) continue;
visited.add(current);
stack.push(...(dependentsByJobId.get(current) || []));
stack.push(...(dependentsByScopedKey.get(current) || []));
}
reachabilityCache.set(cacheKey, false);
return false;
}
const reducedNeedsByJobId = new Map<string, string[]>();
for (const [jobId, needs] of directNeedsByJobId.entries()) {
reducedNeedsByJobId.set(jobId, needs.filter((need) => {
const reducedNeedsByScopedKey = new Map<string, string[]>();
for (const [fromKey, needs] of directNeedsByScopedKey.entries()) {
reducedNeedsByScopedKey.set(fromKey, needs.filter((need) => {
return !needs.some((otherNeed) => otherNeed !== need && canReach(need, otherNeed));
}));
}
return reducedNeedsByJobId;
return reducedNeedsByScopedKey;
}
const directNeedsByJobId = computed(() => buildDirectNeedsMap(props.jobs));
const directNeedsByScopedKey = computed(() => buildDirectNeedsMap(props.jobs));
const edges = computed<Edge[]>(() => {
const edgesList: Edge[] = [];
const jobsByJobId = new Map<string, ActionsJob[]>();
// Store every job per scoped key, not just one: matrix-expanded jobs share same jobId
const jobsByScopedKey = new Map<string, ActionsJob[]>();
for (const job of props.jobs) {
if (!jobsByJobId.has(job.jobId)) {
jobsByJobId.set(job.jobId, []);
const key = scopedKey(job);
const existing = jobsByScopedKey.get(key);
if (existing) {
existing.push(job);
} else {
jobsByScopedKey.set(key, [job]);
}
jobsByJobId.get(job.jobId)!.push(job);
}
for (const job of props.jobs) {
for (const need of directNeedsByJobId.value.get(job.jobId) || []) {
const upstreamJobs = jobsByJobId.get(need) || [];
for (const upstreamJob of upstreamJobs) {
for (const needKey of directNeedsByScopedKey.value.get(scopedKey(job)) || []) {
for (const upstreamJob of jobsByScopedKey.get(needKey) || []) {
edgesList.push({
fromId: upstreamJob.id,
toId: job.id,
@@ -469,10 +482,11 @@ const nodesWithOutgoingEdge = computed(() => {
function computeJobLevels(jobs: ActionsJob[]): Map<string, number> {
const jobMap = new Map<string, ActionsJob>()
// Scope-aware: each job is keyed by `${parentJobID}:${jobId}` so the same JobID
// in different reusable workflow calls does not cross-link in the level graph.
const jobMap = new Map<string, ActionsJob>();
jobs.forEach(job => {
jobMap.set(job.name, job);
if (job.jobId) jobMap.set(job.jobId, job);
jobMap.set(scopedKey(job), job);
});
const levels = new Map<string, number>();
@@ -480,60 +494,59 @@ function computeJobLevels(jobs: ActionsJob[]): Map<string, number> {
const recursionStack = new Set<string>();
const MAX_DEPTH = 100;
function dfs(jobNameOrId: string, depth: number = 0): number {
function dfs(scoped: string, depth: number = 0): number {
if (depth > MAX_DEPTH) {
console.error(`Max recursion depth (${MAX_DEPTH}) reached for: ${jobNameOrId}`);
console.error(`Max recursion depth (${MAX_DEPTH}) reached for: ${scoped}`);
return 0;
}
if (recursionStack.has(jobNameOrId)) {
console.error(`Cycle detected involving: ${jobNameOrId}`);
if (recursionStack.has(scoped)) {
console.error(`Cycle detected involving: ${scoped}`);
return 0;
}
if (visited.has(jobNameOrId)) {
return levels.get(jobNameOrId) || 0;
if (visited.has(scoped)) {
return levels.get(scoped) || 0;
}
recursionStack.add(jobNameOrId);
visited.add(jobNameOrId);
recursionStack.add(scoped);
visited.add(scoped);
const job = jobMap.get(jobNameOrId);
const job = jobMap.get(scoped);
if (!job) {
recursionStack.delete(jobNameOrId);
recursionStack.delete(scoped);
return 0;
}
if (!job.needs?.length) {
levels.set(job.jobId, 0);
recursionStack.delete(jobNameOrId);
levels.set(scoped, 0);
recursionStack.delete(scoped);
return 0;
}
let maxLevel = -1;
for (const need of job.needs) {
const needJob = jobMap.get(need);
const needScoped = `${job.parentJobID || 0}:${need}`;
const needJob = jobMap.get(needScoped);
if (!needJob) continue;
const needLevel = dfs(need, depth + 1);
const needLevel = dfs(needScoped, depth + 1);
maxLevel = Math.max(maxLevel, needLevel);
}
const level = maxLevel + 1
levels.set(job.name, level);
if (job.jobId && job.jobId !== job.name) {
levels.set(job.jobId, level);
}
const level = maxLevel + 1;
levels.set(scoped, level);
recursionStack.delete(jobNameOrId);
recursionStack.delete(scoped);
return level;
}
jobs.forEach(job => {
if (!visited.has(job.name) && !visited.has(job.jobId)) {
dfs(job.name);
const sk = scopedKey(job);
if (!visited.has(sk)) {
dfs(sk);
}
})
});
return levels;
}