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

github.rest.actions.createWorkflowDispatch does not trigger a run #250

Closed
bennypowers opened this issue Mar 16, 2022 · 6 comments
Closed

Comments

@bennypowers
Copy link

Describe the bug
I've written a step which should trigger a workflow_dispatch run in my repo, but nothing happens

To Reproduce

 - name: Bundle
    id: bundle
    if: ${{ steps.changesets.outputs.published == 'true' }}
    uses: actions/github-script@v6
    with:
      debug: ${{ secrets.ACTIONS_RUNNER_DEBUG }}
      github-token: ${{ secrets.GITHUB_TOKEN }}
      script: |
        try {
          const result = await github.rest.actions.createWorkflowDispatch({
            owner: 'patternfly',
            repo: 'patternfly-elements',
            workflow_id: 'bundle.yml',
            ref: 'main',
            inputs: {
              tags: ${{ steps.get-tags.outputs.tags }}
            },
          })
          console.log(result);
        } catch(error) {
          console.error(error);
          core.setFailed(error);
        }

In this case, This is what I observed logged in the run:

{
  status: 204,
  url: 'https://api.github.com/repos/patternfly/patternfly-elements/actions/workflows/bundle.yml/dispatches',
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
    connection: 'close',
    'content-security-policy': "default-src 'none'",
    date: 'Wed, 16 Mar 2022 23:27:24 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
    vary: 'Accept-Encoding, Accept, X-Requested-With',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-media-type': 'github.v3',
    'x-github-request-id': '07C1:3CFD:580A27:F241C1:6232725C',
    'x-ratelimit-limit': '1000',
    'x-ratelimit-remaining': '947',
    'x-ratelimit-reset': '1647475036',
    'x-ratelimit-resource': 'core',
    'x-ratelimit-used': '53',
    'x-xss-protection': '0'
  },
  data: undefined
}

I've tried several approaches here and I'm really at a loss. What could account for this? Do I need a separate github PAT?

@joshmgross
Copy link
Member

👋 Hey @bennypowers, you'll need to use a separate GitHub PAT. Events triggered with the GITHUB_TOKEN won't trigger other workflows.

https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow

@bennypowers
Copy link
Author

Yep, that did it. Thanks!

@joshmgross
Copy link
Member

👋 Hey @bennypowers, this is now supported without using a separate PAT

https://github.blog/changelog/2022-09-08-github-actions-use-github_token-with-workflow_dispatch-and-repository_dispatch/

almereyda added a commit to federated-wiki/wiki-oci-base that referenced this issue Jan 2, 2024
This adds an update-downstream job which dispatches the increase-base-version workflow in the wiki-oci-distribution repository to sync the base version.

This is largely based on:

* actions/github-script#250
* https://github.blog/changelog/2022-09-08-github-actions-use-github_token-with-workflow_dispatch-and-repository_dispatch/
@shrumsowen11
Copy link

shrumsowen11 commented Jan 26, 2024

Hello @joshmgross ,
I am trying to update the github-script from v3 to either v6 or v7.

Current github script v3 uses



 Some-job:
   runs-on: someRunner
   steps:
     -  name: Trigger "jobName"
        uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GH_PAT_TOKEN}}
          script: |
            await github.repos.createDispatchEvent({
              owner: context.repo.owner,
              repo: context.repo.repo,
              event_type: 'eventName',
              client_payload: { somekey Values}
          });

and the respective event 'eventName' looks like

name: another Job

on:
  repository_dispatch:
    types: [ eventName ]

jobs:
  Some-other-job:
    name: jobname
    runs-on: someRunner

    steps:
      - name: Construct URLs from client_payload
        id: construct-urls
        run: |
          urls=$(echo '${{ toJson(github.event.client_payload) }}' | jq -r 'to_entries | map("\(.value)") | join(",")')
          echo "URLs=$urls" >> $GITHUB_ENV
      - name: stepname
        uses: mycustomAction@v1
        with:
          username: ${{ user }}
          password: ${{ pass }}
          urls: ${{ env.URLs }}

I have updated the github script to v7 but it looks like the github.repos.createDispatchEvent is not available for this version anymore
I need to acquire the same result using the latest github script version, can you help on this

@joshmgross
Copy link
Member

@shrumsowen11 see https://github.com/actions/github-script#v5, github.repos should be available as github.rest.repos

@shrumsowen11
Copy link

@shrumsowen11 see https://github.com/actions/github-script#v5, github.repos should be available as github.rest.repos

Thanks a bunch @joshmgross , had tried few other things but missed this one. It works with
github.rest.repos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants