Skip to content

WIP: Improve support for reusable workflows#36388

Draft
Zettat123 wants to merge 8 commits intogo-gitea:mainfrom
Zettat123:reusable-workflow-log-2
Draft

WIP: Improve support for reusable workflows#36388
Zettat123 wants to merge 8 commits intogo-gitea:mainfrom
Zettat123:reusable-workflow-log-2

Conversation

@Zettat123
Copy link
Copy Markdown
Contributor

@Zettat123 Zettat123 commented Jan 16, 2026

This PR aimes to improve the logic for handling reusable workflows. Key changes include:

  • Introduce ParentJob to represent a job calling a reusable workflow.
  • Parse reusable workflow files on Gitea side rather than by runner during execution. This ensures that jobs within the reusable workflow can be correctly picked up and executed by runners with the specified labels.

Related to https://gitea.com/gitea/act/pulls/152


Screenshots image image image

This PR is not ready for review yet as there are still several changes to be made (#36388 (comment)). The CI will currently fail at this stage.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 16, 2026
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/migrations labels Jan 16, 2026
@Zettat123 Zettat123 added the pr/wip This PR is not ready for review label Jan 16, 2026
@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch from a4ef071 to 01b2cf5 Compare January 21, 2026 00:48
@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch from 562b931 to 5307ac0 Compare January 27, 2026 21:26
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Jan 28, 2026
@Sirherobrine23
Copy link
Copy Markdown
Contributor

Hi @Zettat123, could you take a look at this patch based on your PR? I've made some minor changes to align the logs in the same workflow

localhost_3000_Sirherobrine23_test_actions_runs_19

@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch 2 times, most recently from 4fbf1b5 to f14ab9f Compare March 4, 2026 00:07
@Sirherobrine23
Copy link
Copy Markdown
Contributor

One question, wasn't the migration supposed to continue with the old actions? I tested it with a backup, and the old actions aren't being listed. Could it be something with the sql query?

@Zettat123
Copy link
Copy Markdown
Contributor Author

@Sirherobrine23 Thank you for the patches. This PR is currently a few commits behind the main branch, so I am in the process of updating the branch and resolving conflicts. Once the conflicts are fixed, I will attempt to apply these patches.

One question, wasn't the migration supposed to continue with the old actions? I tested it with a backup, and the old actions aren't being listed. Could it be something with the sql query?

This change won't affect previous actions. The issue you discovered appears to be a bug, and I will fix it in the next update.


I also noticed issue #36822 that you created; this bug is caused by Gitea improperly handling reusable workflows. It will be resolved once this PR is completed.

@Zettat123 Zettat123 changed the title WIP: Improve log display for reusable workflows WIP: Improve support for reusable workflows Mar 4, 2026
@Zettat123
Copy link
Copy Markdown
Contributor Author

Hi @Sirherobrine23, due to code conflicts, I didn't apply the patch directly. Instead, I’ve created a new PR - Zettat123#1 . Could you please check if it covers all the changes from your patch?

@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch from 4e1a1fb to 70e907c Compare March 5, 2026 04:25
@Zettat123
Copy link
Copy Markdown
Contributor Author

Hi @Sirherobrine23, I have tested and reviewed your patch. Here are some concerns:

  • jobIndex has been replaced by jobID. Since many parts of the current logic rely on jobIndex, this modification is incomplete. This approach requires further discussion/validation.

  • Nested calls are not fully supported. While this change handles single-level calls well (e.g., Workflow A calling Workflow B), it cannot properly handle nested calls (e.g., Workflow A calling Workflow B, which then calls Workflow C).


The UI changes in the current PR could still be further improved. Any suggestions are welcome.

@Sirherobrine23
Copy link
Copy Markdown
Contributor

I swapped jobIndex for jobID in my testing the workflows, it was quick, i tried keeping jobIndex because it wasn't locating the job, but it was something i needed to fix before sending patch

@Zettat123
Copy link
Copy Markdown
Contributor Author

Zettat123 commented Mar 5, 2026

I swapped jobIndex for jobID in my testing the workflows, it was quick, i tried keeping jobIndex because it wasn't locating the job, but it was something i needed to fix before sending patch

Don't worry. I'll send another PR to replace jobIndex with jobID. After that PR, this PR will be able to locate a job by its ID.


#36842

silverwind pushed a commit that referenced this pull request Mar 10, 2026
This PR migrates the web Actions run/job routes from index-based
`runIndex` or `jobIndex` to database IDs.

**⚠️ BREAKING ⚠️**: Existing saved links/bookmarks that use the old
index-based URLs will no longer resolve after this change.

Improvements of this change:
- Previously, `jobIndex` depended on list order, making it hard to
locate a specific job. Using `jobID` provides stable addressing.
- Web routes now align with API, which already use IDs.
- Behavior is closer to GitHub, which exposes run/job IDs in URLs.
- Provides a cleaner base for future features without relying on list
order.
- #36388 this PR improves the support for reusable workflows. If a job
uses a reusable workflow, it may contain multiple child jobs, which
makes relying on job index to locate a job much more complicated

---------

Signed-off-by: Zettat123 <[email protected]>
Co-authored-by: Copilot <[email protected]>
@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch from 87203d0 to d6dc325 Compare March 11, 2026 01:57
Copy link
Copy Markdown
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was written by Claude.

Overall, the architecture is solid and the integration test is well-designed. Here are the important issues I found:


Bug: Two consecutive returns in ParseRawOn (dead code)

modules/actions/jobparser/model.go:

if k != "workflow_dispatch" && k != "workflow_call" {
    return nil, fmt.Errorf("map should only for workflow_dispatch but %s: %#v", act, content)
    return nil, fmt.Errorf("map should only for workflow_dispatch or workflow_call but %s: %#v", act, content)
}

The first return makes the second one unreachable. The old error message (mentioning only workflow_dispatch) is kept instead of the corrected one. Looks like an editing mistake.


Bug: Dead code in checkRunNestingLevel

services/actions/reusable_workflow.go:

for cur.ParentJobID > 0 {
    if cur.ParentJobID == 0 {  // <-- can never be true inside this loop
        break
    }

The inner check is dead code since the loop condition already guarantees ParentJobID > 0.


expandReusableWorkflow failure is silently swallowed

In services/actions/job_emitter.go, if expandReusableWorkflow fails, it's only logged. The job remains with ChildRunID == -1 and Status == Waiting, stuck forever since CreateTaskForRunner skips jobs where child_run_id != 0. The job should be marked as failed/errored so users see the problem.

Same issue in services/actions/run.go after InsertRun where errors from expandReusableWorkflow are logged but the run/job stays in a broken state.


Rerun guard removed

RerunWorkflowRunJobs removed the if !run.Status.IsDone() guard. The new code only conditionally resets timestamps. This means a running workflow could now be "rerun". The IsDone() check in rerunWorkflowJob was also weakened — old code returned early if !status.IsDone(), new code returns early only if oldStatus == newStatus. A running job being set to waiting could cause races.


LoadAttributes called twice

expandReusableWorkflow calls parentJob.LoadAttributes(ctx), and then createChildRunFromReusableWorkflow (called immediately after) also calls parentJob.LoadAttributes(ctx). One of them is redundant.


Copyright year

services/actions/reusable_workflow.go has Copyright 2025 but should be 2026.


Missing secrets: inherit support

GitHub supports secrets: inherit to pass all parent secrets through. The current implementation only handles explicit secret mappings. Worth noting for follow-up.

@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Mar 15, 2026
@Sirherobrine23
Copy link
Copy Markdown
Contributor

I'm looking at the action_run_job.child_run_id and action_run.parent_job_id column and it's showing as NULL. I had to update manually:

UPDATE public.action_run_job
SET child_run_id = 0
WHERE child_run_id IS NULL;

UPDATE public.action_run
SET parent_job_id = 0
WHERE parent_job_id IS NULL;
image

@Sirherobrine23
Copy link
Copy Markdown
Contributor

You also need to modify repo.NumOpenActionRuns to ignore workflow_call

gitea/models/repo/repo.go

Lines 324 to 326 in 6372cd7

repo.NumOpenProjects = repo.NumProjects - repo.NumClosedProjects
repo.NumOpenActionRuns = repo.NumActionRuns - repo.NumClosedActionRuns
if repo.DefaultWikiBranch == "" {


And some actions are no longer being triggered when the needs are defined

image
name: Docker build
on:
  push:
  workflow_dispatch:
  schedule:
    - cron: 0 0/2 * * *

jobs:
  check-release:
    runs-on: ubuntu-latest
    name: Check if image released
    outputs:
      LATEST_SKIP: ${{ steps.checker.outputs.LATEST_SKIP }}
      RELEASE_SKIP: ${{ steps.checker.outputs.RELEASE_SKIP }}
      # -----
      LATEST_DOCKER_TAG: ${{ steps.checker.outputs.LATEST_DOCKER_TAG }}
      RELEASE_DOCKER_TAG: ${{ steps.checker.outputs.RELEASE_DOCKER_TAG }}
      # -----
      LATEST_GIT_VERSION: ${{ steps.checker.outputs.LATEST_GIT_VERSION }}
      RELEASE_GIT_VERSION: ${{ steps.checker.outputs.RELEASE_GIT_VERSION }}
      # -----
      LATEST_GITEA_VERSION: ${{ steps.checker.outputs.LATEST_GITEA_VERSION }}
      RELEASE_GITEA_VERSION: ${{ steps.checker.outputs.RELEASE_GITEA_VERSION }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - uses: actions/setup-go@v4
        with:
          go-version-file: "./.github/checker/go.mod"
          cache: true

      - name: Release check
        id: checker
        uses: ./.github/checker
        env:
          GITEA_REPO: "https://github.com/go-gitea/gitea.git"
  
  main-build:
    if: needs.check-release.outputs.RELEASE_SKIP != '0' && needs.check-release.outputs.LATEST_SKIP == '0'
    needs: [ check-release ]
    name: Build main docker image
    uses: "./.github/workflows/call.yaml"
    secrets: inherit
    with:
      GITEA_TAG: ${{ needs.check-release.outputs.LATEST_GIT_VERSION }}
      DOCKER_TAG: ${{ needs.check-release.outputs.LATEST_DOCKER_TAG }}
      GITEA_REPO: "https://github.com/go-gitea/gitea.git"
      GITEA_VERSION: ${{ needs.check-release.outputs.LATEST_GITEA_VERSION }}

  release-build:
    if: needs.check-release.outputs.RELEASE_SKIP == '0'
    needs: [ check-release ]
    name: Build release docker image
    uses: "./.github/workflows/call.yaml"
    secrets: inherit
    with:
      GITEA_TAG: ${{ needs.check-release.outputs.RELEASE_GIT_VERSION }}
      DOCKER_TAG: ${{ needs.check-release.outputs.RELEASE_DOCKER_TAG }}
      GITEA_REPO: "https://github.com/go-gitea/gitea.git"
      GITEA_VERSION: ${{ needs.check-release.outputs.RELEASE_GITEA_VERSION }}

@Zettat123
Copy link
Copy Markdown
Contributor Author

I'm looking at the action_run_job.child_run_id and action_run.parent_job_id column and it's showing as NULL. I had to update manually:

Thank you for reporting this bug. It's fixed by f6d6462

@Sirherobrine23
Copy link
Copy Markdown
Contributor

gitea/models/actions/run.go

Lines 201 to 203 in 6372cd7

SetExpr("num_action_runs",
builder.Select("count(*)").From("action_run").
Where(builder.Eq{"repo_id": repo.ID}),

changes count(*) to count(parent_job_id = 0)

@Sirherobrine23
Copy link
Copy Markdown
Contributor

You will need to modify these files for the artifacts folder:

artifacts, total, err := db.FindAndCount[actions_model.ActionArtifact](ctx, actions_model.FindArtifactsOptions{
RepoID: repoID,
RunID: runID,
ArtifactName: artifactName,
FinalizedArtifactsV4: true,
ListOptions: utils.GetListOptions(ctx),
})

artifacts, err := db.Find[actions_model.ActionArtifact](ctx, actions_model.FindArtifactsOptions{
RunID: run.ID,
ArtifactName: artifactName,
})

artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{
RunID: runID,
Status: int(actions.ArtifactStatusUploadConfirmed),
})

artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{
RunID: runID,
Status: int(actions.ArtifactStatusUploadConfirmed),
})

artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{
RunID: runID,
ArtifactName: itemPath,
Status: int(actions.ArtifactStatusUploadConfirmed),
})

artifacts, err := db.Find[actions_model.ActionArtifact](ctx, actions_model.FindArtifactsOptions{
RepoID: repoID,
RunID: run.ID,
})

recordsToDelete = append(recordsToDelete, &actions_model.ActionArtifact{
RepoID: repoID,
RunID: run.ID,
})

@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch from 44c0638 to 028e9cb Compare March 17, 2026 03:09
@Sirherobrine23
Copy link
Copy Markdown
Contributor

Your last commit stopped showing the workflow childs (i use this rebase code Sirherobrine23@be75b0d):

Gravacao.da.tela.2026_03_17.15-55-07.mp4

@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch from 028e9cb to 6e21b4f Compare March 18, 2026 04:20
@github-actions github-actions bot removed modifies/api This PR adds API routes or modifies them modifies/templates This PR modifies the template files modifies/frontend labels Mar 18, 2026
@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch 2 times, most recently from 7d729c0 to cf3fabb Compare March 18, 2026 04:26
@Zettat123
Copy link
Copy Markdown
Contributor Author

Hi @Sirherobrine23, thanks for testing this PR. I’ve actually been working on bug fixes for the past few days. Unfortunately, the ParentJob-ChildRun hierarchy introduced by this PR broke almost all logic related to Run-Job relationships, and some of that affected logic is effectively unfixable.

As a result, I’ve had to abandon the previous implementation and begin a refactor to remove the "ChildRun" concept entirely. This work is still in progress, and there are many bugs and missing features. I appreciate your testing and suggestions, but please note that since this PR is still in active development, be sure to back up all your data before testing.

@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch 4 times, most recently from 86e13db to d3fd84e Compare March 22, 2026 01:20
@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Mar 22, 2026
@Zettat123 Zettat123 force-pushed the reusable-workflow-log-2 branch from 3672bd6 to 5f709d0 Compare March 25, 2026 20:36
@bircni
Copy link
Copy Markdown
Member

bircni commented Apr 3, 2026

Updates?

@Zettat123
Copy link
Copy Markdown
Contributor Author

This PR is now blocked by #37119. Will continue after #37119 is completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/dependencies modifies/frontend modifies/go Pull requests that update Go code modifies/migrations pr/wip This PR is not ready for review topic/gitea-actions related to the actions of Gitea

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants