forgejo-federation/services/actions
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
..
auth.go Add ac claim for old docker/build-push-action@v3 / current buildx gha cache (#29584) 2024-03-11 23:36:58 +07:00
auth_test.go Add interface{} to any replacement to make fmt, exclude *.pb.go (#30461) 2024-04-15 20:01:36 +02:00
cleanup.go Expire artifacts before deleting them physically (#29241) 2024-02-23 09:06:14 +01:00
clear_tasks.go Use db.Find instead of writing methods for every object (#28084) 2023-11-24 03:49:41 +00:00
commit_status.go fix(actions): call automerge service on successful commit state 2024-04-15 16:17:45 +02:00
init.go Move notification interface to services layer (#26915) 2023-09-05 18:37:47 +00:00
interface.go feat(api): enhance Actions Secrets Management API for repository (#30656) 2024-04-28 15:39:01 +02:00
job_emitter.go Improve the handling of jobs.<job_id>.if (#31070) 2024-06-02 09:08:07 +02:00
job_emitter_test.go Improve the handling of jobs.<job_id>.if (#31070) 2024-06-02 09:08:07 +02:00
main_test.go [ACTIONS] skip superflous pull request synchronized event (#2314) 2024-02-11 13:06:54 +00:00
notifier.go fix: hook post-receive for sha256 repos 2024-05-15 16:43:16 +02:00
notifier_helper.go Enable unparam linter (#31277) 2024-06-16 13:42:58 +02:00
notifier_helper_test.go [ACTIONS] skip superflous pull request synchronized event (#2314) 2024-02-11 13:06:54 +00:00
rerun.go Fix bugs in rerunning jobs (#29955) 2024-03-26 19:04:26 +01:00
rerun_test.go Fix bugs in rerunning jobs (#29955) 2024-03-26 19:04:26 +01:00
schedule_tasks.go Interpolate runs-on with variables when scheduling tasks (#30640) 2024-04-28 15:39:00 +02:00
variables.go Add API for Variables (#29520) 2024-04-07 10:57:53 +02:00
workflows.go Add support for workflow_dispatch (#3334) 2024-06-28 05:17:11 +00:00