-
Notifications
You must be signed in to change notification settings - Fork 2.2k
chore(actions): run test suite against PRs and on label #14372
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: 'Set Status' | ||
description: 'Set status on a specified head-sha' | ||
inputs: | ||
context: | ||
description: 'Name of the status' | ||
required: true | ||
description: | ||
description: 'Short description of the status' | ||
required: false | ||
state: | ||
description: >- | ||
State of the status with possible values of 'error', 'failure', 'pending', 'success' | ||
required: true | ||
sha: | ||
description: 'The commit ID to add the status to' | ||
required: true | ||
target-url: | ||
description: >- | ||
Target URL to associate with this status. | ||
This URL will be linked from the GitHub UI to allow users to easily see the source of the status.' | ||
required: false | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Set a commit status | ||
id: set-status | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 https://github.com/actions/github-script/commit/60a0d83039c74a4aee543508d2ffcb1c3799cdea | ||
env: | ||
status_context: ${{ inputs.context }} | ||
description: ${{ inputs.description }} | ||
state: ${{ inputs.state }} | ||
sha: ${{ inputs.sha }} | ||
target_url: ${{ inputs.target-url }} | ||
owner: ${{ github.event.repository.owner.login }} | ||
repo: ${{ github.event.repository.name }} | ||
with: | ||
result-encoding: string | ||
script: | | ||
const { status_context, description, state, sha, target_url, owner, repo } = process.env; | ||
const inputValidationErrors = []; | ||
if (state.length === 0) { | ||
inputValidationErrors.push('"state" input cannot be empty.'); | ||
} | ||
if (!["error", "failure", "pending", "success"].includes(state)) { | ||
inputValidationErrors.push('"state" must be a string input with possible value of "error", "failure", "pending", "success".'); | ||
} | ||
if (context.length === 0) { | ||
inputValidationErrors.push('"context" input cannot be empty.'); | ||
} | ||
if (sha.length === 0) { | ||
inputValidationErrors.push('"sha" input cannot be empty.'); | ||
} | ||
if (!sha.match(/^[0-9a-z]+$/)) { | ||
inputValidationErrors.push('"sha" must be an alphanumeric string.'); | ||
} | ||
if (target_url && target_url.length > 0) { | ||
if (target_url.length > 2048) { | ||
inputValidationErrors.push('"target-url" must be less than 2048 characters.'); | ||
} | ||
|
||
try { | ||
const url = new URL(target_url); | ||
|
||
if (url.protocol !== 'https:') { | ||
inputValidationErrors.push('"target-url" must use HTTPS protocol.'); | ||
} | ||
|
||
const allowedHostnames = ['github.com', 'api.github.com']; | ||
if (!allowedHostnames.includes(url.hostname)) { | ||
inputValidationErrors.push(`"target-url" must be one of: ${allowedHostnames.join(', ')}.`); | ||
} | ||
|
||
} catch (error) { | ||
if (error instanceof TypeError && error.message.includes('Invalid URL')) { | ||
inputValidationErrors.push('"target-url" must be a valid URL format.'); | ||
} else { | ||
inputValidationErrors.push(`"target-url" validation failed: ${error.message}`); | ||
} | ||
} | ||
} | ||
if (inputValidationErrors.length > 0) { | ||
inputValidationErrors.forEach(core.error); | ||
process.exit(1); | ||
} | ||
github.rest.repos.createCommitStatus({ | ||
owner, | ||
repo, | ||
sha, | ||
state, | ||
context: status_context, | ||
description: description.length > 0 ? description : undefined, | ||
target_url: target_url.length > 0 ? target_url : undefined, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Description: This workflow runs test suite against PRs that are not from forks. | ||
# | ||
# Triggers: | ||
# - When a PR is opened, updated, or labeled against specific branches | ||
# - Only runs when the PR has the 'run-tests' label | ||
# - Only runs for internal PRs (not from forks) | ||
|
||
name: Test / Internal PRs | ||
|
||
concurrency: | ||
group: push-e2e-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
ashwinkumar6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
branches: [main, release] | ||
types: [opened, synchronize, labeled] | ||
|
||
jobs: | ||
setup: | ||
if: | | ||
github.event.pull_request.head.repo.full_name == github.repository && | ||
contains(github.event.pull_request.labels.*.name, 'run-tests') | ||
runs-on: ubuntu-latest | ||
permissions: | ||
statuses: write # This is required for running set-status actions | ||
steps: | ||
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017 | ||
- name: Update status to pending prior to starting tests | ||
uses: ./.github/actions/set-status | ||
with: | ||
sha: ${{ github.event.pull_request.head.sha }} | ||
state: 'pending' | ||
context: 'Run PR e2e checks' | ||
description: 'PR e2e checks are now running' | ||
# URL below is a link to the current workflow run to allow users to see the status of the workflow. | ||
target-url: https://github.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any validation on target-url? If not, please restrict this to only expected input (min/max length, malicious characters, etc). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the review. I added checks for that • Length limits (2048 chars) |
||
|
||
prebuild: | ||
needs: setup | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest] | ||
uses: ./.github/workflows/callable-prebuild-amplify-js.yml | ||
with: | ||
runs_on: ${{ matrix.platform }} | ||
|
||
prebuild-samples-staging: | ||
needs: setup | ||
secrets: inherit | ||
uses: ./.github/workflows/callable-prebuild-samples-staging.yml | ||
|
||
e2e: | ||
ashwinkumar6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
needs: [setup, prebuild, prebuild-samples-staging] | ||
secrets: inherit | ||
uses: ./.github/workflows/callable-e2e-tests.yml | ||
|
||
update-success-status: | ||
if: ${{ success() }} | ||
needs: [e2e] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
statuses: write # This is required for running set-status actions | ||
steps: | ||
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017 | ||
- name: Update status when tests are successful | ||
uses: ./.github/actions/set-status | ||
with: | ||
sha: ${{ github.event.pull_request.head.sha }} | ||
state: 'success' | ||
context: 'Run PR e2e checks' | ||
description: 'PR e2e checks have finished running' | ||
target-url: https://github.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }} | ||
|
||
update-failure-status: | ||
if: ${{ failure() }} | ||
needs: [e2e] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
statuses: write # This is required for running set-status actions | ||
steps: | ||
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017 | ||
- name: Update status when tests are not successful | ||
uses: ./.github/actions/set-status | ||
with: | ||
sha: ${{ github.event.pull_request.head.sha }} | ||
state: 'failure' | ||
context: 'Run e2e PR checks' | ||
description: 'PR e2e checks have failed' | ||
target-url: https://github.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }} |
Uh oh!
There was an error while loading. Please reload this page.