ci: Update CI status labeler

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>
This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2022-02-03 20:16:34 +01:00
parent 19b3af8f2f
commit 5e5f23c69d
No known key found for this signature in database
GPG Key ID: BC5E2BD907F9A8EC
6 changed files with 261 additions and 234 deletions

View File

@ -0,0 +1,48 @@
name: "Set issue labels based on status"
description: "Sets / removes issue labels based on CI job status"
inputs:
token:
required: true
description: "The Github API token to use"
issue-number:
required: true
description: "The issue to label"
prefix:
required: true
description: "The label prefix (e.g. lint, install)"
job-status:
required: true
description: "The status of the CI job"
remove-on-skipped:
required: false
default: false
description: "Remove the label if the job was skipped"
runs:
using: "composite"
steps:
- name: Label success
uses: andymckay/labeler@1.0.4
if: ${{ inputs.job-status == 'success' }}
with:
repo-token: ${{ inputs.token }}
issue-number: ${{ inputs.issue-number }}
add-labels: "${{ inputs.prefix }}:ok"
remove-labels: "${{ inputs.prefix }}:failed"
- name: Label failure
uses: andymckay/labeler@1.0.4
if: ${{ inputs.job-status == 'failure' }}
with:
repo-token: ${{ inputs.token }}
issue-number: ${{ inputs.issue-number }}
add-labels: "${{ inputs.prefix }}:failed"
remove-labels: "${{ inputs.prefix }}:ok"
- name: Remove label
uses: andymckay/labeler@1.0.4
if: ${{ (inputs.job-status == 'skipped') && (inputs.remove-on-skipped == true) }}
with:
repo-token: ${{ inputs.token }}
issue-number: ${{ inputs.issue-number }}
remove-labels: "${{ inputs.prefix }}:ok, ${{ inputs.prefix }}:failed"

View File

@ -15,8 +15,8 @@ on:
value: ${{ jobs.generate-readme.outputs.commitHash }}
jobs:
validate-chart:
name: Validate chart.yaml
validate-changelog:
name: Validate changelog
runs-on: ubuntu-latest
steps:
- name: Checkout
@ -30,7 +30,6 @@ jobs:
CHARTS=(${{ inputs.modifiedCharts }})
for i in "${CHARTS[@]}"
do
printf "Checking release notes for chart %s\n" "${i}"
IFS='/' read -r -a chart_parts <<< "$i"
./.github/scripts/check-releasenotes.sh "charts/${chart_parts[0]}/${chart_parts[1]}"
echo ""
@ -40,7 +39,7 @@ jobs:
name: Generate chart README files
runs-on: ubuntu-latest
needs:
- validate-chart
- validate-changelog
outputs:
commitHash: ${{ steps.store-commit-hash.outputs.commit_hash }}
steps:

View File

@ -0,0 +1,108 @@
---
name: "Metadata: Label pull requests CI status"
on:
workflow_run:
workflows:
- "Pull Request: Validate"
types:
- completed
jobs:
label-ci-status:
name: Label CI status
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Generate Token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
- name: "Get information about the origin 'CI' run"
uses: potiuk/get-workflow-origin@v1_3
id: source-run-info
with:
token: ${{ steps.generate-token.outputs.token }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Get workflow job status"
uses: actions/github-script@v5
id: get-workflow-jobs
with:
github-token: ${{ steps.generate-token.outputs.token }}
# https://mhagemann.medium.com/the-ultimate-way-to-slugify-a-url-string-in-javascript-b8e4a0d849e1
script: |
function slugify(string) {
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìıİłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;'
const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text
}
let result = new Object
const wfJobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
})
for (const job of wfJobs.data.jobs) {
result[slugify(job.name)] = job.conclusion
}
console.log(result)
return result
- name: Label pre-commit status
uses: ./.github/actions/label-from-status
with:
token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
prefix: precommit
job-status: |-
${{ fromJSON(steps.get-workflow-jobs.outputs.result).pre-commit-check-run-pre-commit-checks || 'skipped' }}
remove-on-skipped: true
- name: Label changelog status
uses: ./.github/actions/label-from-status
with:
token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
prefix: changelog
job-status: |-
${{ fromJSON(steps.get-workflow-jobs.outputs.result).charts-readme-validate-changelog || 'skipped' }}
remove-on-skipped: true
# - name: Label lint status
# uses: ./.github/actions/label-from-status
# with:
# token: ${{ steps.generate-token.outputs.token }}
# issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
# prefix: lint
# job-status: |-
# ${{ fromJSON(steps.get-workflow-jobs.outputs.result).lint || 'skipped' }}
# remove-on-skipped: true
# - name: Label install status
# uses: ./.github/actions/label-from-status
# with:
# token: ${{ steps.generate-token.outputs.token }}
# issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
# prefix: lint
# job-status: |-
# ${{ fromJSON(steps.get-workflow-jobs.outputs.result).lint || 'skipped' }}
# remove-on-skipped: true

View File

@ -1,38 +1,38 @@
---
name: "Metadata: Label Commenter"
# ---
# name: "Metadata: Label Commenter"
on:
issues:
types:
- labeled
- unlabeled
pull_request_target:
types:
- labeled
- unlabeled
# on:
# issues:
# types:
# - labeled
# - unlabeled
# pull_request_target:
# types:
# - labeled
# - unlabeled
permissions:
contents: read
issues: write
pull-requests: write
# permissions:
# contents: read
# issues: write
# pull-requests: write
jobs:
comment:
name: Label commenter
runs-on: ubuntu-20.04
steps:
- name: Generate Token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
# jobs:
# comment:
# name: Label commenter
# runs-on: ubuntu-20.04
# steps:
# - name: Generate Token
# uses: tibdex/github-app-token@v1
# id: generate-token
# with:
# app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
# private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
- uses: actions/checkout@v2
with:
token: ${{ steps.generate-token.outputs.token }}
ref: master
# - uses: actions/checkout@v2
# with:
# token: ${{ steps.generate-token.outputs.token }}
# ref: master
- uses: peaceiris/actions-label-commenter@v1
with:
github_token: ${{ steps.generate-token.outputs.token }}
# - uses: peaceiris/actions-label-commenter@v1
# with:
# github_token: ${{ steps.generate-token.outputs.token }}

