Publish NPM workflow (nhn/tui.image-editor)
The Publish NPM workflow from nhn/tui.image-editor, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Publish NPM workflow from the nhn/tui.image-editor 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
name: Publish NPM
on: [workflow_dispatch]
env:
BUILD_CACHE_KEY: ${{ github.sha }}
jobs:
check-version:
name: Check package version
runs-on: ubuntu-latest
steps:
- name: Checkout production branch
uses: actions/checkout@v2
- name: Check package version
id: check
uses: PostHog/check-package-version@v2
with:
path: ./apps/image-editor/
- name: Cancel actions when version is unchanged
uses: andymckay/cancel-action@0.2
if: steps.check.outputs.is-new-version == 'false'
install-dependencies:
name: Install dependencies
needs: [check-version]
runs-on: ubuntu-latest
steps:
- name: Checkout production branch
uses: actions/checkout@v2
- name: Install dependencies
id: cache-keys
uses: ./.github/composite-actions/install-dependencies
outputs:
root_cache_key: ${{ steps.cache-keys.outputs.root_cache_key }}
build:
name: Build package using cache
needs: [install-dependencies]
runs-on: ubuntu-latest
steps:
- name: Checkout production branch
uses: actions/checkout@v2
with:
ref: production
- name: build
uses: ./.github/composite-actions/build-package
with:
ROOT_CACHE_KEY: ${{ needs.install-dependencies.outputs.root_cache_key }}
BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }}
- name: Get package version
id: version
uses: PostHog/check-package-version@v2
with:
path: ./apps/image-editor/
- name: Commit files
run: |
git config --local user.name "lja1018"
git config --local user.email "jaeeon.lim@nhn.com"
git add .
git commit -m "chore: update version to v${{ steps.version.outputs.committed-version }}"
shell: bash
- name: Push built file
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: production
outputs:
root_cache_key: ${{ needs.install-dependencies.outputs.root_cache_key }}
push-tag:
needs: [build]
name: Push tag
runs-on: ubuntu-latest
steps:
- name: Checkout production branch
uses: actions/checkout@v2
with:
ref: production
- name: Use Node.js 15.x
uses: actions/setup-node@v1
with:
node-version: '15.x'
registry-url: https://registry.npmjs.org/
- name: Get package version
id: version
uses: PostHog/check-package-version@v2
with:
path: ./apps/image-editor/
- name: Create Tag
run: |
git config --local user.name "lja1018"
git config --local user.email "jaeeon.lim@nhn.com"
git tag v${{ steps.version.outputs.committed-version }}
- name: Push tag
run: |
git push origin v${{ steps.version.outputs.committed-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-package:
needs: [build]
name: Publish package
runs-on: ubuntu-latest
steps:
- name: Checkout production branch
uses: actions/checkout@v2
with:
ref: production
- name: Publish package
uses: ./.github/composite-actions/publish-package
with:
ROOT_CACHE_KEY: ${{ needs.build.outputs.root_cache_key }}
BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
publish-cdn:
needs: [build]
name: Publish CDN
runs-on: ubuntu-latest
steps:
- name: Checkout production branch
uses: actions/checkout@v2
with:
ref: production
- name: Publish CDN
uses: ./.github/composite-actions/publish-cdn
with:
ROOT_CACHE_KEY: ${{ needs.build.outputs.root_cache_key }}
BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }}
TOAST_CLOUD_TENANTID: ${{ secrets.TOAST_CLOUD_TENANTID }}
TOAST_CLOUD_STORAGEID: ${{ secrets.TOAST_CLOUD_STORAGEID }}
TOAST_CLOUD_USERNAME: ${{ secrets.TOAST_CLOUD_USERNAME }}
TOAST_CLOUD_PASSWORD: ${{ secrets.TOAST_CLOUD_PASSWORD }}
publish-docs:
needs: [build]
name: Publish docs
runs-on: ubuntu-latest
steps:
- name: Checkout production branch
uses: actions/checkout@v2
with:
ref: production
- name: Publish docs
uses: ./.github/composite-actions/publish-docs
with:
ROOT_CACHE_KEY: ${{ needs.build.outputs.root_cache_key }}
BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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: Publish NPM on: [workflow_dispatch] env: BUILD_CACHE_KEY: ${{ github.sha }} jobs: check-version: timeout-minutes: 30 name: Check package version runs-on: latchkey-small steps: - name: Checkout production branch uses: actions/checkout@v2 - name: Check package version id: check uses: PostHog/check-package-version@v2 with: path: ./apps/image-editor/ - name: Cancel actions when version is unchanged uses: andymckay/cancel-action@0.2 if: steps.check.outputs.is-new-version == 'false' install-dependencies: timeout-minutes: 30 name: Install dependencies needs: [check-version] runs-on: latchkey-small steps: - name: Checkout production branch uses: actions/checkout@v2 - name: Install dependencies id: cache-keys uses: ./.github/composite-actions/install-dependencies outputs: root_cache_key: ${{ steps.cache-keys.outputs.root_cache_key }} build: timeout-minutes: 30 name: Build package using cache needs: [install-dependencies] runs-on: latchkey-small steps: - name: Checkout production branch uses: actions/checkout@v2 with: ref: production - name: build uses: ./.github/composite-actions/build-package with: ROOT_CACHE_KEY: ${{ needs.install-dependencies.outputs.root_cache_key }} BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }} - name: Get package version id: version uses: PostHog/check-package-version@v2 with: path: ./apps/image-editor/ - name: Commit files run: | git config --local user.name "lja1018" git config --local user.email "jaeeon.lim@nhn.com" git add . git commit -m "chore: update version to v${{ steps.version.outputs.committed-version }}" shell: bash - name: Push built file uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: production outputs: root_cache_key: ${{ needs.install-dependencies.outputs.root_cache_key }} push-tag: timeout-minutes: 30 needs: [build] name: Push tag runs-on: latchkey-small steps: - name: Checkout production branch uses: actions/checkout@v2 with: ref: production - name: Use Node.js 15.x uses: actions/setup-node@v1 with: cache: 'npm' node-version: '15.x' registry-url: https://registry.npmjs.org/ - name: Get package version id: version uses: PostHog/check-package-version@v2 with: path: ./apps/image-editor/ - name: Create Tag run: | git config --local user.name "lja1018" git config --local user.email "jaeeon.lim@nhn.com" git tag v${{ steps.version.outputs.committed-version }} - name: Push tag run: | git push origin v${{ steps.version.outputs.committed-version }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-package: timeout-minutes: 30 needs: [build] name: Publish package runs-on: latchkey-small steps: - name: Checkout production branch uses: actions/checkout@v2 with: ref: production - name: Publish package uses: ./.github/composite-actions/publish-package with: ROOT_CACHE_KEY: ${{ needs.build.outputs.root_cache_key }} BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }} NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} publish-cdn: timeout-minutes: 30 needs: [build] name: Publish CDN runs-on: latchkey-small steps: - name: Checkout production branch uses: actions/checkout@v2 with: ref: production - name: Publish CDN uses: ./.github/composite-actions/publish-cdn with: ROOT_CACHE_KEY: ${{ needs.build.outputs.root_cache_key }} BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }} TOAST_CLOUD_TENANTID: ${{ secrets.TOAST_CLOUD_TENANTID }} TOAST_CLOUD_STORAGEID: ${{ secrets.TOAST_CLOUD_STORAGEID }} TOAST_CLOUD_USERNAME: ${{ secrets.TOAST_CLOUD_USERNAME }} TOAST_CLOUD_PASSWORD: ${{ secrets.TOAST_CLOUD_PASSWORD }} publish-docs: timeout-minutes: 30 needs: [build] name: Publish docs runs-on: latchkey-small steps: - name: Checkout production branch uses: actions/checkout@v2 with: ref: production - name: Publish docs uses: ./.github/composite-actions/publish-docs with: ROOT_CACHE_KEY: ${{ needs.build.outputs.root_cache_key }} BUILD_CACHE_KEY: ${{ env.BUILD_CACHE_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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. - Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
3 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.
This workflow runs 7 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.