Skip to content

Commit 792d589

Browse files
author
Ashwin Kumar
committed
chore(actions): run test suite against PRs and on label
1 parent 3c4d29e commit 792d589

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

.github/actions/set-status/action.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: 'Set Status'
2+
description: 'Set status on a specified head-sha'
3+
inputs:
4+
context:
5+
description: 'Name of the status'
6+
required: true
7+
description:
8+
description: 'Short description of the status'
9+
required: false
10+
state:
11+
description: >-
12+
State of the status with possible values of 'error', 'failure', 'pending', 'success'
13+
required: true
14+
sha:
15+
description: 'The commit ID to add the status to'
16+
required: true
17+
target-url:
18+
description: >-
19+
Target URL to associate with this status.
20+
This URL will be linked from the GitHub UI to allow users to easily see the source of the status.'
21+
required: false
22+
runs:
23+
using: 'composite'
24+
steps:
25+
- name: Set a commit status
26+
id: set-status
27+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 https://github.com/actions/github-script/commit/60a0d83039c74a4aee543508d2ffcb1c3799cdea
28+
env:
29+
status_context: ${{ inputs.context }}
30+
description: ${{ inputs.description }}
31+
state: ${{ inputs.state }}
32+
sha: ${{ inputs.sha }}
33+
target_url: ${{ inputs.target-url }}
34+
owner: ${{ github.event.repository.owner.login }}
35+
repo: ${{ github.event.repository.name }}
36+
with:
37+
result-encoding: string
38+
script: |
39+
const { status_context, description, state, sha, target_url, owner, repo } = process.env;
40+
const inputValidationErrors = [];
41+
if (state.length === 0) {
42+
inputValidationErrors.push('"state" input cannot be empty.');
43+
}
44+
if (!["error", "failure", "pending", "success"].includes(state)) {
45+
inputValidationErrors.push('"state" must be a string input with possible value of "error", "failure", "pending", "success".');
46+
}
47+
if (context.length === 0) {
48+
inputValidationErrors.push('"context" input cannot be empty.');
49+
}
50+
if (sha.length === 0) {
51+
inputValidationErrors.push('"sha" input cannot be empty.');
52+
}
53+
if (!sha.match(/^[0-9a-z]+$/)) {
54+
inputValidationErrors.push('"sha" must be an alphanumeric string.');
55+
}
56+
if (inputValidationErrors.length > 0) {
57+
inputValidationErrors.forEach(core.error);
58+
process.exit(1);
59+
}
60+
github.rest.repos.createCommitStatus({
61+
owner,
62+
repo,
63+
sha,
64+
state,
65+
context: status_context,
66+
description: description.length > 0 ? description : undefined,
67+
target_url: target_url.length > 0 ? target_url : undefined,
68+
});

.github/workflows/pr-label.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Description: This workflow runs test suite against PRs that are not from forks.
2+
#
3+
# Triggers:
4+
# - When a PR is opened, updated, or labeled against specific branches
5+
# - Only runs when the PR has the 'run-tests' label
6+
# - Only runs for internal PRs (not from forks)
7+
8+
name: Test / Internal PRs
9+
10+
concurrency:
11+
group: push-e2e-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
on:
15+
pull_request:
16+
branches: [main, release]
17+
types: [opened, synchronize, labeled]
18+
19+
jobs:
20+
setup:
21+
if: |
22+
github.event.pull_request.head.repo.full_name == github.repository &&
23+
contains(github.event.pull_request.labels.*.name, 'run-tests')
24+
runs-on: ubuntu-latest
25+
permissions:
26+
statuses: write # This is required for running set-status actions
27+
steps:
28+
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017
29+
- name: Update status to pending prior to starting tests
30+
uses: ./.github/actions/set-status
31+
with:
32+
sha: ${{ github.event.pull_request.head.sha }}
33+
state: 'pending'
34+
context: 'Run PR e2e checks'
35+
description: 'PR e2e checks are now running'
36+
# URL below is a link to the current workflow run to allow users to see the status of the workflow.
37+
target-url: https://github.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }}
38+
39+
prebuild:
40+
needs: setup
41+
strategy:
42+
matrix:
43+
platform: [ubuntu-latest, macos-latest]
44+
uses: ./.github/workflows/callable-prebuild-amplify-js.yml
45+
with:
46+
runs_on: ${{ matrix.platform }}
47+
48+
prebuild-samples-staging:
49+
needs: setup
50+
secrets: inherit
51+
uses: ./.github/workflows/callable-prebuild-samples-staging.yml
52+
53+
e2e:
54+
needs: [setup, prebuild, prebuild-samples-staging]
55+
secrets: inherit
56+
uses: ./.github/workflows/callable-e2e-tests.yml
57+
58+
update-success-status:
59+
if: ${{ success() }}
60+
needs: [setup, prebuild, prebuild-samples-staging, e2e]
61+
runs-on: ubuntu-latest
62+
permissions:
63+
statuses: write # This is required for running set-status actions
64+
steps:
65+
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017
66+
- name: Update status when tests are successful
67+
uses: ./.github/actions/set-status
68+
with:
69+
sha: ${{ github.event.pull_request.head.sha }}
70+
state: 'success'
71+
context: 'Run PR e2e checks'
72+
description: 'PR e2e checks have finished running'
73+
target-url: https://github.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }}
74+
75+
update-failure-status:
76+
if: ${{ failure() }}
77+
needs: [setup, prebuild, prebuild-samples-staging, e2e]
78+
runs-on: ubuntu-latest
79+
permissions:
80+
statuses: write # This is required for running set-status actions
81+
steps:
82+
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017
83+
- name: Update status when tests are not successful
84+
uses: ./.github/actions/set-status
85+
with:
86+
sha: ${{ github.event.pull_request.head.sha }}
87+
state: 'failure'
88+
context: 'Run e2e PR checks'
89+
description: 'PR e2e checks have failed'
90+
target-url: https://github.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }}

0 commit comments

Comments
 (0)