Skip to content
Latchkey

πŸ—οΈ Build + Publish templates.json file workflow (lissy93/portainer-templates)

The πŸ—οΈ Build + Publish templates.json file workflow from lissy93/portainer-templates, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, 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: lissy93/portainer-templates.github/workflows/build-template.ymlLicense MITView source

What it does

This is the πŸ—οΈ Build + Publish templates.json file workflow from the lissy93/portainer-templates 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)
# Regenerates templates.json weekly and commits it back to main.
# Cron/dispatch only (no push trigger) so its own commit can't re-run it.
name: πŸ—οΈ Build + Publish templates.json file

on:
  workflow_dispatch:
  schedule:
    - cron: '0 2 * * *' # Nightly at 02:00

# Read by default; the build job elevates to write to commit
permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      # Checkout repo
      - name: Checkout repository πŸ›ŽοΈ
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
        with:
          # We push with our own token below
          persist-credentials: false

      # Get current date-time (used for commit message)
      - name: Get Date πŸ“…
        id: date
        run: echo "date=$(date +'%d-%b-%Y')" >> "$GITHUB_OUTPUT"

      # Downloads + installs Python (used for running gen scripts)
      - name: Set up Python 🐍
        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: '3.x'

      # Install contents of requirements.txt
      - name: Install dependencies πŸ“₯
        run: |
          python -m pip install --upgrade pip
          cd lib && pip install -r requirements.txt

      # The make command triggers all the Python scripts, generates output
      - name: Run make command πŸ”¨
        run: make

      # Commit and push the outputed JSON files
      - name: Commit and push generated files ‴️
        env:
          DATE: ${{ steps.date.outputs.date }}
          # BOT_TOKEN so the push triggers the Tag workflow (GITHUB_TOKEN wouldn't)
          GH_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
          REPO: ${{ github.repository }}
        run: |
          set -euo pipefail
          git config user.name "Liss-Bot"
          git config user.email "alicia-gh-bot@mail.as93.net"
          remote="https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git"
          git add templates.json
          if git diff --staged --quiet; then
            echo "Nothin new added, so nothing to commit, exiting..."
          else
            git commit -m "Updates templates (auto-generated, on ${DATE})"
            git push "$remote" HEAD:main
          fi
          git add .github/README.md
          if git diff --staged --quiet; then
            echo "No need to update README, skipping..."
          else
            git commit -m "Updates template + source list in docs (auto-generated, on ${DATE})"
            git push "$remote" HEAD:main
          fi

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.

# Regenerates templates.json weekly and commits it back to main.
# Cron/dispatch only (no push trigger) so its own commit can't re-run it.
name: πŸ—οΈ Build + Publish templates.json file
 
on:
  workflow_dispatch:
  schedule:
    - cron: '0 2 * * *' # Nightly at 02:00
 
# Read by default; the build job elevates to write to commit
permissions:
  contents: read
 
jobs:
  build:
    timeout-minutes: 30
    runs-on: latchkey-small
    permissions:
      contents: write
    steps:
      # Checkout repo
      - name: Checkout repository πŸ›ŽοΈ
        uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
        with:
          # We push with our own token below
          persist-credentials: false
 
      # Get current date-time (used for commit message)
      - name: Get Date πŸ“…
        id: date
        run: echo "date=$(date +'%d-%b-%Y')" >> "$GITHUB_OUTPUT"
 
      # Downloads + installs Python (used for running gen scripts)
      - name: Set up Python 🐍
        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          cache: 'pip'
          python-version: '3.x'
 
      # Install contents of requirements.txt
      - name: Install dependencies πŸ“₯
        run: |
          python -m pip install --upgrade pip
          cd lib && pip install -r requirements.txt
 
      # The make command triggers all the Python scripts, generates output
      - name: Run make command πŸ”¨
        run: make
 
      # Commit and push the outputed JSON files
      - name: Commit and push generated files ‴️
        env:
          DATE: ${{ steps.date.outputs.date }}
          # BOT_TOKEN so the push triggers the Tag workflow (GITHUB_TOKEN wouldn't)
          GH_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
          REPO: ${{ github.repository }}
        run: |
          set -euo pipefail
          git config user.name "Liss-Bot"
          git config user.email "alicia-gh-bot@mail.as93.net"
          remote="https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git"
          git add templates.json
          if git diff --staged --quiet; then
            echo "Nothin new added, so nothing to commit, exiting..."
          else
            git commit -m "Updates templates (auto-generated, on ${DATE})"
            git push "$remote" HEAD:main
          fi
          git add .github/README.md
          if git diff --staged --quiet; then
            echo "No need to update README, skipping..."
          else
            git commit -m "Updates template + source list in docs (auto-generated, on ${DATE})"
            git push "$remote" HEAD:main
          fi
 

What changed

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