Issue Labeled workflow (layui/layui)
The Issue Labeled workflow from layui/layui, explained and optimized by Latchkey.
A
CI health: A - excellent
Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Issue Labeled workflow from the layui/layui repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
name: Issue Labeled
on:
issues:
types: [labeled]
permissions:
contents: read
jobs:
issue-labeled:
permissions:
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: content template
id: template
run: |
contribute="详见:🍀 [Layui Issue 贡献指南](https://github.com/layui/layui/blob/main/CONTRIBUTING.md)"
echo "CONTRIBUTING=$contribute" >> $GITHUB_OUTPUT
- name: handle labeled issue
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labelName = context.payload.label?.name;
const issue = context.payload.issue;
const config = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
};
const templates = {
'help wanted': {
close: false,
body: `@${issue.user.login} 你好 👋。
我们赞成为该议题寻求社区帮助,欢迎创建 [Pull Request](https://github.com/layui/layui/pulls) 来协助实现,若变更内容涉及到 API 新增和改动,除了提交核心代码外,还需包含:文档、测试用例等相关文件,以便我们更好地进行 Review。期待您的贡献!
> ${{ steps.template.outputs.CONTRIBUTING }}`,
},
'invalid': {
close: true,
body: `@${issue.user.login} 你好,为了提升沟通效率,我们对 Issue 制定了严格的要求,你的 Issue 因不符合规定而被自动关闭。
建议你在下次创建 Issue 时,遵循相应规范和社区行为准则。谢谢。
> ${{ steps.template.outputs.CONTRIBUTING }}`,
},
'need reproduce': {
close: false,
body: `@${issue.user.login} 你好,请提供一个最小化的重现,以便我们为你协助排查问题。良好的重现应当包括但不仅限于:
- 产生问题的详细步骤
- 与问题相关的完整代码
- 在线 Demo (推荐通过 [stackblitz](https://stackblitz.com/) 或 [codepen](https://codepen.io/) 创建)
> ${{ steps.template.outputs.CONTRIBUTING }}
> 延伸:👉 [为什么要提供最小化重现?](https://antfu.me/posts/why-reproductions-are-required-zh)`,
},
'discussion': {
close: true,
body: `@${issue.user.login} 你好,Issue 只接受「Bug 报告」和「功能请求」,而你的议题涉及到如何使用、功能疑惑或其他业务相关的问题,这并不适合作为 Issue 讨论。建议你通过以下方式寻求解决方案:
- 仔细查阅 Layui 官方文档:https://layui.dev
- 通过其他技术社区搜索相关资料、或充分利用当前主流的人工智能大模型
- [Discussions](https://github.com/layui/layui/discussions)
> ${{ steps.template.outputs.CONTRIBUTING }}`,
},
'unrelated': {
close: true,
body: `@${issue.user.login} 你提出的问题与 Layui 可能不存在相关联。建议通过以下方式寻求解决方案:
- 通过其他技术社区搜索相关资料、或充分利用当前主流的人工智能大模型
- [Discussions](https://github.com/layui/layui/discussions)
> ${{ steps.template.outputs.CONTRIBUTING }}`,
},
};
const action = templates[labelName];
if (!action) {
core.info(`Skip unsupported label: ${labelName}`);
return;
}
await github.rest.issues.createComment({
...config,
body: action.body,
});
if (action.close) {
await github.rest.issues.update({
...config,
state: 'closed',
});
}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Issue Labeled on: issues: types: [labeled] permissions: contents: read jobs: issue-labeled: timeout-minutes: 30 permissions: issues: write pull-requests: write runs-on: latchkey-small steps: - name: content template id: template run: | contribute="详见:🍀 [Layui Issue 贡献指南](https://github.com/layui/layui/blob/main/CONTRIBUTING.md)" echo "CONTRIBUTING=$contribute" >> $GITHUB_OUTPUT - name: handle labeled issue uses: actions/github-script@v9 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const labelName = context.payload.label?.name; const issue = context.payload.issue; const config = { owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }; const templates = { 'help wanted': { close: false, body: `@${issue.user.login} 你好 👋。 我们赞成为该议题寻求社区帮助,欢迎创建 [Pull Request](https://github.com/layui/layui/pulls) 来协助实现,若变更内容涉及到 API 新增和改动,除了提交核心代码外,还需包含:文档、测试用例等相关文件,以便我们更好地进行 Review。期待您的贡献! > ${{ steps.template.outputs.CONTRIBUTING }}`, }, 'invalid': { close: true, body: `@${issue.user.login} 你好,为了提升沟通效率,我们对 Issue 制定了严格的要求,你的 Issue 因不符合规定而被自动关闭。 建议你在下次创建 Issue 时,遵循相应规范和社区行为准则。谢谢。 > ${{ steps.template.outputs.CONTRIBUTING }}`, }, 'need reproduce': { close: false, body: `@${issue.user.login} 你好,请提供一个最小化的重现,以便我们为你协助排查问题。良好的重现应当包括但不仅限于: - 产生问题的详细步骤 - 与问题相关的完整代码 - 在线 Demo (推荐通过 [stackblitz](https://stackblitz.com/) 或 [codepen](https://codepen.io/) 创建) > ${{ steps.template.outputs.CONTRIBUTING }} > 延伸:👉 [为什么要提供最小化重现?](https://antfu.me/posts/why-reproductions-are-required-zh)`, }, 'discussion': { close: true, body: `@${issue.user.login} 你好,Issue 只接受「Bug 报告」和「功能请求」,而你的议题涉及到如何使用、功能疑惑或其他业务相关的问题,这并不适合作为 Issue 讨论。建议你通过以下方式寻求解决方案: - 仔细查阅 Layui 官方文档:https://layui.dev - 通过其他技术社区搜索相关资料、或充分利用当前主流的人工智能大模型 - [Discussions](https://github.com/layui/layui/discussions) > ${{ steps.template.outputs.CONTRIBUTING }}`, }, 'unrelated': { close: true, body: `@${issue.user.login} 你提出的问题与 Layui 可能不存在相关联。建议通过以下方式寻求解决方案: - 通过其他技术社区搜索相关资料、或充分利用当前主流的人工智能大模型 - [Discussions](https://github.com/layui/layui/discussions) > ${{ steps.template.outputs.CONTRIBUTING }}`, }, }; const action = templates[labelName]; if (!action) { core.info(`Skip unsupported label: ${labelName}`); return; } await github.rest.issues.createComment({ ...config, body: action.body, }); if (action.close) { await github.rest.issues.update({ ...config, state: 'closed', }); }
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.