Docs Alias Failure Notification workflow (vercel/turbo)
The Docs Alias Failure Notification workflow from vercel/turbo, 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 Docs Alias Failure Notification workflow from the vercel/turbo 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)
# Docs Alias Failure Notification
#
# Sends a Slack notification when the versioned docs alias assignment fails.
name: Docs Alias Failure Notification
env:
TURBO_TELEMETRY_MESSAGE_DISABLED: "1"
on:
workflow_run:
workflows: ["Release"]
types:
- completed
permissions:
contents: read
jobs:
notify-failure:
name: "Notify Slack on Docs Alias Failure"
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
# Fetch version.txt via the API at the exact commit of the failed run
# instead of checking out the branch. This avoids checking out a ref by
# name (the staging branch may already be deleted by the failure cleanup
# job) and avoids putting any repo content on disk.
- name: Get version
id: version
shell: bash
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
if CONTENT=$(gh api -H "Accept: application/vnd.github.raw+json" "repos/${{ github.repository }}/contents/version.txt?ref=${HEAD_SHA}"); then
IFS= read -r VERSION <<< "$CONTENT"
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then
printf 'version=%s\n' "$VERSION" >> "$GITHUB_OUTPUT"
else
echo "::warning::version.txt did not contain a valid release version. Reporting unknown version."
echo "version=unknown" >> "$GITHUB_OUTPUT"
fi
else
echo "::warning::Could not fetch version.txt at ${HEAD_SHA}. Reporting unknown version."
echo "version=unknown" >> "$GITHUB_OUTPUT"
fi
- name: Send failure notification to Slack
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
webhook: ${{ secrets.DOCS_ALIAS_FAILURE_SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"version": ${{ toJSON(steps.version.outputs.version) }}
}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
# Docs Alias Failure Notification # # Sends a Slack notification when the versioned docs alias assignment fails. name: Docs Alias Failure Notification env: TURBO_TELEMETRY_MESSAGE_DISABLED: "1" on: workflow_run: workflows: ["Release"] types: - completed permissions: contents: read jobs: notify-failure: timeout-minutes: 30 name: "Notify Slack on Docs Alias Failure" runs-on: latchkey-small if: ${{ github.event.workflow_run.conclusion == 'failure' }} steps: # Fetch version.txt via the API at the exact commit of the failed run # instead of checking out the branch. This avoids checking out a ref by # name (the staging branch may already be deleted by the failure cleanup # job) and avoids putting any repo content on disk. - name: Get version id: version shell: bash env: GH_TOKEN: ${{ github.token }} HEAD_SHA: ${{ github.event.workflow_run.head_sha }} run: | if CONTENT=$(gh api -H "Accept: application/vnd.github.raw+json" "repos/${{ github.repository }}/contents/version.txt?ref=${HEAD_SHA}"); then IFS= read -r VERSION <<< "$CONTENT" if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then printf 'version=%s\n' "$VERSION" >> "$GITHUB_OUTPUT" else echo "::warning::version.txt did not contain a valid release version. Reporting unknown version." echo "version=unknown" >> "$GITHUB_OUTPUT" fi else echo "::warning::Could not fetch version.txt at ${HEAD_SHA}. Reporting unknown version." echo "version=unknown" >> "$GITHUB_OUTPUT" fi - name: Send failure notification to Slack uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0 with: webhook: ${{ secrets.DOCS_ALIAS_FAILURE_SLACK_WEBHOOK_URL }} webhook-type: incoming-webhook payload: | { "version": ${{ toJSON(steps.version.outputs.version) }} }
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.