Comment on old issues workflow (stylelint/stylelint)
The Comment on old issues workflow from stylelint/stylelint, explained and optimized by Latchkey.
A
CI health: A - excellent
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the Comment on old issues workflow from the stylelint/stylelint 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: Comment on old issues
on:
schedule:
- cron: '0 0 * * *' # Every day at 00:00 UTC
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-slim
if: github.repository == 'stylelint/stylelint'
permissions:
issues: write
steps:
- name: Comment on old issues
run: |
six_months_ago=$(date --date '6 months ago' '+%Y-%m-%d')
# For the search syntax, see https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests
old_issue_urls=$(gh issue list \
--search "is:open updated:<${six_months_ago} label:\"status: ready to implement\"" \
--json 'url' \
--jq '.[] | .url')
for url in ${old_issue_urls}; do
gh issue comment "${url}" --body "${issue_comment}"
gh issue edit "${url}" --add-label 'status: ask to implement' --remove-label 'status: ready to implement'
done
env:
GH_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
issue_comment: |-
This issue is older than six months. Please ask before opening a pull request, as it may no longer be relevant.
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Comment on old issues on: schedule: - cron: '0 0 * * *' # Every day at 00:00 UTC workflow_dispatch: jobs: check: timeout-minutes: 30 runs-on: ubuntu-slim if: github.repository == 'stylelint/stylelint' permissions: issues: write steps: - name: Comment on old issues run: | six_months_ago=$(date --date '6 months ago' '+%Y-%m-%d') # For the search syntax, see https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests old_issue_urls=$(gh issue list \ --search "is:open updated:<${six_months_ago} label:\"status: ready to implement\"" \ --json 'url' \ --jq '.[] | .url') for url in ${old_issue_urls}; do gh issue comment "${url}" --body "${issue_comment}" gh issue edit "${url}" --add-label 'status: ask to implement' --remove-label 'status: ready to implement' done env: GH_REPO: ${{ github.repository }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} issue_comment: |- This issue is older than six months. Please ask before opening a pull request, as it may no longer be relevant.
What changed
- 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.