2021-07-24 11:03:17 +00:00
|
|
|
---
|
|
|
|
name: "Metadata: Label pull requests CI status"
|
|
|
|
|
|
|
|
on:
|
2021-07-24 12:25:54 +00:00
|
|
|
workflow_run:
|
|
|
|
workflows:
|
|
|
|
- "Pre-commit consistency check"
|
|
|
|
- "Charts: Lint and test"
|
|
|
|
types:
|
|
|
|
- completed
|
2021-07-24 11:03:17 +00:00
|
|
|
|
|
|
|
jobs:
|
2021-07-24 12:22:58 +00:00
|
|
|
label-precommit:
|
|
|
|
name: Label pre-commit status
|
|
|
|
runs-on: ubuntu-20.04
|
2021-07-24 12:41:27 +00:00
|
|
|
if: "${{ github.event.workflow.name == 'Pre-commit consistency check' }}"
|
2021-07-24 12:22:58 +00:00
|
|
|
steps:
|
|
|
|
- uses: getsentry/action-github-app-token@v1
|
|
|
|
id: get-app-token
|
|
|
|
with:
|
|
|
|
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
|
|
|
|
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
|
2021-07-24 11:37:05 +00:00
|
|
|
|
2021-07-24 12:54:57 +00:00
|
|
|
- name: "Get information about the origin 'CI' run"
|
|
|
|
uses: potiuk/get-workflow-origin@v1_3
|
|
|
|
id: source-run-info
|
|
|
|
with:
|
|
|
|
token: ${{ steps.get-app-token.outputs.token }}
|
|
|
|
sourceRunId: ${{ github.event.workflow_run.id }}
|
|
|
|
|
2021-07-24 14:36:47 +00:00
|
|
|
- name: "Label precommit status"
|
|
|
|
uses: actions/github-script@v4
|
2021-07-24 12:41:27 +00:00
|
|
|
with:
|
2021-07-24 14:36:47 +00:00
|
|
|
github-token: ${{ steps.get-app-token.outputs.token }}
|
|
|
|
script: |
|
|
|
|
var LABEL_ADD
|
|
|
|
var LABEL_REMOVE
|
2021-07-24 14:46:19 +00:00
|
|
|
if ('${{ github.event.workflow_run.conclusion }}' == 'success') {
|
2021-07-24 14:36:47 +00:00
|
|
|
LABEL_ADD = 'precommit:ok'
|
|
|
|
LABEL_REMOVE = 'precommit:failed'
|
|
|
|
} else {
|
|
|
|
LABEL_ADD = 'precommit:failed'
|
|
|
|
LABEL_REMOVE = 'precommit:ok'
|
|
|
|
}
|
2021-07-24 12:49:41 +00:00
|
|
|
|
2021-07-24 15:04:29 +00:00
|
|
|
await github.issues.addLabels({
|
2021-07-24 14:36:47 +00:00
|
|
|
issue_number: ${{ steps.source-run-info.outputs.pullRequestNumber }},
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
labels: [LABEL_ADD]
|
|
|
|
})
|
2021-07-24 15:04:29 +00:00
|
|
|
await github.issues.removeLabel({
|
2021-07-24 14:55:13 +00:00
|
|
|
issue_number: ${{ steps.source-run-info.outputs.pullRequestNumber }},
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
name: LABEL_REMOVE
|
|
|
|
})
|
2021-07-24 15:04:29 +00:00
|
|
|
.catch(err => {
|
|
|
|
// Ignore errors that provide the label is not there
|
|
|
|
if (err.status !== 404 && err.status !== 410) {
|
|
|
|
core.error(`Unexpected error status: ${err.status} with message: ${err.message}`);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
2021-07-24 11:45:11 +00:00
|
|
|
|
2021-07-24 12:41:27 +00:00
|
|
|
label-lint-install:
|
|
|
|
name: Label lint and install status
|
|
|
|
runs-on: ubuntu-20.04
|
2021-07-24 12:54:57 +00:00
|
|
|
if: "${{ github.event.workflow.name == 'Charts: Lint and test' }}"
|
2021-07-24 12:41:27 +00:00
|
|
|
steps:
|
|
|
|
- uses: getsentry/action-github-app-token@v1
|
|
|
|
id: get-app-token
|
|
|
|
with:
|
|
|
|
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
|
|
|
|
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
|
2021-07-24 11:45:11 +00:00
|
|
|
|
2021-07-24 12:54:57 +00:00
|
|
|
- name: "Get information about the origin 'CI' run"
|
|
|
|
uses: potiuk/get-workflow-origin@v1_3
|
|
|
|
id: source-run-info
|
|
|
|
with:
|
|
|
|
token: ${{ steps.get-app-token.outputs.token }}
|
|
|
|
sourceRunId: ${{ github.event.workflow_run.id }}
|
|
|
|
|
2021-07-24 13:25:26 +00:00
|
|
|
- name: "Get workflow job status"
|
2021-07-24 12:41:27 +00:00
|
|
|
uses: actions/github-script@v4
|
2021-07-24 13:03:27 +00:00
|
|
|
id: get-workflow-jobs
|
2021-07-24 12:41:27 +00:00
|
|
|
with:
|
|
|
|
github-token: ${{ steps.get-app-token.outputs.token }}
|
|
|
|
script: |
|
2021-07-24 14:10:45 +00:00
|
|
|
let result = new Object
|
2021-07-24 13:37:54 +00:00
|
|
|
|
2021-07-24 12:58:31 +00:00
|
|
|
const wfJobs = await github.actions.listJobsForWorkflowRun({
|
2021-07-24 12:41:27 +00:00
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
2021-07-24 12:49:41 +00:00
|
|
|
run_id: context.payload.workflow_run.id,
|
2021-07-24 13:25:26 +00:00
|
|
|
})
|
|
|
|
|
2021-07-24 13:37:54 +00:00
|
|
|
for (const job of wfJobs.data.jobs) {
|
|
|
|
if (job.name === 'Lint charts') {
|
2021-07-24 14:10:45 +00:00
|
|
|
result['lint'] = job.conclusion
|
2021-07-24 13:37:54 +00:00
|
|
|
} else if (job.name === 'Install successful') {
|
2021-07-24 14:10:45 +00:00
|
|
|
result['install'] = job.conclusion
|
2021-07-24 13:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 14:04:43 +00:00
|
|
|
console.log(result)
|
2021-07-24 13:41:56 +00:00
|
|
|
return result
|
2021-07-24 13:03:27 +00:00
|
|
|
|
2021-07-24 14:36:47 +00:00
|
|
|
- name: "Label lint status"
|
2021-07-24 14:20:50 +00:00
|
|
|
uses: actions/github-script@v4
|
|
|
|
with:
|
|
|
|
github-token: ${{ steps.get-app-token.outputs.token }}
|
|
|
|
script: |
|
2021-07-24 14:36:47 +00:00
|
|
|
var LABEL_ADD
|
|
|
|
var LABEL_REMOVE
|
2021-07-24 14:46:19 +00:00
|
|
|
if ('${{ fromJSON(steps.get-workflow-jobs.outputs.result).lint}}' == 'success') {
|
2021-07-24 14:36:47 +00:00
|
|
|
LABEL_ADD = 'lint:ok'
|
|
|
|
LABEL_REMOVE = 'lint:failed'
|
|
|
|
} else {
|
|
|
|
LABEL_ADD = 'lint:failed'
|
|
|
|
LABEL_REMOVE = 'lint:ok'
|
|
|
|
}
|
|
|
|
|
2021-07-24 15:04:29 +00:00
|
|
|
await github.issues.addLabels({
|
2021-07-24 14:26:04 +00:00
|
|
|
issue_number: ${{ steps.source-run-info.outputs.pullRequestNumber }},
|
2021-07-24 14:20:50 +00:00
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
2021-07-24 14:36:47 +00:00
|
|
|
labels: [LABEL_ADD]
|
2021-07-24 14:20:50 +00:00
|
|
|
})
|
2021-07-24 14:36:47 +00:00
|
|
|
try {
|
2021-07-24 15:04:29 +00:00
|
|
|
await github.issues.removeLabel({
|
2021-07-24 14:36:47 +00:00
|
|
|
issue_number: ${{ steps.source-run-info.outputs.pullRequestNumber }},
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
2021-07-24 14:55:13 +00:00
|
|
|
name: LABEL_REMOVE
|
2021-07-24 14:36:47 +00:00
|
|
|
})
|
2021-07-24 14:49:11 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
2021-07-24 14:36:47 +00:00
|
|
|
|
|
|
|
- name: "Label install status"
|
|
|
|
uses: actions/github-script@v4
|
|
|
|
with:
|
|
|
|
github-token: ${{ steps.get-app-token.outputs.token }}
|
|
|
|
script: |
|
|
|
|
var LABEL_ADD
|
|
|
|
var LABEL_REMOVE
|
2021-07-24 14:46:19 +00:00
|
|
|
if ('${{ fromJSON(steps.get-workflow-jobs.outputs.result).install}}' == 'success') {
|
2021-07-24 14:36:47 +00:00
|
|
|
LABEL_ADD = 'install:ok'
|
|
|
|
LABEL_REMOVE = 'install:failed'
|
|
|
|
} else {
|
|
|
|
LABEL_ADD = 'install:failed'
|
|
|
|
LABEL_REMOVE = 'install:ok'
|
|
|
|
}
|
|
|
|
|
2021-07-24 15:04:29 +00:00
|
|
|
await github.issues.addLabels({
|
2021-07-24 14:26:04 +00:00
|
|
|
issue_number: ${{ steps.source-run-info.outputs.pullRequestNumber }},
|
2021-07-24 14:20:50 +00:00
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
2021-07-24 14:36:47 +00:00
|
|
|
labels: [LABEL_ADD]
|
2021-07-24 14:20:50 +00:00
|
|
|
})
|
2021-07-24 14:36:47 +00:00
|
|
|
try {
|
2021-07-24 15:04:29 +00:00
|
|
|
await github.issues.removeLabel({
|
2021-07-24 14:36:47 +00:00
|
|
|
issue_number: ${{ steps.source-run-info.outputs.pullRequestNumber }},
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
2021-07-24 14:55:13 +00:00
|
|
|
name: LABEL_REMOVE
|
2021-07-24 14:36:47 +00:00
|
|
|
})
|
2021-07-24 14:49:11 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.log(e)
|
|
|
|
}
|