fix: correctly detect PR number when run with workflow_run #294
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update the call to the GitHub Rest API, as the previous one wasn't able to retrieve the Pull Request associated to the workflow_run.
From time to time, the API call may get rate limit errors given search API seems to use many calls internally. In this case, the error is caught and a warning is logged. Running the workflow again should then succeed.
Using workflow_run lets do surge deployment when the PR is created from a fork.
This makes this action directly usable instead of developing custom solutions like in
ant-design/ant-design-pro@v6.0.0-beta.1/.github/workflows/preview-deploy.yml which recreate the whole action logic in the workflow definition.
Fixes #124
This fix was developed in collaboration with @benjaminParisel
Notes
This change has been intensively tested through a custom implementation of the surge-preview action provided in benjaminParisel#1 (same content as the PR proposed here).
This custom implementation has been tested in a PR created from a fork repo, see process-analytics/github-actions-playground#349. It has also been tested with PR created from the target repository, see process-analytics/github-actions-playground#350.
The implementation is adapted from https://github.com/orgs/community/discussions/25220#discussioncomment-8697399. The API rate limit was mentioned in https://github.com/orgs/community/discussions/25220#discussioncomment-8971083 and we have encountered once or twice during our tests. That's why we decided to handle the error and add a warning log in this case.
The dist folder has not been updated to include binary changes, and let the maintainers of this repo do the update by themself. If you need me to push the dist folder as well, please let me know.
If this PR is merged, we could later contribute to documentation improvements to describe the workflow_run usage to manage deployment for PR created from a fork repository. For example, explain: