Skip to content
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

Merged

Conversation

pangliang
Copy link
Contributor

@pangliang pangliang commented Nov 22, 2023

fix #23668

My plan:

  • In the actions.list method, if workflow is selected and IsAdmin, check whether the on event contains workflow_dispatch. If so, display a Run workflow button to allow the user to manually trigger the run.
  • Providing a form that allows users to select target brach or tag, and these parameters can be configured in yaml
  • Simple form validation, required input cannot be empty
  • Add a route /actions/run, and an actions.Run method to handle
  • Add WorkflowDispatchPayload struct to pass the Webhook event payload to the runner when triggered, this payload carries the inputs values and other fields, doc: workflow_dispatch payload

Other PRs

  • the 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.

  • Doc Said: This event will only trigger a workflow run if the workflow file is on the default branch.
    • If the workflow yaml file only exists in a non-default branch, it cannot be triggered. (It will not even show up in the workflow list)
    • If the same workflow yaml file exists in each branch at the same time, the version of the default branch is used. Even if Use workflow from selects another branch

image

name: Docker Image CI

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
      environment:
        description: 'Environment to run tests against'
        type: environment
        required: true
        default: 'environment values'
      number_required_1:
        description: 'number '
        type: number
        required: true
        default: '100'
      number_required_2:
        description: 'number'
        type: number
        required: true
        default: '100'
      number_required_3:
        description: 'number'
        type: number
        required: true
        default: '100'
      number_1:
        description: 'number'
        type: number
        required: false
      number_2:
        description: 'number'
        type: number
        required: false
      number_3:
        description: 'number'
        type: number
        required: false

env:
  inputs_logLevel:              ${{ inputs.logLevel }}
  inputs_tags:                  ${{ inputs.tags }}
  inputs_boolean_default_true:  ${{ inputs.boolean_default_true }}
  inputs_boolean_default_false: ${{ inputs.boolean_default_false }}
  inputs_environment:           ${{ inputs.environment }}
  inputs_number_1:              ${{ inputs.number_1  }}
  inputs_number_2:              ${{ inputs.number_2  }}
  inputs_number_3:              ${{ inputs.number_3  }}
  inputs_number_required_1:     ${{ inputs.number_required_1  }}
  inputs_number_required_2:     ${{ inputs.number_required_2  }}
  inputs_number_required_3:     ${{ inputs.number_required_3  }}

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: ls -la
      - run: env | grep inputs
      - run: echo ${{ inputs.logLevel }}
      - run: echo ${{ inputs.boolean_default_false }}

image
image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 22, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 22, 2023
@wizpresso-steve-cy-fan
Copy link

Well, the problem is, you can specify some user-supplied fields for workflow_dispatch, have you handled that case as well?

@lunny lunny added the topic/gitea-actions related to the actions of Gitea label Nov 23, 2023
@pangliang
Copy link
Contributor Author

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

@pangliang pangliang force-pushed the actions_support_workflow_dispatch_event branch from 170e929 to b3b5544 Compare November 29, 2023 16:43
@pangliang pangliang changed the title WIP: Actions support workflow dispatch event Actions support workflow dispatch event Nov 29, 2023
@yp05327
Copy link
Contributor

yp05327 commented Nov 30, 2023

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
image
Should we also follow this note?

@yp05327
Copy link
Contributor

yp05327 commented Nov 30, 2023

In the actions.list method, if workflow is selected and IsAdmin, check whether the on event contains workflow_dispatch. If so, display a Run workflow button to allow the user to manually trigger the run.

IMO, this notification takes too many spaces, and we don't need to always display it at there?
How about put it into the dropdown menu?
image

Not a block, feel free to discus.

@pangliang pangliang changed the title Actions support workflow dispatch event WIP: Actions support workflow dispatch event Nov 30, 2023
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 5, 2023
@pangliang pangliang force-pushed the actions_support_workflow_dispatch_event branch from 2f14a4a to 3bec7d1 Compare December 5, 2023 05:24
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 5, 2023
@pangliang
Copy link
Contributor Author

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch image Should we also follow this note?

I think it should be following now.

  • When list workflow, DefaultBranch is used
  • When running workflow_dispatch workflow, the target ref is selected and specified, but the workflow configuration still uses DefaultBranch

@pangliang
Copy link
Contributor Author

