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

Preview Action: Use pull_request_target to avoid token restriction #169

Merged
merged 1 commit into from
Apr 26, 2024

Conversation

vcanales
Copy link
Member

Due to restrictions imposed to the GH_TOKEN when forks are created from forks when workflows are triggered by the pull_request event, I'm switching the execution to be done on pull_request_trigger, which lifts said restrictions.

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

This event runs in the context of the base of the pull request, rather
than in the context of the merge commit, as the pull_request event does.
This prevents execution of unsafe code from the head of the pull request
that could alter your repository or steal any secrets you use in your
workflow. This event allows your workflow to do things like label or
comment on pull requests from forks. Avoid using this event if you need
to build or run code from the pull request.
@vcanales vcanales added bug Something isn't working enhancement New feature or request labels Apr 26, 2024
@vcanales vcanales changed the title Use pull_request_target to avoid token restriction Apr 26, 2024
Due to restrictions imposed to the `GH_TOKEN` when forks are created
    from forks when workflows are triggered by the pull_request event, I'm
    switching the execution to be done on `pull_request_trigger`, which
    lifts said restrictions.

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

    > This event runs in the context of the base of the pull request, rather
    than in the context of the merge commit, as the pull_request event does.
    This prevents execution of unsafe code from the head of the pull request
    that could alter your repository or steal any secrets you use in your
    workflow. This event allows your workflow to do things like label or
    comment on pull requests from forks. Avoid using this event if you need
    to build or run code from the pull request.

fix fetch
@vcanales vcanales force-pushed the preview-action/use-pull-request-target branch from 5867676 to 42aea1f Compare April 26, 2024 16:40
Copy link
Collaborator

@MaggieCabrera MaggieCabrera left a comment

Choose a reason for hiding this comment

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

Can't really test this until we merge, right? Code makes sense to me

@vcanales
Copy link
Member Author

Can't really test this until we merge, right?

Correct, but I've tested and confirmed it works as expected over at Automattic/themes

@vcanales
Copy link
Member Author

Sample PR from a fork tested after the fix was merged: Automattic/themes#7721

@MaggieCabrera
Copy link
Collaborator

I believe you, thanks! Merging

@MaggieCabrera MaggieCabrera merged commit c131d44 into trunk Apr 26, 2024
vcanales added a commit that referenced this pull request Apr 29, 2024
MaggieCabrera pushed a commit that referenced this pull request Apr 29, 2024
@vcanales vcanales deleted the preview-action/use-pull-request-target branch May 6, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
2 participants