Release Labeling #3
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: 'Release Labeling' | |
on: | |
workflow_call: | |
secrets: | |
CI_MACHINE_TOKEN: | |
description: 'CI machine token' | |
required: true | |
inputs: | |
rename_label: | |
description: 'Rename label' | |
type: string | |
required: true | |
default: 'Next Release' | |
new_label: | |
description: 'New label' | |
type: string | |
required: true | |
new_label_color: | |
description: 'New label color' | |
type: string | |
required: false | |
default: '#fbca04' | |
workflow_dispatch: | |
inputs: | |
rename_label: | |
description: 'Rename label' | |
type: string | |
required: true | |
default: 'Next Release' | |
new_label: | |
description: 'New label' | |
type: string | |
required: true | |
new_label_color: | |
description: 'New label color' | |
type: string | |
required: false | |
default: 'fbca04' | |
jobs: | |
release-labeling: | |
runs-on: ubuntu-20.04 | |
env: | |
REPO: core | |
steps: | |
- run: echo 'GitHub context' | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
- name: Rename label | |
if: success() | |
id: validate-inputs | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
retries: 3 | |
retry-exempt-status-codes: 400,401 | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
async function getLabel(name) { | |
console.log(`Getting label [${name}]`); | |
try { | |
const response = await github.rest.issues.getLabel({ | |
owner: '${{ github.repository_owner }}', | |
repo: '${{ env.REPO }}', | |
name, | |
}); | |
return response.data; | |
} catch(error) { | |
console.log(`Error getting label: ${error}`); | |
return undefined; | |
} | |
} | |
const renameLabel = await getLabel('${{ inputs.rename_label }}'); | |
if (!renameLabel) { | |
console.log(`Label [${{ inputs.rename_label }}] not found, skipping rename`); | |
return; | |
} | |
const newLabel = await getLabel('${{ inputs.new_label }}'); | |
if (newLabel) { | |
console.log(`Label [${newLabel.name}] already exists, skipping rename`); | |
return; | |
} | |
console.log(`Renaming label [${renameLabel.name}] for owner [${{ github.repository_owner }}] repo [${{ env.REPO }}] with new label [${{ inputs.new_label }}]`); | |
await github.rest.issues.updateLabel({ | |
owner: '${{ github.repository_owner }}', | |
repo: '${{ env.REPO }}', | |
name: renameLabel.name, | |
new_name: '${{ inputs.new_label }}', | |
color: '${{ inputs.new_label_color }}' | |
}); | |
- name: Re-Create New Label | |
if: success() | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
retries: 3 | |
retry-exempt-status-codes: 400,401 | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
async function getLabel(name) { | |
console.log(`Getting label [${name}]`); | |
try { | |
const response = await github.rest.issues.getLabel({ | |
owner: '${{ github.repository_owner }}', | |
repo: '${{ env.REPO }}', | |
name, | |
}); | |
return response.data; | |
} catch(error) { | |
console.log(`Error getting label: ${error}`); | |
return undefined; | |
} | |
} | |
const renameLabel = await getLabel('${{ inputs.rename_label }}'); | |
if (renameLabel) { | |
console.log(`Label [${renameLabel.name}] already exists, skipping re-creation`); | |
return; | |
} | |
console.log(`Recreating label [${{ inputs.rename_label }}] for owner [${{ github.repository_owner }}] repo [${{ env.REPO }}]`); | |
await github.rest.issues.createLabel({ | |
owner: '${{ github.repository_owner }}', | |
repo: '${{ env.REPO }}', | |
name: '${{ inputs.rename_label }}' | |
}); |