Health Monitor #1692
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
name: Health Monitor | |
on: | |
schedule: | |
- cron: '0 2 * * *' | |
issue_comment: | |
types: [ created ] | |
workflow_dispatch: | |
inputs: | |
repeat-failed-sites-count: | |
required: false | |
type: number | |
default: 1 | |
jobs: | |
main-branch: | |
if: | | |
github.event_name == 'schedule' || | |
github.event_name == 'workflow_dispatch' | |
runs-on: windows-latest | |
env: | |
REPEAT_FAILED_SITES_COUNT: ${{ inputs.repeat-failed-sites-count || 1 }} | |
steps: | |
- name: Use Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 16 | |
- name: Checkout the Health Monitor repository | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ secrets.HEALTH_MONITOR_REPO }} | |
token: ${{ secrets.CLONE_PRIVATE_REPOS_TOKEN }} | |
path: ./HealthMonitor/health-monitor | |
- name: Checkout the testcafe-hammerhead repository | |
uses: actions/checkout@v2 | |
with: | |
path: ./HealthMonitor/testcafe-hammerhead | |
- name: Write the current testcafe-hammerhead abbreviated commit hash to a file | |
run: git log -1 --pretty=format:"%h" > ..\health-monitor\last-commit-id.txt | |
working-directory: ./HealthMonitor/testcafe-hammerhead | |
- name: Install testcafe-hammerhead dependencies and run a build task | |
run: | | |
npm i | |
npx gulp build | |
working-directory: ./HealthMonitor/testcafe-hammerhead | |
- name: Install Health Monitor dependencies | |
run: | | |
npm i | |
npm i testcafe-hammerhead ../testcafe-hammerhead --save | |
working-directory: ./HealthMonitor/health-monitor | |
- name: Run Health Monitor | |
run: npx gulp health-monitor | |
working-directory: ./HealthMonitor/health-monitor | |
pr-branch: | |
if: | | |
github.event.issue.pull_request && | |
( | |
github.event.comment.author_association == 'OWNER' || | |
github.event.comment.author_association == 'COLLABORATOR' || | |
github.event.comment.author_association == 'MEMBER' | |
) && | |
github.event.comment.body == 'run monitor' | |
runs-on: windows-latest | |
steps: | |
- name: Create a PR comment with a job URL | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const request = { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.runId | |
} | |
const runJobs = await github.rest.actions.listJobsForWorkflowRun(request) | |
.then(res => res.data.jobs) | |
.catch(err => { | |
core.setFailed(`Request failed with error ${err}`); | |
}); | |
const currentJob = runJobs.find(job => job.name === context.job); | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Monitor started on this PR.\nDetails: ${currentJob.html_url}?check_suite_focus=true` | |
}); | |
- name: Use Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 16 | |
- name: Checkout the Health Monitor repository | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ secrets.HEALTH_MONITOR_REPO }} | |
token: ${{ secrets.CLONE_PRIVATE_REPOS_TOKEN }} | |
path: ./HealthMonitor/health-monitor | |
- name: Get PR info to checkout testcafe-hammerhead branch | |
uses: actions/github-script@v6 | |
id: get-pr-to-checkout | |
with: | |
script: | | |
const request = { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}; | |
try { | |
const result = await github.rest.pulls.get(request); | |
return result.data; | |
} | |
catch (err) { | |
core.setFailed(`Request failed with the following error:\n${err}`); | |
} | |
- name: Checkout the testcafe-hammerhead PR branch | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ fromJSON(steps.get-pr-to-checkout.outputs.result).head.repo.full_name }} | |
ref: ${{ fromJSON(steps.get-pr-to-checkout.outputs.result).head.ref }} | |
path: ./HealthMonitor/testcafe-hammerhead | |
- name: Write the current testcafe-hammerhead abbreviated commit hash to a file | |
run: git log -1 --pretty=format:"%h" > ..\health-monitor\last-commit-id.txt | |
working-directory: ./HealthMonitor/testcafe-hammerhead | |
- name: Install testcafe-hammerhead dependencies and run a build task | |
run: | | |
npm i | |
npx gulp build | |
working-directory: ./HealthMonitor/testcafe-hammerhead | |
- name: Install Health Monitor dependencies | |
run: | | |
npm i | |
npm i testcafe-hammerhead ../testcafe-hammerhead --save | |
working-directory: ./HealthMonitor/health-monitor | |
- name: Run Health Monitor | |
run: npx gulp health-monitor | |
working-directory: ./HealthMonitor/health-monitor |