Docs Alias Failure Notification workflow (vercel/turbo)
The Docs Alias Failure Notification workflow from vercel/turbo, explained and optimized by Latchkey.
- A
- CI health grade
- 85/100
- Health score
- 1
- Job per trigger
- 2
- Fixes in the optimized version
In short
- CI health: A (excellent)
- The optimized version below points runs-on at Latchkey managed runners and adds job timeouts.
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
# 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: ubuntu-latest
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. Each Linux x64 job moves to the Latchkey size matching its vCPU count,latchkey-smallfor a standard 2 vCPU runner; macOS, Windows and arm64 jobs stay as written. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. It runs on a standard GitHub-hosted Linux x64 runner, which in a private repository bills $0.006 a minute against $0.0025 on latchkey-small, 58% lower; in a public repository like this one it is free. Estimate the monthly difference with your own run counts.
Actions used in this workflow
- slackapi/slack-github-action