Skip to content
Latchkey

Deploy Worker workflow (7Sageer/sublink-worker)

The Deploy Worker workflow from 7Sageer/sublink-worker, explained and optimized by Latchkey.

F

CI health: F - at risk

Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: 7Sageer/sublink-worker.github/workflows/deploy.ymlLicense MITView source

What it does

This is the Deploy Worker workflow from the 7Sageer/sublink-worker 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: Deploy Worker

on:
  workflow_dispatch:
  repository_dispatch:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22'
      
      - name: Install dependencies
        run: npm install
      
      - name: Install wrangler
        run: npm install -g wrangler
      
      - name: Check and Create KV Namespace
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
        run: |
          KV_NAMESPACE="SUBLINK_KV"
          echo "Checking for KV namespace: $KV_NAMESPACE"
          if ! LIST_OUTPUT=$(wrangler kv namespace list 2>&1); then
            echo "Error getting KV namespace list: $LIST_OUTPUT"
            exit 1
          fi
          
          LIST_OUTPUT=$(echo "$LIST_OUTPUT" | grep -v "Cloudflare collects" | grep -v "telemetry")
          echo "Cleaned KV namespace list output: $LIST_OUTPUT"
          
          if ! echo "$LIST_OUTPUT" | jq empty; then
            echo "Invalid JSON output from wrangler"
            exit 1
          fi
          
          KV_ID=$(echo "$LIST_OUTPUT" | jq -r '.[] | select(.title == "sublink-worker-'$KV_NAMESPACE'") | .id')
          
          if [ -z "$KV_ID" ]; then
              echo "KV namespace $KV_NAMESPACE does not exist. Creating..."
              CREATE_OUTPUT=$(wrangler kv namespace create "sublink-worker-$KV_NAMESPACE" 2>&1)
              echo "Create KV namespace output: $CREATE_OUTPUT"
              KV_ID=$(echo "$CREATE_OUTPUT" | grep -o '[0-9a-f]\{32\}')
              
              if [ -z "$KV_ID" ]; then
                  echo "Failed to extract KV ID. Full output: $CREATE_OUTPUT"
                  exit 1
              fi
              
              echo "KV namespace $KV_NAMESPACE created successfully with ID: $KV_ID"
          else
              echo "KV namespace $KV_NAMESPACE already exists with ID: $KV_ID"
          fi
          echo "KV_ID=$KV_ID" >> $GITHUB_ENV
          
      - name: Update wrangler.toml
        run: |
          # Read the entire content of wrangler.toml
          WRANGLER_CONTENT=$(cat wrangler.toml)
          
          # Update the KV namespace ID
          UPDATED_CONTENT=$(echo "$WRANGLER_CONTENT" | sed 's/id = "[^"]*"/id = "'$KV_ID'"/')
          
          # Write the updated content back to wrangler.toml
          echo "$UPDATED_CONTENT" > wrangler.toml
          
          echo "Updated wrangler.toml content:"
          cat wrangler.toml
          
      - name: Deploy to Cloudflare Workers
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          command: deploy

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

name: Deploy Worker
 
on:
  workflow_dispatch:
  repository_dispatch:
  push:
    branches:
      - main
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  deploy:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          cache: 'npm'
          node-version: '22'
      
      - name: Install dependencies
        run: npm install
      
      - name: Install wrangler
        run: npm install -g wrangler
      
      - name: Check and Create KV Namespace
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
        run: |
          KV_NAMESPACE="SUBLINK_KV"
          echo "Checking for KV namespace: $KV_NAMESPACE"
          if ! LIST_OUTPUT=$(wrangler kv namespace list 2>&1); then
            echo "Error getting KV namespace list: $LIST_OUTPUT"
            exit 1
          fi
          
          LIST_OUTPUT=$(echo "$LIST_OUTPUT" | grep -v "Cloudflare collects" | grep -v "telemetry")
          echo "Cleaned KV namespace list output: $LIST_OUTPUT"
          
          if ! echo "$LIST_OUTPUT" | jq empty; then
            echo "Invalid JSON output from wrangler"
            exit 1
          fi
          
          KV_ID=$(echo "$LIST_OUTPUT" | jq -r '.[] | select(.title == "sublink-worker-'$KV_NAMESPACE'") | .id')
          
          if [ -z "$KV_ID" ]; then
              echo "KV namespace $KV_NAMESPACE does not exist. Creating..."
              CREATE_OUTPUT=$(wrangler kv namespace create "sublink-worker-$KV_NAMESPACE" 2>&1)
              echo "Create KV namespace output: $CREATE_OUTPUT"
              KV_ID=$(echo "$CREATE_OUTPUT" | grep -o '[0-9a-f]\{32\}')
              
              if [ -z "$KV_ID" ]; then
                  echo "Failed to extract KV ID. Full output: $CREATE_OUTPUT"
                  exit 1
              fi
              
              echo "KV namespace $KV_NAMESPACE created successfully with ID: $KV_ID"
          else
              echo "KV namespace $KV_NAMESPACE already exists with ID: $KV_ID"
          fi
          echo "KV_ID=$KV_ID" >> $GITHUB_ENV
          
      - name: Update wrangler.toml
        run: |
          # Read the entire content of wrangler.toml
          WRANGLER_CONTENT=$(cat wrangler.toml)
          
          # Update the KV namespace ID
          UPDATED_CONTENT=$(echo "$WRANGLER_CONTENT" | sed 's/id = "[^"]*"/id = "'$KV_ID'"/')
          
          # Write the updated content back to wrangler.toml
          echo "$UPDATED_CONTENT" > wrangler.toml
          
          echo "Updated wrangler.toml content:"
          cat wrangler.toml
          
      - name: Deploy to Cloudflare Workers
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          command: deploy
 

What changed

1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow