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

Support events without a payload #15

Merged
merged 3 commits into from
Jun 17, 2022

Conversation

zackse
Copy link
Contributor

@zackse zackse commented Apr 7, 2022

The current code does not support the schedule event type because it does not have a request payload. This changeset updates the code to avoid requiring a payload for parsing out the repo owner and name.

In preparation for testing, I ran npm run lint && npm run format && npm run build which was in .husky/pre-commit and committed the results, but it's not clear to me if the package updates are dependent on my local (and likely broken) environment. It's a separate commit (186ad68) so it can more easily be removed from the PR if necessary.

My testing was limited to the schedule and workflow_dispatch (manual) events, both of which worked with this update. The schedule event does not have a payload, but the workflow_displatch does.

Hope this helps!

For example, 'on: schedule' does not have a payload[1], which results in
an error when attempting to use this action:

    TypeError: Cannot read property 'url' of undefined

This commit updates the code to use the `repo` attribute instead
of parsing out the repo org/name from the repo URL.

1. https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
```
npm run lint && npm run format && npm run build
```

Added this as a separate commit, as I don't know anything about npm
packages, and it's not clear if all of the package list changes are
desirable.
It may be preferable to set a v1 link and keep that updated to point to
the latest release.

Also mentioned in PR CircleCI-Public#11:
CircleCI-Public#11 (comment)
@zackse
Copy link
Contributor Author

zackse commented Apr 7, 2022

Here is the error message from a failed run before this changeset was applied:

Preparing CircleCI Pipeline Trigger
  /home/runner/work/_actions/CircleCI-Public/trigger-circleci-pipeline-action/v1.0.4/dist/index.js:12707
  const [, , repoOrg, repoName] = pattern.exec(payload.repository.url);
                                                                  ^
  TypeError: Cannot read property 'url' of undefined
      at /home/runner/work/_actions/CircleCI-Public/trigger-circleci-pipeline-action/v1.0.4/dist/index.js:12707:[6]
      at /home/runner/work/_actions/CircleCI-Public/trigger-circleci-pipeline-action/v1.0.4/dist/index.js:12[7]
      at Object.<anonymous> (/home/runner/work/_actions/CircleCI-Public/trigger-circleci-pipeline-action/v1.0.4/dist/index.js:12783:12)
      at Module._compile (internal/modules/cjs/loader.js:[9]
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:[10]
      at Module.load (internal/modules/cjs/loader.js:863:32)
      at Function.Module._load (internal/modules/cjs/loader.js:708:14)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:[12]
      at internal/main/run_main_module.js:[17]

Here is the associated workflow config file:

on:
  schedule:
    - cron: '*/15 * * * *'

jobs:
  trigger-circleci:
    runs-on: ubuntu-latest
    steps:
      - name: CircleCI trigger on schedule
        id: step1
        uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0.4
        env:
          CCI_TOKEN: ...

Copy link
Contributor

@KyleTryon KyleTryon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! looks good

@KyleTryon KyleTryon merged commit 21b9739 into CircleCI-Public:main Jun 17, 2022
omxela pushed a commit to mo-work/trigger-circleci-pipeline-action that referenced this pull request Oct 9, 2022
* support events that don't have a payload

For example, 'on: schedule' does not have a payload[1], which results in
an error when attempting to use this action:

    TypeError: Cannot read property 'url' of undefined

This commit updates the code to use the `repo` attribute instead
of parsing out the repo org/name from the repo URL.

1. https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule

* prepare build

```
npm run lint && npm run format && npm run build
```

Added this as a separate commit, as I don't know anything about npm
packages, and it's not clear if all of the package list changes are
desirable.

* README: unify version

It may be preferable to set a v1 link and keep that updated to point to
the latest release.

Also mentioned in PR CircleCI-Public#11:
CircleCI-Public#11 (comment)
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

Successfully merging this pull request may close these issues.

2 participants