View File

@ -1,72 +1,72 @@
---
name: "Metadata: Label issues and pull requests"
# ---
# name: "Metadata: Label issues and pull requests"
on:
issues:
types:
- opened
- edited
- closed
- reopened
pull_request_target:
types:
- opened
- edited
- closed
- reopened
- ready_for_review
- synchronize
# on:
# issues:
# types:
# - opened
# - edited
# - closed
# - reopened
# pull_request_target:
# types:
# - opened
# - edited
# - closed
# - reopened
# - ready_for_review
# - synchronize
jobs:
label:
name: Label issues and pull requests
runs-on: ubuntu-20.04
steps:
- name: Generate Token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
# jobs:
# label:
# name: Label issues and pull requests
# runs-on: ubuntu-20.04
# steps:
# - name: Generate Token
# uses: tibdex/github-app-token@v1
# id: generate-token
# with:
# app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
# private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
- uses: Videndum/label-mastermind@2.1.3
with:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
configJSON: |
{
"releaseMastermind": {
"labels": {
"kind:incorrect-title": {
"name": "kind:incorrect-title",
"colour": "#ffb700",
"description": "Incorrect title"
}
},
"runners": [
{
"root": ".",
"versioning": {
"source": "milestones",
"type": "other"
},
"pr": {
"labels": {
"kind:incorrect-title": {
"requires": 2,
"conditions": [
{
"type": "creatorMatches",
"pattern": "^(?!renovate).+"
},
{
"type": "titleMatches",
"pattern": "^(?!\\[[a-z0-9\\-]+\\]\\s.+).+"
}
]
}
}
}
}
]
}
}
# - uses: Videndum/label-mastermind@2.1.3
# with:
# GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
# configJSON: |
# {
# "releaseMastermind": {
# "labels": {
# "kind:incorrect-title": {
# "name": "kind:incorrect-title",
# "colour": "#ffb700",
# "description": "Incorrect title"
# }
# },
# "runners": [
# {
# "root": ".",
# "versioning": {
# "source": "milestones",
# "type": "other"
# },
# "pr": {
# "labels": {
# "kind:incorrect-title": {
# "requires": 2,
# "conditions": [
# {
# "type": "creatorMatches",
# "pattern": "^(?!renovate).+"
# },
# {
# "type": "titleMatches",
# "pattern": "^(?!\\[[a-z0-9\\-]+\\]\\s.+).+"
# }
# ]
# }
# }
# }
# }
# ]
# }
# }

View File

@ -1,128 +0,0 @@
---
name: "Metadata: Label pull requests CI status"
on:
workflow_run:
workflows:
- "Pre-commit consistency check"
- "Charts: Validate"
types:
- completed
jobs:
label-precommit:
name: Label pre-commit status
runs-on: ubuntu-20.04
if: "${{ github.event.workflow.name == 'Pre-commit consistency check' }}"
steps:
- name: Generate Token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
- name: "Get information about the origin 'CI' run"
uses: potiuk/get-workflow-origin@v1_3
id: source-run-info
with:
token: ${{ steps.generate-token.outputs.token }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: Label precommit success
uses: andymckay/labeler@1.0.4
if: ${{ github.event.workflow_run.conclusion == 'success' }}
with:
repo-token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
add-labels: "precommit:ok"
remove-labels: "precommit:failed"
- name: Label precommit failure
uses: andymckay/labeler@1.0.4
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
with:
repo-token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
add-labels: "precommit:failed"
remove-labels: "precommit:ok"
label-lint-install:
name: Label lint and install status
runs-on: ubuntu-20.04
if: "${{ github.event.workflow.name == 'Charts: Validate' }}"
steps:
- name: Generate Token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
- name: "Get information about the origin 'CI' run"
uses: potiuk/get-workflow-origin@v1_3
id: source-run-info
with:
token: ${{ steps.generate-token.outputs.token }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: "Get workflow job status"
uses: actions/github-script@v5
id: get-workflow-jobs
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
let result = new Object
const wfJobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
})
for (const job of wfJobs.data.jobs) {
if (job.name === 'Lint successful') {
result['lint'] = job.conclusion
} else if (job.name === 'Install successful') {
result['install'] = job.conclusion
}
}
console.log(result)
return result
- name: Label lint success
uses: andymckay/labeler@1.0.4
if: ${{ fromJSON(steps.get-workflow-jobs.outputs.result).lint == 'success' }}
with:
repo-token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
add-labels: "lint:ok"
remove-labels: "lint:failed"
- name: Label lint failure
uses: andymckay/labeler@1.0.4
if: ${{ fromJSON(steps.get-workflow-jobs.outputs.result).lint == 'failure' }}
with:
repo-token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
add-labels: "lint:failed"
remove-labels: "lint:ok"
- name: Label install success
uses: andymckay/labeler@1.0.4
if: ${{ fromJSON(steps.get-workflow-jobs.outputs.result).install == 'success' }}
with:
repo-token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
add-labels: "install:ok"
remove-labels: "install:failed"
- name: Label install failure
uses: andymckay/labeler@1.0.4
if: ${{ fromJSON(steps.get-workflow-jobs.outputs.result).install == 'failure' }}
with:
repo-token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
add-labels: "install:failed"
remove-labels: "install:ok"