-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Actions support workflow dispatch event #28163
base: main
Are you sure you want to change the base?
Actions support workflow dispatch event #28163
Conversation
Well, the problem is, you can specify some user-supplied fields for workflow_dispatch, have you handled that case as well? |
I plan to implement a version similar to github, providing a form that allows users to fill in the env parameters of the workflow run, and these parameters can be configured in yaml. Hopefully I can complete it |
170e929
to
b3b5544
Compare
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch |
2f14a4a
to
3bec7d1
Compare
I think it should be following now.
|
I will give this UI another test. There are some minor tweaks left to do. |
Is it possible to include workflows from all branches in the list? |
@pangliang |
Is API endpoint for workflow_dispatch planned? |
Is this coming in any time soon? 😁 |
Planned for 1.23 given the milestones, still waiting for 1.22 so not tomorrow but I hope not too long too ! |
type WorkflowDispatchPayload struct { | ||
Workflow string `json:"workflow"` | ||
Ref string `json:"ref"` | ||
Inputs map[string]any `json:"inputs"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to keep the sequences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Workflow Dispatch Payload is to transmit data to act_runner, and the WorkflowDispatch
type in nektos/act
uses the kv structure. workflow.go#L77
To maintain order when displaying the inputs
form, need to create a separate new same type for the view and use an array to store the Inputs. Because I think it will not be accepted to directly modify the kv of nektos/act into an array.
Previously discussed here: (issuecomment-1859484485)[https://github.com//pull/28163#issuecomment-1859484485]
in short:
- New
WorkflowDispatchInput
WorkflowDispatch
andworkflowDispatchConfig
ingitea/routes/web/repo/actions/view.go
, to maintain the order of inputs in forms - Keep the kv of
WorkflowDispatchPayload
unchanged to adapt tonektos/act
What do you think? If you think it is feasible, I will modify it like this.
return | ||
} | ||
// always put default branch on the top if it exists | ||
if slices.Contains(branches, ctx.Repo.Repository.DefaultBranch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the first branch is not default branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic seems to be to ensure that the default branch is first; reference from: repo.go#L687
…low_dispatch_event * origin/main: (62 commits) Add test for go-gitea#30674 (go-gitea#30679) Fix border-radius of header+segment boxes (go-gitea#30667) Fix a panic bug when head repository deleting (go-gitea#30674) Fix some bug on migrations (go-gitea#30647) Fix checkbox field markup (go-gitea#30666) Avoid doubled border for the PR info segment (go-gitea#30663) Interpolate runs-on with variables when scheduling tasks (go-gitea#30640) Initial support for colorblindness-friendly themes (go-gitea#30625) Fix flash message for flex-container (go-gitea#30657) Perform Newest sort type correctly when sorting issues (go-gitea#30644) Fix project name wrapping, remove horizontal margin on header (go-gitea#30631) Add a db consistency check to remove runners that do not belong to a repository (go-gitea#30614) Fix wrong table name (go-gitea#30557) Fix compare api swagger (go-gitea#30648) [skip ci] Updated translations via Crowdin Fix queue test (go-gitea#30646) Enable jquery-related eslint rules that have no violations (go-gitea#30632) Enable more `revive` linter rules (go-gitea#30608) Remove obsolete CSS text classes (go-gitea#30576) Hide diff stats on empty PRs (go-gitea#30629) ...
Have you tested long branch name? |
I will, but the |
Branch selector will need more adjustments after #30803 merges. Sorry to hold this PR off, but it's basically previous contributor's fault for leaving it in such a messy and non-reusable state. |
No problem for holding the PR, and if things have to be improved, then things have to be improved. But it's not nice to put a blame like that to someone who is just trying to help and contribute... for free. Even if it's "technically true", no one is born knowing all the proper design patterns and all codebase's standards, etc... To every contributor -- thank you for improving Gitea 🧡 |
Closes #2797 I'm aware of go-gitea/gitea#28163 exists, but since I had it laying around on my drive and collecting dust, I might as well open a PR for it if anyone wants the feature a bit sooner than waiting for upstream to release it or to be a forgejo "native" implementation. This PR Contains: - Support for the `workflow_dispatch` trigger - Inputs: boolean, string, number, choice Things still to be done: - [x] API Endpoint `/api/v1/<org>/<repo>/actions/workflows/<workflow id>/dispatches` - ~~Fixing some UI bugs I had no time figuring out, like why dropdown/choice inputs's menu's behave weirdly~~ Unrelated visual bug with dropdowns inside dropdowns - [x] Fix bug where opening the branch selection submits the form - [x] Limit on inputs to render/process Things not in this PR: - Inputs: environment (First need support for environments in forgejo) Things needed to test this: - A patch for https://code.forgejo.org/forgejo/runner to actually consider the inputs inside the workflow. ~~One possible patch can be seen here: https://code.forgejo.org/Mai-Lapyst/runner/src/branch/support-workflow-inputs~~ [PR](https://code.forgejo.org/forgejo/runner/pulls/199) ![image](/attachments/2db50c9e-898f-41cb-b698-43edeefd2573) ## Testing - Checkout PR - Setup new development runner with [this PR](https://code.forgejo.org/forgejo/runner/pulls/199) - Create a repo with a workflow (see below) - Go to the actions tab, select the workflow and see the notice as in the screenshot above - Use the button + dropdown to run the workflow - Try also running it via the api using the `` endpoint - ... - Profit! <details> <summary>Example workflow</summary> ```yaml on: workflow_dispatch: inputs: logLevel: description: 'Log Level' required: true default: 'warning' type: choice options: - info - warning - debug tags: description: 'Test scenario tags' required: false type: boolean boolean_default_true: description: 'Test scenario tags' required: true type: boolean default: true boolean_default_false: description: 'Test scenario tags' required: false type: boolean default: false number1_default: description: 'Number w. default' default: '100' type: number number2: description: 'Number w/o. default' type: number string1_default: description: 'String w. default' default: 'Hello world' type: string string2: description: 'String w/o. default' required: true type: string jobs: test: runs-on: docker steps: - uses: actions/checkout@v3 - run: whoami - run: cat /etc/issue - run: uname -a - run: date - run: echo ${{ inputs.logLevel }} - run: echo ${{ inputs.tags }} - env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - run: echo "abc" ``` </details> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3334 Reviewed-by: Earl Warren <[email protected]> Co-authored-by: Mai-Lapyst <[email protected]> Co-committed-by: Mai-Lapyst <[email protected]>
I suggests adding a new API endpoint to facilitate the dispatching of workflows. It empowers developers and teams to automate repetitive tasks and orchestrate complex workflows efficiently. Create a workflow dispatch eventPayload:
Permissions:
Additional endpoints:
|
fix #23668
My plan:
actions.list
method, if workflow is selected and IsAdmin, check whether the on event containsworkflow_dispatch
. If so, display aRun workflow
button to allow the user to manually trigger the run.required
input cannot be empty/actions/run
, and anactions.Run
method to handleWorkflowDispatchPayload
struct to pass the Webhook event payload to the runner when triggered, this payload carries theinputs
values and other fields, doc: workflow_dispatch payloadOther PRs
Workflow.WorkflowDispatchConfig()
method still return non-nil when workflow_dispatch is not defined. I submitted a PR https://gitea.com/gitea/act/pulls/85 to fix it. Still waiting for them to process.Behavior should be same with github, but may cause confusion. Here's a quick reminder.
only
trigger a workflow run if the workflow file ison the default branch
.Use workflow from
selects another branch