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

PRs created don't trigger other actions #48

Closed
abatilo opened this issue Sep 28, 2019 · 28 comments · Fixed by hapijs/tlds#9
Closed

PRs created don't trigger other actions #48

abatilo opened this issue Sep 28, 2019 · 28 comments · Fixed by hapijs/tlds#9
Labels
has workaround This issue has a workaround

Comments

@abatilo
Copy link

abatilo commented Sep 28, 2019

It seems that any PRs that get created by this action will not trigger any actions waiting on a pull request event, which means that you can have any required status checks.

Any ideas for how to get around this?

@peter-evans
Copy link
Owner

peter-evans commented Sep 28, 2019

This is a deliberate limitation imposed by GitHub Actions that an action cannot trigger other workflows. From the documentation:

An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.

https://help.github.com/en/articles/events-that-trigger-workflows#example-using-more-than-one-event

I'm not sure if there are any work arounds. I guess you would need another event to trigger the additional workflow.

@peter-evans
Copy link
Owner

peter-evans commented Sep 28, 2019

I've found a work around. It looks like GitHub are determining that API calls are coming from actions by checking the authentication token. If you use a repo scoped token instead of the default GITHUB_TOKEN then the on: pull_request workflow will run checks against the created pull request.

Create a repo scoped token at https://github.com/settings/tokens and then add it as a secret to the repository your workflow runs in. It will be under https://github.com/[username]/[repo]/settings/secrets

Use that secret in your workflow and assign it to the environment variable GITHUB_TOKEN.

    - name: Create Pull Request
      uses: peter-evans/create-pull-request@v1.3.1
      env:
        GITHUB_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}

There is a downside to this method. The PR is no longer created by the github-actions bot user and instead appears to be created by the user associated with the token.

image

@peter-evans
Copy link
Owner

I contacted GitHub about this issue and their response confirms that using a personal token as I outlined above is the correct approach.

From GitHub Support:

This is a deliberate decision by the Actions team in order to prevent accidental "infinite loop" situations, and as an anti-abuse measure.
You will be able to work around this using a Personal Access Token in place of the provided token. As this needs to be explicitly provided it will remove any potential for possible abuse, so we recommend using this method when needing to create a pull request.

@Mike-E-angelo
Copy link

Mike-E-angelo commented Dec 4, 2019

Ah what a pain. Resorting to a token that applies to every repository of the user without being able to scope specifically to the desired repository is quite the security concern.

(My complaints are to GitHub, not this repo BUT SOMEONE MUST HEAR ME AS I SHOUT POWERLESS INTO THE VOID!! 😅)

@Mike-E-angelo
Copy link

Hey all, check it out... another possible workaround is to use an on.schedule.cron trigger as discussed here:

pascalgn/automerge-action#37 (comment)

Here's my (sample/testing 😁) configuration:

https://github.com/ExtendedXmlSerializer/NextRelease/blob/959614d9e72c08f80d7e71a0e52265a42ed91c75/.github/workflows/automerge.yml#L25-L30

Not as elegant as a direct trigger, but certainly better than having to resort to a Personal Access Token.

Thought I'd share. 👍

@dogmatic69
Copy link

There is a massive drawback to using this token, if a repository owner uses a personal token they will not be able to request changes nor approve a PR. This is due to the fact that the PR will be created by the owner.

@peter-evans
Copy link
Owner

Thanks to @proudust for bringing it to my attention, an alternative to using a PAT is SSH Deploy keys that can be set per repository. See the documentation here for how to use Deploy keys with create-pull-request action. Note that this method will only trigger push workflows, not pull_request, so checks must be in an on: push workflow.

@peter-evans
Copy link
Owner

Using deploy keys is now even easier because actions/checkout now supports checkout with SSH keys. See the updated documentation here.

@brockfanning
Copy link

Sorry if this has been explained - do I understand correctly that if the repository needs to have workflows triggered on pull_request and has a branch rule requiring that status checks pass, a PAT is the only option? Otherwise, the generated PR will be stuck in "Waiting for status to be reported" and won't be able to be merged?

@peter-evans
Copy link
Owner

peter-evans commented Apr 5, 2020

@brockfanning There are actually a number of different workarounds now with various pros and cons. I've summarised them and updated the documentation here.

https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs

