Comment Bundle Size workflow (shaka-project/shaka-player)
The Comment Bundle Size workflow from shaka-project/shaka-player, explained and optimized by Latchkey.
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 Comment Bundle Size workflow from the shaka-project/shaka-player repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Comment Bundle Size
# Runs when Measure Bundle Size workflow completes.
# This will run with full privileges.
on:
workflow_run:
workflows: [Measure Bundle Size]
types: [completed]
jobs:
comment:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download report artifact
uses: actions/download-artifact@v4
with:
name: bundle-report
path: artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.SHAKA_BOT_TOKEN }}
- name: Add or Update PR Comment
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.SHAKA_BOT_TOKEN }}
COMMENT_INCLUDES: "Bundle Size Report"
COMMENT_USER: "shaka-bot"
run: |
MESSAGE=$(cat artifact/report.md)
echo "$MESSAGE"
PR_NUMBER=$(echo "$MESSAGE" | head -1 | grep -oE "[0-9]+")
echo "PR_NUMBER: $PR_NUMBER"
# Find existing bot comment
jq_filter=".[] | select((.user.login == \"$COMMENT_USER\") and (.body | startswith(\"$COMMENT_INCLUDES\"))) | .id"
gh api \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
| jq "$jq_filter" > old-comment-id
if [[ -z "$(cat old-comment-id)" ]]; then
echo "Creating new bundle size comment"
gh api \
--method POST \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
-f "body=$MESSAGE"
else
echo "Updating existing bundle size comment"
gh api \
--method PATCH \
/repos/${{ github.repository }}/issues/comments/$(cat old-comment-id) \
-f "body=$MESSAGE"
fi
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Comment Bundle Size # Runs when Measure Bundle Size workflow completes. # This will run with full privileges. on: workflow_run: workflows: [Measure Bundle Size] types: [completed] jobs: comment: timeout-minutes: 30 runs-on: latchkey-small if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Download report artifact uses: actions/download-artifact@v4 with: name: bundle-report path: artifact run-id: ${{ github.event.workflow_run.id }} github-token: ${{ secrets.SHAKA_BOT_TOKEN }} - name: Add or Update PR Comment shell: bash env: GITHUB_TOKEN: ${{ secrets.SHAKA_BOT_TOKEN }} COMMENT_INCLUDES: "Bundle Size Report" COMMENT_USER: "shaka-bot" run: | MESSAGE=$(cat artifact/report.md) echo "$MESSAGE" PR_NUMBER=$(echo "$MESSAGE" | head -1 | grep -oE "[0-9]+") echo "PR_NUMBER: $PR_NUMBER" # Find existing bot comment jq_filter=".[] | select((.user.login == \"$COMMENT_USER\") and (.body | startswith(\"$COMMENT_INCLUDES\"))) | .id" gh api \ /repos/${{ github.repository }}/issues/$PR_NUMBER/comments \ | jq "$jq_filter" > old-comment-id if [[ -z "$(cat old-comment-id)" ]]; then echo "Creating new bundle size comment" gh api \ --method POST \ /repos/${{ github.repository }}/issues/$PR_NUMBER/comments \ -f "body=$MESSAGE" else echo "Updating existing bundle size comment" gh api \ --method PATCH \ /repos/${{ github.repository }}/issues/comments/$(cat old-comment-id) \ -f "body=$MESSAGE" fi
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.