CircleCI-Public / trigger-circleci-pipeline-action

Trigger a CircleCI pipeline from any GitHub Actions event.
https://github.com/marketplace/actions/trigger-circleci-pipeline
47 stars 43 forks source link

Support events without a payload #15

Closed zackse closed 2 years ago

zackse commented 2 years ago

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!

zackse commented 2 years ago

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: ...