Skip to content

Commit

Permalink
test: Add test for PR from a fork
Browse files Browse the repository at this point in the history
  • Loading branch information
nfelt14 committed Aug 30, 2024
1 parent 27e0dfa commit c88ca57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,28 @@ jobs:
echo "Actual: ${{ steps.fetch-pr-number-found.outputs.number }}"
exit 1
fi
- name: Fetch known PR number from a fork
uses: ./actions/fetch_pr_number
id: fetch-pr-number-found-fork
with:
sha: 9163270797352721c78d82054f6ead259f2f7366
github-repository: ${{ github.repository }}
- name: Verify the PR number from a fork
run: |
if [ "${{ steps.fetch-pr-number-found-fork.outputs.number }}" != "31" ]; then
echo "The fetched PR number doesn't match the expected PR number."
echo "Expected: 31"
echo "Actual: ${{ steps.fetch-pr-number-found.outputs.number }}"
exit 1
fi
- name: Fetch unknown PR number
uses: ./actions/fetch_pr_number
id: fetch-pr-number-not-found
with:
sha: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
github-repository: ${{ github.repository }}
max-attempts: 2
retry-delay: 2
continue-on-error: true # This step should fail
- name: Verify no PR number was found and the previous step failed
run: |
Expand Down
14 changes: 11 additions & 3 deletions actions/fetch_pr_number/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ inputs:
github-repository:
description: The GitHub repository to search for the PR in.
required: true
retry-delay:
description: The delay in seconds between retries.
default: '120'
required: false
max-attempts:
description: The maximum number of attempts to find the PR number.
default: '5'
required: false
outputs:
number:
description: The PR number.
Expand All @@ -21,7 +29,7 @@ runs:
uses: actions/github-script@e69ef5462fd455e02edcaf4dd7708eda96b9eda0 # v7.0.0
with:
script: |-
const maxAttempts = 5;
const maxAttempts = $((${{ inputs.max-attempts }}));
let attempt = 0;
let pullRequestNumber;
while (attempt < maxAttempts) {
Expand All @@ -40,8 +48,8 @@ runs:
} 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
console.log(`Waiting for ${{ inputs.retry-delay }} seconds before retrying...`);
await new Promise(resolve => setTimeout(resolve, $((${{ inputs.retry-delay }})) * 1000)); // Wait for 2 minutes
}
}
attempt++;
Expand Down

0 comments on commit c88ca57

Please sign in to comment.