Issue Opened workflow (layui/layui)
The Issue Opened 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 Opened 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 Opened
on:
issues:
types: [opened, edited, typed, untyped]
permissions:
contents: read
jobs:
issue-opened:
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_ENV
- name: check invalid
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const config = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
};
const payload = context.payload;
const isCreatedByBot = payload.sender.type === 'Bot';
const issue = payload.issue;
// 是否遵循 Issue 模板
const followsIssueTemplate = issue.body?.includes('layui-issue-template');
// 是否已选择 GitHub Issue Type
const issueTypeValue = issue.type?.name || issue.issue_type?.name;
const hasIssueType = !!issueTypeValue;
// 跳过 closed 状态的 issues
if (issue.state === 'closed') {
return console.log('Issue is closed.');
}
// 若修改的不是内容,则不必校验
if (payload.action === 'edited') {
if (payload.changes && !payload.changes.body.from) {
return console.log('Edited fields exclude "body".');
}
}
// 若已选择 Issue Type,则无需校验
if (hasIssueType) {
return console.log(`Issue has Issue Type: ${issueTypeValue}`);
}
// 由机器人创建或不符合模板规范
if (isCreatedByBot || !followsIssueTemplate) {
if (!isCreatedByBot) {
github.rest.issues.createComment({
...config,
body: `@${payload.sender.login} 你好,为了提升沟通效率,我们对 Issue 制定了严格的要求,你的 Issue 因不符合规定而被自动关闭。
建议你在下次创建 Issue 时,遵循相应规范和社区行为准则。谢谢。\n > ${process.env.CONTRIBUTING}`
});
}
// 给 issue 添加指定标签和关闭
github.rest.issues.addLabels({
...config,
labels: ['invalid']
});
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 Opened on: issues: types: [opened, edited, typed, untyped] permissions: contents: read jobs: issue-opened: 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_ENV - name: check invalid uses: actions/github-script@v9 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const config = { owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }; const payload = context.payload; const isCreatedByBot = payload.sender.type === 'Bot'; const issue = payload.issue; // 是否遵循 Issue 模板 const followsIssueTemplate = issue.body?.includes('layui-issue-template'); // 是否已选择 GitHub Issue Type const issueTypeValue = issue.type?.name || issue.issue_type?.name; const hasIssueType = !!issueTypeValue; // 跳过 closed 状态的 issues if (issue.state === 'closed') { return console.log('Issue is closed.'); } // 若修改的不是内容,则不必校验 if (payload.action === 'edited') { if (payload.changes && !payload.changes.body.from) { return console.log('Edited fields exclude "body".'); } } // 若已选择 Issue Type,则无需校验 if (hasIssueType) { return console.log(`Issue has Issue Type: ${issueTypeValue}`); } // 由机器人创建或不符合模板规范 if (isCreatedByBot || !followsIssueTemplate) { if (!isCreatedByBot) { github.rest.issues.createComment({ ...config, body: `@${payload.sender.login} 你好,为了提升沟通效率,我们对 Issue 制定了严格的要求,你的 Issue 因不符合规定而被自动关闭。 建议你在下次创建 Issue 时,遵循相应规范和社区行为准则。谢谢。\n > ${process.env.CONTRIBUTING}` }); } // 给 issue 添加指定标签和关闭 github.rest.issues.addLabels({ ...config, labels: ['invalid'] }); 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.