forgejo/modules/structs
Mai-Lapyst 51735c415b Add support for workflow_dispatch (#3334)
Closes #2797

I'm aware of https://github.com/go-gitea/gitea/pull/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 <earl-warren@noreply.codeberg.org>
Co-authored-by: Mai-Lapyst <mai-lapyst@noreply.codeberg.org>
Co-committed-by: Mai-Lapyst <mai-lapyst@noreply.codeberg.org>
2024-06-28 05:17:11 +00:00
..
activity.go Document possible action types for the user activity feed API (#31196) 2024-06-09 11:13:39 +02:00
activitypub.go
admin_user.go Do not require login_name & source_id for /admin/user/{username} 2024-04-17 10:33:52 +02:00
attachment.go
commit_status.go Restore warning commit status (#27504) 2023-10-08 22:16:06 +00:00
commit_status_test.go refactor improve NoBetterThan (#26126) 2023-07-26 08:52:07 +00:00
cron.go
doc.go
fork.go
git_blob.go
git_hook.go
hook.go Add support for workflow_dispatch (#3334) 2024-06-28 05:17:11 +00:00
issue.go Make gitea webhooks openproject compatible (gitea#28435) 2024-06-05 15:58:51 +02:00
issue_comment.go [FEAT] allow setting the update date on issues and comments 2024-02-05 14:44:33 +01:00
issue_label.go Support using label names when changing issue labels (#30943) 2024-05-19 13:12:35 +02:00
issue_milestone.go
issue_reaction.go
issue_stopwatch.go
issue_test.go
issue_tracked_time.go
lfs_lock.go
mirror.go Fix push mirror, wrong timestamp format (#27153) 2023-09-23 12:15:05 +00:00
miscellaneous.go
moderation.go [MODERATION] User blocking 2024-02-05 15:56:45 +01:00
nodeinfo.go
notifications.go
org.go Allow Organisations to have a E-Mail (#25082) 2023-07-25 08:26:27 +00:00
org_member.go
org_team.go Increase max length of org team names from 30 to 255 characters (#31410) 2024-06-23 12:21:38 +02:00
package.go Fix package webhook (#27839) 2023-10-31 04:43:38 +00:00
pull.go Make gitea webhooks openproject compatible (gitea#28435) 2024-06-05 15:58:51 +02:00
pull_review.go [GITEA] POST /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments 2024-02-05 16:09:42 +01:00
release.go [FEAT]Add Option to hide Release Archive links (#3139) 2024-04-24 15:15:55 +00:00
repo.go Add topics for repository API (#31127) 2024-06-02 16:26:54 +02:00
repo_actions.go Add API endpoints for getting action jobs status (#26673) 2024-05-05 12:15:40 +01:00
repo_branch.go [FEAT] Configure if protected branch rule should apply to admins 2024-03-29 00:21:49 +01:00
repo_collaborator.go
repo_commit.go Add file status for API "Get a single commit from a repository" (#16205) (#25831) 2023-07-20 16:35:47 +08:00
repo_compare.go feat(api): implement branch/commit comparison API (#30349) 2024-04-21 11:58:18 +02:00
repo_file.go Refactor "Content" for file uploading (#25851) 2023-07-18 18:14:47 +00:00
repo_flags.go [FEAT] API support for repository flags 2024-02-05 16:09:42 +01:00
repo_key.go
repo_note.go
repo_refs.go
repo_tag.go Add tag protection via rest api #17862 (#31295) 2024-06-16 13:42:59 +02:00
repo_topic.go
repo_tree.go
repo_watch.go Replace interface{} with any (#25686) 2023-07-04 18:36:08 +00:00
repo_wiki.go
secret.go refactor(API): refactor secret creation and update functionality (#26751) 2023-08-28 13:08:19 +08:00
settings.go Allow instance-wide disabling of forking 2024-02-25 12:00:17 +01:00
status.go
task.go
user.go Make gitea webhooks openproject compatible (gitea#28435) 2024-06-05 15:58:51 +02:00
user_app.go
user_email.go
user_gpgkey.go
user_key.go
variable.go Add API for Variables (#29520) 2024-04-07 10:57:53 +02:00
visible_type.go
workflow.go Add support for workflow_dispatch (#3334) 2024-06-28 05:17:11 +00:00