-
Notifications
You must be signed in to change notification settings - Fork 91
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
Allow maintainer to re-run integration tests for PRs from forks #811
Conversation
@mfisher87, this is an attempt to fix the failing integration tests issue (#810). My work on #808 exacerbates the issue, and after further research, I opened #810 and created this PR in an attempt to fix the problem. Unfortunately, I don't think we'll know for sure until this PR is actually merged to If this works, the general workflow for a PR from a fork would be as follows:
Currently, the only way for int. tests to run is for a maintainer (someone with write permission to this repo) to submit an internal PR (i.e., from a branch within this repo, not from a fork) OR for a maintainer to merge a PR with failing int. tests. In the latter case, we must make an assumption that the int. tests will succeed once merged to With this PR, we should be able to get int. tests to run from forks prior to merging, so that if int. tests fail, we do not merge. The downside to this is that it requires a bit of manual effort from a maintainer to make sure the PR does not pose a security risk (which should not be the case for trusted contributors) since the changes in this PR make it such that the fork PR can read the secrets that such PRs cannot currently read (thus, the reason int. tests from a fork always fail), but only once a maintainer gives the thumbs up and re-runs the failed build (when this happens, the build is run with the maintainer's permission, which allows secrets to be read). |
Amazing. I was trying to do the same in the |
- name: Checkout source | ||
if: ${{ github.event_name != 'pull_request_target' }} | ||
uses: actions/checkout@v4 | ||
- name: Fetch user permission | ||
if: ${{ github.event_name == 'pull_request_target' }} | ||
id: permission | ||
uses: actions-cool/check-user-permission@v2 | ||
with: | ||
require: write | ||
username: ${{ github.triggering_actor }} | ||
- name: Check user permission | ||
if: ${{ github.event_name == 'pull_request_target' && steps.permission.outputs.require-result == 'false' }} | ||
# If the triggering actor does not have write permission (i.e., this is a | ||
# PR from a fork), then we exit, otherwise most of the integration tests will | ||
# fail because they require access to secrets. In this case, a maintainer | ||
# will need to make sure the PR looks safe, and if so, manually re-run the | ||
# failed jobs. | ||
run: | | ||
echo "User ${{ github.triggering_actor }} does not have permission to run integration tests." | ||
echo "A maintainer must perform a security review and re-run this build, if the code is safe." | ||
exit 1 | ||
- name: Checkout source | ||
if: ${{ github.event_name == 'pull_request_target' }} | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name: Checkout source | |
if: ${{ github.event_name != 'pull_request_target' }} | |
uses: actions/checkout@v4 | |
- name: Fetch user permission | |
if: ${{ github.event_name == 'pull_request_target' }} | |
id: permission | |
uses: actions-cool/check-user-permission@v2 | |
with: | |
require: write | |
username: ${{ github.triggering_actor }} | |
- name: Check user permission | |
if: ${{ github.event_name == 'pull_request_target' && steps.permission.outputs.require-result == 'false' }} | |
# If the triggering actor does not have write permission (i.e., this is a | |
# PR from a fork), then we exit, otherwise most of the integration tests will | |
# fail because they require access to secrets. In this case, a maintainer | |
# will need to make sure the PR looks safe, and if so, manually re-run the | |
# failed jobs. | |
run: | | |
echo "User ${{ github.triggering_actor }} does not have permission to run integration tests." | |
echo "A maintainer must perform a security review and re-run this build, if the code is safe." | |
exit 1 | |
- name: Checkout source | |
if: ${{ github.event_name == 'pull_request_target' }} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Fetch user permission | |
if: ${{ github.event_name == 'pull_request_target' }} | |
id: permission | |
uses: actions-cool/check-user-permission@v2 | |
with: | |
require: write | |
username: ${{ github.triggering_actor }} | |
- name: Check user permission | |
if: ${{ github.event_name == 'pull_request_target' && steps.permission.outputs.require-result == 'false' }} | |
# If the triggering actor does not have write permission (i.e., this is a | |
# PR from a fork), then we exit, otherwise most of the integration tests will | |
# fail because they require access to secrets. In this case, a maintainer | |
# will need to make sure the PR looks safe, and if so, manually re-run the | |
# failed jobs. | |
run: | | |
echo "User ${{ github.triggering_actor }} does not have permission to run integration tests." | |
echo "A maintainer must perform a security review and re-run this build, if the code is safe." | |
exit 1 | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} |
I think we can simplify to one checkout -- if the event_name is pull_request_target, we'll fail before we reach that point due to the permissions checks.
EDIT: What a repulsive diff output. I only removed the first checkout, and removed the conditional from the second checkout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we can simplify this, but we don't want to only one checkout because a "push" event will not have a pull request sha. I'll rework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the default for ref
is ""
(IIRC), can we do ${{ github.event.pull_request.head.sha | '' }}
?
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Get full python version | ||
id: full-python-version | ||
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") | ||
run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed and refactored in #733
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. I'll remove from this PR so we don't get a merge conflict.
echo "User ${{ github.triggering_actor }} does not have permission to run integration tests." | ||
echo "A maintainer must perform a security review and re-run this build, if the code is safe." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "User ${{ github.triggering_actor }} does not have permission to run integration tests." | |
echo "A maintainer must perform a security review and re-run this build, if the code is safe." | |
echo "User ${{ github.triggering_actor }} does not have permission to run integration tests." | tee -a $GITHUB_OUTPUT | |
echo "A maintainer must perform a security review and re-run this build, if the code is safe (see https://securitylab.github.com/resources/github-actions-preventing-pwn-requests)." | tee -a $GITHUB_OUTPUT | |
echo "Re-run at ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | tee -a $GITHUB_OUTPUT |
It'd be awesome to expose this at the GUI. Untested URL :)
This is an attempt to fix #810. It may require merging before it can be fully confirmed to fix the problem because it may require the
integration-test.yml
file to be on themain
branch before it will be properly triggered.Pull Request (PR) draft checklist - click to expand
contributing documentation
before getting started.
title such as "Add testing details to the contributor section of the README".
example
closes #1
. SeeGitHub docs - Linking a pull request to an issue.
CHANGELOG.md
with details about your change in a section titled## Unreleased
. If such a section does not exist, please create one. FollowCommon Changelog for your additions.
README.md
with details of changes to theearthaccess interface, if any. Consider new environment variables, function names,
decorators, etc.
Click the "Ready for review" button at the bottom of the "Conversation" tab in GitHub
once these requirements are fulfilled. Don't worry if you see any test failures in
GitHub at this point!
Pull Request (PR) merge checklist - click to expand
Please do your best to complete these requirements! If you need help with any of these
requirements, you can ping the
@nsidc/earthaccess-support
team in a comment and wewill help you out!
Request containing "pre-commit.ci autofix" to automate this.
📚 Documentation preview 📚: https://earthaccess--811.org.readthedocs.build/en/811/