forgejo/modules
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
..
actions Add support for workflow_dispatch (#3334) 2024-06-28 05:17:11 +00:00
activitypub FIX: use proper time format (activitypub/client) (#4132) 2024-06-14 15:22:37 +00:00
analyze
assetfs
auth Enable unparam linter (#31277) 2024-06-16 13:42:58 +02:00
avatar Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
base Refactor sha1 and time-limited code (#31023) 2024-05-26 18:43:30 +02:00
cache [PORT] Add cache test for admins (#31265) 2024-06-23 11:38:35 +02:00
charset
container
csv
emoji
eventsource
forgefed fix review 2024-05-29 18:31:06 +02:00
generate
git Enable unparam linter (#31277) 2024-06-16 13:42:58 +02:00
gitgraph Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
gitrepo
graceful
hcaptcha
highlight
hostmatcher
html
httpcache
httplib
indexer Fix bug filtering issues which have no project (#31337) 2024-06-16 13:42:59 +02:00
issue/template Support setting the default attribute of the issue template dropdown field (#31045) 2024-05-26 20:13:09 +02:00
json
label
lfs Fix #31185 try fix lfs download from bitbucket failed (#31201) 2024-06-16 13:42:59 +02:00
log Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
markup Fix markdown math brackets render problem (#31420) 2024-06-23 12:40:06 +02:00
mcaptcha
metrics Rename project board -> column to make the UI less confusing (#30170) 2024-06-02 09:42:39 +02:00
migration
nosql
optional
options
packages Extract and display readme and comments for Composer packages (#30927) 2024-06-16 13:42:59 +02:00
paginator
pprof
private Move database operations of merging a pull request to post receive hook and add a transaction (#30805) 2024-05-12 20:03:10 +02:00
process Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
proxy
proxyprotocol
public
queue chore(deps): update module github.com/redis/go-redis/v9 to v9.5.2 2024-06-04 12:38:35 +02:00
recaptcha
references Refactor to use UnsafeStringToBytes (#31358) 2024-06-16 13:42:58 +02:00
regexplru
repository fix(repository): git push to an adopted repository fails 2024-06-16 19:06:06 +02:00
secret
session
setting Add support for workflow_dispatch (#3334) 2024-06-28 05:17:11 +00:00
sitemap
ssh
storage test(avatar): deleting a user avatar is idempotent 2024-06-05 09:10:42 +02:00
structs Add support for workflow_dispatch (#3334) 2024-06-28 05:17:11 +00:00
svg
sync
system Refactor to use UnsafeStringToBytes (#31358) 2024-06-16 13:42:58 +02:00
templates Add slogan config (#3752) 2024-06-07 17:12:48 +00:00
test test(util): MockProtect when mocking multiple times 2024-06-02 15:24:06 +02:00
testlogger Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
timeutil
translation
turnstile
typesniffer Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
updatechecker
uri
user
util Refactor to use UnsafeStringToBytes (#31358) 2024-06-16 13:42:58 +02:00
validation added validation fixes 2024-05-14 08:31:34 +02:00
web Delete legacy cookie before setting new cookie (#31306) 2024-06-16 08:21:32 +02:00
webhook Add support for workflow_dispatch (#3334) 2024-06-28 05:17:11 +00:00