-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an action that can be used to fetch a PR number
- Loading branch information
Showing
6 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,25 +23,32 @@ jobs: | |
else | ||
echo "BREAKING_CHANGES=true" >> "$GITHUB_ENV" | ||
fi | ||
- name: Fetch PR number | ||
id: pr | ||
uses: 8BitJonny/gh-get-current-pr@08e737c57a3a4eb24cec6487664b243b77eb5e36 | ||
- if: ${{ endsWith(github.repository, '/python-package-ci-cd') }} # Run the local action when this is run in the python-package-ci-cd repository | ||
id: fetch-pr-number-local | ||
uses: ./actions/fetch_pr_number | ||
with: | ||
sha: ${{ github.event.workflow_run.head_sha }} | ||
github-repository: ${{ github.repository }} | ||
- if: ${{ !endsWith(github.repository, '/python-package-ci-cd') }} # Run the public action when this is run outside the python-package-ci-cd repository | ||
id: fetch-pr-number | ||
uses: tektronix/python-package-ci-cd/actions/[email protected] | ||
with: | ||
sha: ${{ github.event.workflow_run.head_sha }} | ||
github-repository: ${{ github.repository }} | ||
- name: Publish API Breaking Changes Check Results | ||
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 | ||
if: ${{ env.BREAKING_CHANGES == 'true' }} | ||
with: | ||
header: breaking-api-changes | ||
number: ${{ steps.pr.outputs.number }} | ||
number: ${{ steps.fetch-pr-number.outputs.number || steps.fetch-pr-number-local.outputs.number }} | ||
recreate: true | ||
path: artifacts/breaking_changes.md | ||
- name: Add workflow link to comment | ||
if: ${{ env.BREAKING_CHANGES == 'true' }} | ||
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 | ||
with: | ||
header: breaking-api-changes | ||
number: ${{ steps.pr.outputs.number }} | ||
number: ${{ steps.fetch-pr-number.outputs.number || steps.fetch-pr-number-local.outputs.number }} | ||
append: true | ||
message: |- | ||
<p><a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}">Link to workflow run</a></p> | ||
|
@@ -50,5 +57,5 @@ jobs: | |
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 | ||
with: | ||
header: breaking-api-changes | ||
number: ${{ steps.pr.outputs.number }} | ||
number: ${{ steps.fetch-pr-number.outputs.number || steps.fetch-pr-number-local.outputs.number }} | ||
delete: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,23 +27,30 @@ jobs: | |
run_id: ${{ github.event.workflow_run.id }} | ||
name: artifact_${{ matrix.os-name }}_tests | ||
path: artifacts | ||
- name: Fetch PR number | ||
id: pr | ||
uses: 8BitJonny/gh-get-current-pr@08e737c57a3a4eb24cec6487664b243b77eb5e36 | ||
- if: ${{ endsWith(github.repository, '/python-package-ci-cd') }} # Run the local action when this is run in the python-package-ci-cd repository | ||
id: fetch-pr-number-local | ||
uses: ./actions/fetch_pr_number | ||
with: | ||
sha: ${{ github.event.workflow_run.head_sha }} | ||
github-repository: ${{ github.repository }} | ||
- if: ${{ !endsWith(github.repository, '/python-package-ci-cd') }} # Run the public action when this is run outside the python-package-ci-cd repository | ||
id: fetch-pr-number | ||
uses: tektronix/python-package-ci-cd/actions/[email protected] | ||
with: | ||
sha: ${{ github.event.workflow_run.head_sha }} | ||
github-repository: ${{ github.repository }} | ||
- name: Publish Test Results | ||
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 | ||
with: | ||
header: test-results-${{ matrix.os-name }} | ||
number: ${{ steps.pr.outputs.number }} | ||
number: ${{ steps.fetch-pr-number.outputs.number || steps.fetch-pr-number-local.outputs.number }} | ||
recreate: true | ||
path: artifacts/.results_tests/github_report.md | ||
- name: Add workflow link to comment | ||
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 | ||
with: | ||
header: test-results-${{ matrix.os-name }} | ||
number: ${{ steps.pr.outputs.number }} | ||
number: ${{ steps.fetch-pr-number.outputs.number || steps.fetch-pr-number-local.outputs.number }} | ||
append: true | ||
message: |- | ||
<p><a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}">Link to workflow run</a></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
name: Find the PR number for a given SHA | ||
description: Find the PR number for the provided SHA. This action also works for PRs | ||
that are from forks. | ||
inputs: | ||
sha: | ||
description: The SHA of the commit to find the PR number for. | ||
required: true | ||
github-repository: | ||
description: The GitHub repository to search for the PR in. | ||
required: true | ||
outputs: | ||
number: | ||
description: The PR number. | ||
value: ${{ steps.fetch-pr.outputs.result }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Fetch PR number | ||
id: fetch-pr | ||
uses: actions/github-script@e69ef5462fd455e02edcaf4dd7708eda96b9eda0 # v7.0.0 | ||
with: | ||
script: |- | ||
const maxAttempts = 5; | ||
let attempt = 0; | ||
let pullRequestNumber; | ||
while (attempt < maxAttempts) { | ||
try { | ||
const response = await github.rest.search.issuesAndPullRequests({ | ||
q: 'repo:${{ inputs.github-repository }} is:pr sha:${{ inputs.sha }}', | ||
per_page: 1, | ||
}); | ||
const items = response.data.items; | ||
if (items.length < 1) { | ||
throw new Error('No PRs found'); | ||
} | ||
pullRequestNumber = items[0].number; | ||
console.info("Pull request number is", pullRequestNumber); | ||
break; // Exit loop on success | ||
} catch (error) { | ||
console.error(`Attempt ${attempt + 1} failed:`, error.message); | ||
if (attempt < maxAttempts - 1) { // Check if not last attempt | ||
console.log(`Waiting for 2 minutes before retrying...`); | ||
await new Promise(resolve => setTimeout(resolve, 120000)); // Wait for 2 minutes | ||
} | ||
} | ||
attempt++; | ||
} | ||
if (!pullRequestNumber) { | ||
core.setFailed(`Failed to fetch PR number after ${maxAttempts} attempts`); | ||
} | ||
return pullRequestNumber; |
Empty file.