Skip to content
Latchkey

Issue Closed workflow (layui/layui)

The Issue Closed 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.

Grade your own workflow free or run it on Latchkey →
Source: layui/layui.github/workflows/issue-closed.ymlLicense MITView source

What it does

This is the Issue Closed 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 Closed

on:
  issues:
    types: [closed]

jobs:
  issue-closed:
    runs-on: ubuntu-latest
    steps:
      # 追加标签
      - name: Add labels
        id: label-check
        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 issue = await github.rest.issues.get(config);

            // 是否带有 `bug`, `wontfix` 标签
            const hasBugLabel = issue.data.labels.some(label => label.name === 'bug');
            const hasWontfixLabel = issue.data.labels.some(label => label.name === 'wontfix');

            // 对带有 `bug` 标签的 issue 追加 `resolved` 标签,表示 bug 已解决。
            if (hasBugLabel && !hasWontfixLabel) {
              github.rest.issues.addLabels({
                ...config,
                labels: ['resolved']
              });
            }

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Issue Closed
 
on:
  issues:
    types: [closed]
 
jobs:
  issue-closed:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      # 追加标签
      - name: Add labels
        id: label-check
        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 issue = await github.rest.issues.get(config);
 
            // 是否带有 `bug`, `wontfix` 标签
            const hasBugLabel = issue.data.labels.some(label => label.name === 'bug');
            const hasWontfixLabel = issue.data.labels.some(label => label.name === 'wontfix');
 
            // 对带有 `bug` 标签的 issue 追加 `resolved` 标签,表示 bug 已解决。
            if (hasBugLabel && !hasWontfixLabel) {
              github.rest.issues.addLabels({
                ...config,
                labels: ['resolved']
              });
            }
 

What changed

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow