build(deps): bump the non-breaking group across 1 directory with 10 updates #8008
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: Add/Remove Labels | |
on: | |
pull_request_target: | |
types: [ opened, closed ] | |
jobs: | |
merge_job: | |
if: github.event.pull_request.merged == true | |
permissions: | |
contents: read | |
pull-requests: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
let removeLabelsList = [ | |
"Pending Merge", | |
"Needs Author Reply", | |
"Needs Review", | |
"Review High Priority", | |
"Needs Second Approval", | |
"Blocked by dependency", | |
"Needs a new dev", | |
"squash-merge", | |
"Keep Open", | |
"Stable" | |
]; | |
async function removeLabel(label) { | |
await github.rest.issues.removeLabel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
name: label | |
}); | |
} | |
async function addPostMergeComments() { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: `Maintainers: Please [Sync Translations](https://github.com/ankidroid/Anki-Android/actions/workflows/sync_translations.yml) to produce a commit with only the automated changes from this PR. | |
Read more about updating strings on the wiki, | |
- [localization-administration](https://github.com/ankidroid/Anki-Android/wiki/Development-Guide#localization-administration) | |
- [download-localized-strings](https://github.com/ankidroid/Anki-Android/wiki/Development-Guide#download-localized-strings)` | |
}) | |
} | |
let result = await github.rest.issues.listLabelsOnIssue({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
}); | |
if (result.data !== null && result.data.length > 0) { | |
let labels = result.data; | |
for (let label of labels) { | |
if (removeLabelsList.includes(label.name)) { | |
console.log("Removed: ", label.name); | |
removeLabel(label.name); | |
} | |
// add post merge comments for 'strings' labeled PR | |
if (label.name == "Strings") { | |
addPostMergeComments(); | |
} | |
} | |
} | |
add_label: | |
if: (!(github.event.action == 'closed' && github.event.pull_request.merged != true)) && github.event.pull_request.merged != true && github.event.pull_request.head.ref != 'i18n_sync' | |
permissions: | |
contents: read | |
pull-requests: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const I18N_FILES = [ | |
"01-core", | |
"02-strings", | |
"03-dialogs", | |
"04-network", | |
"05-feedback", | |
"06-statistics", | |
"07-cardbrowser", | |
"08-widget", | |
"09-backup", | |
"10-preferences", | |
"11-arrays", | |
"16-multimedia-editor", | |
"17-model-manager", | |
"18-standard-models", | |
"20-search-preference", | |
"marketdescription", | |
]; | |
let stringsLabel = "Strings"; | |
async function addLabel(labels) { | |
await github.rest.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
labels: labels | |
}); | |
} | |
async function removeLabel(labels) { | |
await github.rest.issues.removeLabel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
name: labels, | |
}); | |
} | |
async function addComments() { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: `> [!IMPORTANT] | |
> **Maintainers**: This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes | |
1. [Sync Translations](https://github.com/ankidroid/Anki-Android/actions/workflows/sync_translations.yml) before merging this PR and wait for the action to complete | |
2. Review and merge the [auto-generated PR](https://github.com/ankidroid/Anki-Android/pulls/mikehardy-machineaccount) in order to sync all user-submitted translations | |
3. [Sync Translations again](https://github.com/ankidroid/Anki-Android/actions/workflows/sync_translations.yml) and merge the [PR](https://github.com/ankidroid/Anki-Android/pulls/mikehardy-machineaccount) so the huge automated string changes caused by merging this PR are by themselves and easy to review` | |
}) | |
} | |
const changedFiles = await github.rest.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
}); | |
// loop through list of files in current pr, then check if filename contains in i18n file name, | |
// set boolean to true and use the boolean in outer loop to add label | |
let fileChanged = false; | |
for (let files of changedFiles.data) { | |
for (let i18n of I18N_FILES) { | |
if (files.filename.includes(i18n)) { | |
fileChanged = true; | |
break; | |
} | |
} | |
if (fileChanged) { | |
addLabel([stringsLabel]); | |
addComments(); | |
break; | |
} | |
} | |
async function getPullRequest() { | |
return await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
}); | |
} | |
// if no file changed, remove label | |
const pullRequestData = await getPullRequest(); | |
if (!fileChanged) { | |
if (pullRequestData.data.labels.find(label => label.name === stringsLabel)) { | |
console.log(`Removing #${stringsLabel} label from PR #${context.issue.number}`); | |
removeLabel([stringsLabel]); | |
} | |
} | |
add_new_contributor_label: | |
if: github.event.action == 'opened' | |
permissions: | |
contents: read | |
pull-requests: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const creator = context.payload.sender.login | |
const opts = github.rest.issues.listForRepo.endpoint.merge({ | |
...context.issue, | |
creator, | |
state: 'all' | |
}) | |
const issues = await github.paginate(opts) | |
for (const issue of issues) { | |
if (issue.number === context.issue.number) { | |
continue | |
} | |
if (issue.pull_request) { | |
return // creator is already a contributor | |
} | |
} | |
await github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: ['New contributor'] | |
}) |