fedepaol added a commit to fedepaol/metallb-operator that referenced this issue Feb 13, 2024
Currently, PRs filed by the automation does not run CI. This requires
some leap of faith in order to merge them.
As per peter-evans/create-pull-request#48
and https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens

using a github app token should make the trick.

Signed-off-by: Federico Paolinelli <fpaoline@redhat.com>
timmysilv added a commit to PennyLaneAI/pennylane that referenced this issue Feb 13, 2024
**Context:**
There are many difficulties with dependency management, and this PR
tries to address two of them:
- reproducible versions of PL+deps from a past version
- ability to view which deps have been auto-updated (eg. a new version
of an unbound dep is released) and when

**Description of the Change:**
- Factor out the python environment setup to its own file. All default
package versions are here now
- Update `interface-unit-tests` to trigger the upload of `pip freeze`
results as artifacts for later use. happens in the `core`, `jax`, `tf`,
`torch`, `all-interfaces` and `external` test suites today (ensured that
it only occurs on one worker using `strategy.job-index`)
- Add the `upload-stable-deps` workflow to run after tests complete. The
action only runs on merge commits to master, so users shouldn't see it.
This is the real new feature, and here's how it works:
1. create the branch `bot/stable-deps-update` (or rebases it on master
if it already existed)
2. delete the existing requirement files in `.github/stable/` to avoid
merge conflicts
3. download the previously-uploaded requirement files generated in this
flow to that same folder and check if there's a diff
  4. if no diff, do nothing!
5. if there's a diff and no PR exists, it opens one and tags me (and
hopefully the team because of CODEOWNERS)
6. if there's a diff and a PR already exists, it just pushes to the
existing PR branch (confirmed this is the case despite the open-pr step
running - it just does nothing in that case)

**Benefits:**
Helps with both difficulties mentioned in the context section above

**Possible Drawbacks:**
- the team will have to review this PR (if it becomes too noisy, we can
turn this into a cronjob)
- commits made by bots (eg. actions that use `${{ secrets.GITHUB_TOKEN
}}`) will not trigger CI, so the automated PRs need to have it triggered
manually. A hack to fix this is proposed
[here](peter-evans/create-pull-request#48 (comment))
if we want to consider that, but this is a feature of GitHub (not a
bug), intended to avoid infinite CI loops

I will do something similar for the docs builds after this PR is merged,
it's complex enough for now.

[sc-56376]
Gabriel-Bottrill pushed a commit to QSAR-UBC/pennylane_qutrit_mixed that referenced this issue Feb 14, 2024
**Context:**
There are many difficulties with dependency management, and this PR
tries to address two of them:
- reproducible versions of PL+deps from a past version
- ability to view which deps have been auto-updated (eg. a new version
of an unbound dep is released) and when

**Description of the Change:**
- Factor out the python environment setup to its own file. All default
package versions are here now
- Update `interface-unit-tests` to trigger the upload of `pip freeze`
results as artifacts for later use. happens in the `core`, `jax`, `tf`,
`torch`, `all-interfaces` and `external` test suites today (ensured that
it only occurs on one worker using `strategy.job-index`)
- Add the `upload-stable-deps` workflow to run after tests complete. The
action only runs on merge commits to master, so users shouldn't see it.
This is the real new feature, and here's how it works:
1. create the branch `bot/stable-deps-update` (or rebases it on master
if it already existed)
2. delete the existing requirement files in `.github/stable/` to avoid
merge conflicts
3. download the previously-uploaded requirement files generated in this
flow to that same folder and check if there's a diff
  4. if no diff, do nothing!
5. if there's a diff and no PR exists, it opens one and tags me (and
hopefully the team because of CODEOWNERS)
6. if there's a diff and a PR already exists, it just pushes to the
existing PR branch (confirmed this is the case despite the open-pr step
running - it just does nothing in that case)

**Benefits:**
Helps with both difficulties mentioned in the context section above

**Possible Drawbacks:**
- the team will have to review this PR (if it becomes too noisy, we can
turn this into a cronjob)
- commits made by bots (eg. actions that use `${{ secrets.GITHUB_TOKEN
}}`) will not trigger CI, so the automated PRs need to have it triggered
manually. A hack to fix this is proposed
[here](peter-evans/create-pull-request#48 (comment))
if we want to consider that, but this is a feature of GitHub (not a
bug), intended to avoid infinite CI loops

I will do something similar for the docs builds after this PR is merged,
it's complex enough for now.

[sc-56376]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround This issue has a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.