mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
feat: support jobs.<job_id>.secrets with reusable workflow expansion (#10627)
Follow-up to #10525; adds support for `jobs.<job_id>.secrets` to expanded reusable workflows (when no `runs-on` is specified in a job that `uses: ...` another workflow). ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). - **end-to-end testing**: [prepared, PR n](https://code.forgejo.org/forgejo/end-to-end/pulls/1351) ### Documentation - [x] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] Doc to be created - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10627 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
This commit is contained in:
parent
d8a5ee81fb
commit
9b2f7c557b
11 changed files with 654 additions and 33 deletions
|
|
@ -208,6 +208,30 @@ func (run *ActionRun) SetDefaultConcurrencyGroup() {
|
|||
))
|
||||
}
|
||||
|
||||
func (run *ActionRun) FindOuterWorkflowCall(ctx context.Context, innerCall *ActionRunJob) (*ActionRunJob, error) {
|
||||
allJobs, err := GetRunJobsByRunID(ctx, run.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failure to get run jobs: %w", err)
|
||||
}
|
||||
if innerCall.workflowPayloadDecoded == nil || innerCall.workflowPayloadDecoded.Metadata.WorkflowCallParent == "" {
|
||||
return nil, errors.New("invalid state for FindOuterWorkflowCall")
|
||||
}
|
||||
parent := innerCall.workflowPayloadDecoded.Metadata.WorkflowCallParent
|
||||
for _, job := range allJobs {
|
||||
if job.ID == innerCall.ID {
|
||||
continue
|
||||
}
|
||||
swf, err := job.DecodeWorkflowPayload()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if swf.Metadata.WorkflowCallID == parent {
|
||||
return job, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no workflow call with ID %s found in run %d", parent, run.ID)
|
||||
}
|
||||
|
||||
func actionsCountOpenCacheKey(repoID int64) string {
|
||||
return fmt.Sprintf("Actions:CountOpenActionRuns:%d", repoID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,3 +272,58 @@ jobs:
|
|||
// Expect job with an incomplete runs-on to be StatusBlocked:
|
||||
assert.Equal(t, StatusBlocked, job.Status)
|
||||
}
|
||||
|
||||
func TestActionRun_FindOuterWorkflowCall(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
pullRequestPosterID := int64(4)
|
||||
repoID := int64(10)
|
||||
pullRequestID := int64(2)
|
||||
run := &ActionRun{
|
||||
RepoID: repoID,
|
||||
PullRequestID: pullRequestID,
|
||||
PullRequestPosterID: pullRequestPosterID,
|
||||
}
|
||||
|
||||
workflowRaw := []byte(`
|
||||
jobs:
|
||||
outer-job:
|
||||
uses: ./.forgejo/workflows/reusable.yml
|
||||
`)
|
||||
workflows, err := jobparser.Parse(workflowRaw, false,
|
||||
jobparser.WithJobOutputs(map[string]map[string]string{}),
|
||||
jobparser.ExpandLocalReusableWorkflows(func(job *jobparser.Job, path string) ([]byte, error) {
|
||||
return []byte(`
|
||||
on:
|
||||
workflow_call:
|
||||
jobs:
|
||||
inner-job-1:
|
||||
runs-on: debian
|
||||
steps: []
|
||||
inner-job-2:
|
||||
runs-on: debian
|
||||
steps: []
|
||||
`), nil
|
||||
}))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, InsertRun(t.Context(), run, workflows))
|
||||
|
||||
jobs, err := db.Find[ActionRunJob](t.Context(), FindRunJobOptions{RunID: run.ID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, jobs, 3)
|
||||
|
||||
for _, j := range jobs {
|
||||
t.Run(j.Name, func(t *testing.T) {
|
||||
_, err := j.DecodeWorkflowPayload()
|
||||
require.NoError(t, err)
|
||||
outer, err := run.FindOuterWorkflowCall(t.Context(), j)
|
||||
if j.Name == "outer-job" {
|
||||
require.ErrorContains(t, err, "invalid state for FindOuterWorkflowCall")
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, outer)
|
||||
assert.Equal(t, "outer-job", outer.Name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue