[v1.1.6] Release #15
Workflow file for this run
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: Controller (PR) | |
on: | |
pull_request: | |
types: [opened, reopened] | |
jobs: | |
add-labels: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Assign Zerohertz to PR | |
if: github.event_name == 'pull_request' && github.event.action == 'opened' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{secrets.GH_TOKEN}} | |
script: | | |
github.rest.issues.addAssignees({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
assignees: ['Zerohertz'] | |
}) | |
- name: Add labels based on file path and branch | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{secrets.GH_TOKEN}} | |
script: | | |
const baseBranch = context.payload.pull_request.base.ref; | |
const headBranch = context.payload.pull_request.head.ref; | |
const issueNumber = context.issue.number; | |
const owner = context.repo.owner; | |
const repo = context.repo.repo; | |
const body = context.payload.pull_request.body.toLowerCase(); | |
let labelsToAdd = []; | |
if (body.includes('bug') || body.includes('fix') || body.includes('μμ ')) { | |
labelsToAdd.push('fix'); | |
} | |
if (body.includes('style')) { | |
labelsToAdd.push('style'); | |
} | |
// Check for PR from dev* to master | |
if (baseBranch === 'master' && headBranch.startsWith('dev')) { | |
const files = await github.rest.pulls.listFiles({ | |
owner, | |
repo, | |
pull_number: issueNumber | |
}); | |
files.data.forEach(file => { | |
labelsToAdd.push('release'); | |
if (file.filename.startsWith('Jenkins') || file.filename.startsWith('.github/workflows')) { | |
labelsToAdd.push('chore'); | |
} | |
if (file.filename.startsWith('sphinx') && !file.filename.includes('release')) { | |
labelsToAdd.push('docs'); | |
} | |
if (file.filename.startsWith('zerohertzLib/algorithm/__init__') || body.includes('algorithm')) { | |
labelsToAdd.push('feat/algorithm'); | |
} | |
if (file.filename.startsWith('zerohertzLib/api/__init__') || body.includes('api')) { | |
labelsToAdd.push('feat/api'); | |
} | |
if (file.filename.startsWith('zerohertzLib/logging/__init__') || body.includes('logging')) { | |
labelsToAdd.push('feat/logging'); | |
} | |
if (file.filename.startsWith('zerohertzLib/mlops/__init__') || body.includes('mlops')) { | |
labelsToAdd.push('feat/mlops'); | |
} | |
if (file.filename.startsWith('zerohertzLib/monitoring/__init__') || body.includes('monitoring')) { | |
labelsToAdd.push('feat/monitoring'); | |
} | |
if (file.filename.startsWith('zerohertzLib/plot/__init__') || body.includes('plot')) { | |
labelsToAdd.push('feat/plot'); | |
} | |
if (file.filename.startsWith('zerohertzLib/quant/__init__') || body.includes('quant')) { | |
labelsToAdd.push('feat/quant'); | |
} | |
if (file.filename.startsWith('zerohertzLib/util/__init__') || body.includes('util')) { | |
labelsToAdd.push('feat/util'); | |
} | |
if (file.filename.startsWith('zerohertzLib/vision/__init__') || body.includes('vision')) { | |
labelsToAdd.push('feat/vision'); | |
} | |
}); | |
} | |
// Check for PR from chore-* to master | |
if (baseBranch === 'master' && headBranch.startsWith('chore')) { | |
const files = await github.rest.pulls.listFiles({ | |
owner, | |
repo, | |
pull_number: issueNumber | |
}); | |
files.data.forEach(file => { | |
labelsToAdd.push('release/chore'); | |
if (file.filename.startsWith('Jenkins') || file.filename.startsWith('.github/workflows')) { | |
labelsToAdd.push('chore'); | |
} | |
if (file.filename.startsWith('sphinx') && !file.filename.includes('release')) { | |
labelsToAdd.push('docs'); | |
} | |
}); | |
} | |
// Check for PR from docs to dev* or chore* | |
if ((baseBranch.startsWith('dev') || baseBranch.startsWith('chore')) && headBranch === 'docs') { | |
labelsToAdd.push('docs'); | |
} | |
// Remove duplicates | |
labelsToAdd = [...new Set(labelsToAdd)]; | |
if (labelsToAdd.length > 0) { | |
await github.rest.issues.addLabels({ | |
issue_number: issueNumber, | |
owner, | |
repo, | |
labels: labelsToAdd | |
}); | |
} |