Skip to content
Latchkey

Build AR.js libraries workflow (AR-js-org/AR.js)

The Build AR.js libraries workflow from AR-js-org/AR.js, 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: AR-js-org/AR.js.github/workflows/build.ymlLicense MITView source

What it does

This is the Build AR.js libraries workflow from the AR-js-org/AR.js 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: Build AR.js libraries

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch.
# The action script will build all the libs and will commit the files. When a new git tag is created
# will be made a new release.
on: push

jobs:
  check-and-test:
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ssh-key: ${{ secrets.DEPLOY_KEY }}

      - name: Use Node.js from .nvmrc
        uses: actions/setup-node@v4
        with:
          node-version-file: ".nvmrc"

      - name: Get npm cache directory
        id: npm-cache-dir
        shell: bash
        run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

      - uses: actions/cache@v4
        id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
        with:
          path: ${{ steps.npm-cache-dir.outputs.dir }}
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - name: Set output
        id: vars
        run: echo name=tag::${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
      - name: Check output
        env:
          RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
        run: |
          echo $RELEASE_VERSION
          echo ${{ steps.vars.outputs.tag }}
      - run: npm update
      - run: npm install
      - uses: actions/upload-artifact@v4
        with:
          name: build
          path: |
            aframe/build/*.js
            three.js/build/*.js
      - run: |
          npm run build
      - name: Commit changes
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
        uses: EndBug/add-and-commit@v9
        with:
          default_author: github_actions
          message: new build files from action
          add: '["aframe/build", "three.js/build"]'
      - name: Release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: |
            aframe/build/aframe-ar.js
            aframe/build/aframe-ar.mjs
            aframe/build/aframe-ar-nft.js
            aframe/build/aframe-ar-nft.mjs
            aframe/build/aframe-ar-location-only.js
            aframe/build/aframe-ar-location-only.mjs
            aframe/build/aframe-ar-new-location-only.js
            aframe/build/aframe-ar-new-location-only.mjs
            three.js/build/ar.js
            three.js/build/ar.mjs
            three.js/build/ar-threex.js
            three.js/build/ar-threex.mjs
            three.js/build/ar-threex-location-only.js
            three.js/build/ar-threex-location-only.mjs

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: Build AR.js libraries
 
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch.
# The action script will build all the libs and will commit the files. When a new git tag is created
# will be made a new release.
on: push
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  check-and-test:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ssh-key: ${{ secrets.DEPLOY_KEY }}
 
      - name: Use Node.js from .nvmrc
        uses: actions/setup-node@v4
        with:
          cache: 'npm'
          node-version-file: ".nvmrc"
 
      - name: Get npm cache directory
        id: npm-cache-dir
        shell: bash
        run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
 
      - uses: actions/cache@v4
        id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
        with:
          path: ${{ steps.npm-cache-dir.outputs.dir }}
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - name: Set output
        id: vars
        run: echo name=tag::${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
      - name: Check output
        env:
          RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
        run: |
          echo $RELEASE_VERSION
          echo ${{ steps.vars.outputs.tag }}
      - run: npm update
      - run: npm install
      - uses: actions/upload-artifact@v4
        with:
          name: build
          path: |
            aframe/build/*.js
            three.js/build/*.js
      - run: |
          npm run build
      - name: Commit changes
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
        uses: EndBug/add-and-commit@v9
        with:
          default_author: github_actions
          message: new build files from action
          add: '["aframe/build", "three.js/build"]'
      - name: Release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: |
            aframe/build/aframe-ar.js
            aframe/build/aframe-ar.mjs
            aframe/build/aframe-ar-nft.js
            aframe/build/aframe-ar-nft.mjs
            aframe/build/aframe-ar-location-only.js
            aframe/build/aframe-ar-location-only.mjs
            aframe/build/aframe-ar-new-location-only.js
            aframe/build/aframe-ar-new-location-only.mjs
            three.js/build/ar.js
            three.js/build/ar.mjs
            three.js/build/ar-threex.js
            three.js/build/ar-threex.mjs
            three.js/build/ar-threex-location-only.js
            three.js/build/ar-threex-location-only.mjs
 

What changed

2 third-party actions are referenced by a movable tag. Pin them 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