In the actions.list method, if workflow is selected and IsAdmin, check whether the on event contains workflow_dispatch. If so, display a Run workflow button to allow the user to manually trigger the run.

IMO, this notification takes too many spaces, and we don't need to always display it at there? How about put it into the dropdown menu? image

Not a block, feel free to discus.

At first I also tried to put it in the dropdown menu, but there was a confusing problem. When no child elements exist, the dropdown menu will not hide automatically. Then it is more difficult to deal with when to display the button

if a or b or c or .... then
   <dropdown>
          if a then
              <menu a>
          end
          if b then
              <menu b>
          end
          ...
   </dropdown>
end

I don't know, I feel a little OCD here

Maybe I'm using it the wrong way, so I copied the design from github
If you have a good solution please tell me, Or I can put it in dropdown. After all, there are only two if conditions now.

@pangliang pangliang changed the title WIP: Actions support workflow dispatch event Actions support workflow dispatch event Dec 5, 2023
go.mod Outdated Show resolved Hide resolved
@yp05327
Copy link
Contributor

yp05327 commented Dec 7, 2023

image
It is a required input, but it is empty.

go.mod Outdated Show resolved Hide resolved
routers/web/repo/actions/actions.go Outdated Show resolved Hide resolved
@yp05327
Copy link
Contributor

yp05327 commented Dec 7, 2023

  • environment: gitea doesn't support the environment feature yet, right? Maybe act_runner uses environment as a keyword, so it can't get the value of inputs.environment

gitea doesn't support the environment feature yet, right? Maybe act_runner uses environment as a keyword, so it can't get the value of inputs.environment

If I set a default value, it works. Maybe it is caused by something else.
image
image

And if I change the default value, it will still be the default value.
So it seems that it will only display the default value, but not the value in the form.

@denyskon
Copy link
Member

I changed it to checkbox because it is more common throughout Gitea UI

@denyskon
Copy link
Member

Also, putting the titles of the input fields is equally common in Gitea UI. This long form is just an example and shouldn't normally contain so many fields. We can make it wider, however, just to look better.

@lunny
Copy link
Member

lunny commented Aug 17, 2024

Also, putting the titles of the input fields is equally common in Gitea UI. This long form is just an example and shouldn't normally contain so many fields. We can make it wider, however, just to look better.

Yes, wider is better.

@denyskon
Copy link
Member

grafik

That would be tiny instead of mini. Looks better IMO, normal size would be too wide.

@denyskon
Copy link
Member

grafik
(here with a more realistic example, taken from my production pipeline 😆 )

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Aug 17, 2024
@denyskon denyskon added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 17, 2024
@denyskon denyskon added the docs-update-needed The document needs to be updated synchronously label Aug 17, 2024
@github-actions github-actions bot removed the docs-update-needed The document needs to be updated synchronously label Aug 18, 2024
@yp05327
Copy link
Contributor

yp05327 commented Aug 18, 2024

image
Why removed ???

@techknowlogick
Copy link
Member

Thanks so much @pangliang !!!

@techknowlogick techknowlogick merged commit 36232b6 into go-gitea:main Aug 19, 2024
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 19, 2024
@lunny lunny added the docs-update-needed The document needs to be updated synchronously label Aug 19, 2024
@lunny
Copy link
Member

lunny commented Aug 19, 2024

Please send a docs PR to https://gitea.com/gitea/docs

@pangliang pangliang deleted the actions_support_workflow_dispatch_event branch August 19, 2024 10:25
zjjhot added a commit to zjjhot/gitea that referenced this pull request Aug 20, 2024
* giteaofficial/main:
  add CfTurnstileSitekey context data to all captcha templates (go-gitea#31874)
  Add tag name in the commits list (go-gitea#31082)
  Fix actions notify bug (go-gitea#31866)
  Actions support workflow dispatch event (go-gitea#28163)
4kProgrammer added a commit to 4kProgrammer/gitea that referenced this pull request Aug 20, 2024
@hoo29 hoo29 mentioned this pull request Sep 4, 2024
@FireGhost
Copy link

Why has this feature been removed from 1.22.2 in the end ?

@Janhouse
Copy link

@FireGhost this is part of 1.23, wait for release.

@go-gitea go-gitea locked and limited conversation to collaborators Sep 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs-update-needed The document needs to be updated synchronously lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. topic/gitea-actions related to the actions of Gitea type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Actions - Manually trigger a workflow/action