Skip to content
Latchkey

cleanup nightlies workflow (goreleaser/goreleaser)

The cleanup nightlies workflow from goreleaser/goreleaser, 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: goreleaser/goreleaser.github/workflows/cleanup-nightlies.ymlLicense MITView source

What it does

This is the cleanup nightlies workflow from the goreleaser/goreleaser 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: cleanup nightlies

on:
  workflow_dispatch:
  schedule:
    - cron: "0 6 * * *"

permissions:
  contents: read

jobs:
  cleanup:
    runs-on: ubuntu-latest
    if: github.repository == 'goreleaser/goreleaser'
    permissions:
      contents: write
    steps:
      - name: Delete old nightly releases
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          set -euo pipefail

          gh release -R goreleaser/goreleaser list \
            --limit 100 \
            --json tagName,isPrerelease,publishedAt \
            --jq '[.[] | select(.isPrerelease and (.tagName | endswith("-nightly"))) | {tagName, publishedAt}] | sort_by(.publishedAt) | reverse | .[5:][].tagName' |
          while read -r tag; do
            echo "Deleting $tag..."
            gh release -R goreleaser/goreleaser delete "$tag" --cleanup-tag --yes
          done

The same workflow, on Latchkey

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

name: cleanup nightlies
 
on:
  workflow_dispatch:
  schedule:
    - cron: "0 6 * * *"
 
permissions:
  contents: read
 
jobs:
  cleanup:
    timeout-minutes: 30
    runs-on: latchkey-small
    if: github.repository == 'goreleaser/goreleaser'
    permissions:
      contents: write
    steps:
      - name: Delete old nightly releases
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          set -euo pipefail
 
          gh release -R goreleaser/goreleaser list \
            --limit 100 \
            --json tagName,isPrerelease,publishedAt \
            --jq '[.[] | select(.isPrerelease and (.tagName | endswith("-nightly"))) | {tagName, publishedAt}] | sort_by(.publishedAt) | reverse | .[5:][].tagName' |
          while read -r tag; do
            echo "Deleting $tag..."
            gh release -R goreleaser/goreleaser delete "$tag" --cleanup-tag --yes
          done
 

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.