Skip to content
Latchkey

Deploy To Artifacts workflow (DevExpress/testcafe)

The Deploy To Artifacts workflow from DevExpress/testcafe, explained and optimized by Latchkey.

B

CI health: B - good

Point runs-on at Latchkey and get 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: DevExpress/testcafe.github/workflows/deploy-to-artifacts.ymlLicense MITView source

What it does

This is the Deploy To Artifacts workflow from the DevExpress/testcafe 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 To Artifacts

on:
  workflow_dispatch:
    inputs:
      sha:
        description: 'The commit ref or SHA'
        required: true
        default: 'master'
      merged_sha:
        description: 'The merge commit SHA'
      base_sha:
        description: 'The base commit SHA'

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      sha: ${{steps.prep.outputs.sha}}
    steps:
      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        with:
          status: 'pending'

      - name: Build Info
        run: |
          echo "SHA: ${{ github.event.inputs.sha }}"
          echo "Merged SHA: ${{ github.event.inputs.merged_sha }}"
          echo "Deployment run ID: ${{ github.run_id }}"
      - id: prep
        uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            core.setOutput('sha', context.payload.inputs.merged_sha || context.payload.inputs.sha);
      - uses: actions/checkout@v3
        with:
          ref: ${{steps.prep.outputs.sha}}
      - run: |
          npm ci
          npx --no-install gulp build
          npm pack
      - id: package-name
        uses: actions/github-script@v6
        with:
          script: |
            const { name, version } = require(require('path').join(process.env.GITHUB_WORKSPACE, 'package.json'));

            core.setOutput('packageName', `${name}-${version}`);
            core.setOutput('imageName', `${name}/${name}:${version}`);

      - uses: actions/upload-artifact@v4
        with:
          name: npm
          path: |
            ${{steps.package-name.outputs.packageName}}.tgz
      - run: |
          npx --no-install gulp docker-build
          docker save -o ${{steps.package-name.outputs.packageName}}.tar ${{steps.package-name.outputs.imageName}}
      - uses: actions/upload-artifact@v4
        with:
          name: docker
          path: ${{steps.package-name.outputs.packageName}}.tar

      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        if: failure() || cancelled()
        with:
          status: 'failure'

  changes:
    # TODO: currently cannot generate a list of changes after rebase
    runs-on: ubuntu-latest
    steps:
      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        with:
          status: 'pending'

      - uses: actions/checkout@v3
        with:
          ref: ${{ github.event.inputs.sha }}
          fetch-depth: 0
      - run: |
          git reset --soft `git merge-base "${{github.event.inputs.base_sha}}" HEAD`
          git diff --name-only --cached > changes.txt
      - uses: actions/upload-artifact@v4
        with:
          name: changes
          path: changes.txt

      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        if: failure() || cancelled()
        with:
          status: 'failure'

  test:
    needs: [build, changes]
    runs-on: ubuntu-latest
    environment: CI
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: changes
      - uses: actions/github-script@v6
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            function getInputs () {
              const { sha, merged_sha } = context.payload.inputs;

              return {
                ...merged_sha ? { merged_sha } : {},
                sha,
                deploy_run_id: '${{github.run_id}}'
              }
            }

            async function dispatchWorkflow (workflowName) {
              await github.rest.actions.createWorkflowDispatch({
                owner: context.repo.owner,
                repo: context.repo.repo,
                ref: 'master',
                workflow_id: workflowName,
                inputs: getInputs()
              });
            }

            // TODO: Optimize by running only necessary tests for corresponding changes
            const fileList = require('fs').readFileSync('changes.txt').toString().split('\n').filter(line => line);

            const tasks = [];

            tasks.push('test-client-desktop.yml');
            tasks.push('test-client-mobile.yml');
            tasks.push('test-functional-docker.yml');
            tasks.push('test-functional-local-safari.yml');
            tasks.push('test-functional-local-esm.yml');
            tasks.push('test-functional-local-chrome.yml');
            tasks.push('test-functional-local-edge.yml');
            tasks.push('test-functional-local-firefox.yml');
            tasks.push('test-functional-local-multiple-windows.yml');
            tasks.push('test-functional-local-multiple-windows-na.yml');
            tasks.push('test-functional-local-native-automation.yml');
            tasks.push('test-functional-local-headed-browsers.yml');
            tasks.push('test-functional-local-legacy.yml');
            tasks.push('test-functional-remote-mobile.yml');
            tasks.push('test-server-docker.yml');
            tasks.push('test-server-minimal.yml');
            tasks.push('test-server-latest.yml');
            tasks.push('license-check.yml');

            await Promise.all(tasks.map(task => dispatchWorkflow(task)));

      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        if: always()
        with:
          status: ${{ fromJSON('["failure", "success"]')[job.status == 'success'] }}
          artifacts-path: ${{ fromJSON('["", "#artifacts"]')[job.status == 'success'] }}

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Deploy To Artifacts
 
on:
  workflow_dispatch:
    inputs:
      sha:
        description: 'The commit ref or SHA'
        required: true
        default: 'master'
      merged_sha:
        description: 'The merge commit SHA'
      base_sha:
        description: 'The base commit SHA'
 
jobs:
  build:
    timeout-minutes: 30
    runs-on: latchkey-small
    outputs:
      sha: ${{steps.prep.outputs.sha}}
    steps:
      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        with:
          status: 'pending'
 
      - name: Build Info
        run: |
          echo "SHA: ${{ github.event.inputs.sha }}"
          echo "Merged SHA: ${{ github.event.inputs.merged_sha }}"
          echo "Deployment run ID: ${{ github.run_id }}"
      - id: prep
        uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            core.setOutput('sha', context.payload.inputs.merged_sha || context.payload.inputs.sha);
      - uses: actions/checkout@v3
        with:
          ref: ${{steps.prep.outputs.sha}}
      - run: |
          npm ci
          npx --no-install gulp build
          npm pack
      - id: package-name
        uses: actions/github-script@v6
        with:
          script: |
            const { name, version } = require(require('path').join(process.env.GITHUB_WORKSPACE, 'package.json'));
 
            core.setOutput('packageName', `${name}-${version}`);
            core.setOutput('imageName', `${name}/${name}:${version}`);
 
      - uses: actions/upload-artifact@v4
        with:
          name: npm
          path: |
            ${{steps.package-name.outputs.packageName}}.tgz
      - run: |
          npx --no-install gulp docker-build
          docker save -o ${{steps.package-name.outputs.packageName}}.tar ${{steps.package-name.outputs.imageName}}
      - uses: actions/upload-artifact@v4
        with:
          name: docker
          path: ${{steps.package-name.outputs.packageName}}.tar
 
      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        if: failure() || cancelled()
        with:
          status: 'failure'
 
  changes:
    timeout-minutes: 30
    # TODO: currently cannot generate a list of changes after rebase
    runs-on: latchkey-small
    steps:
      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        with:
          status: 'pending'
 
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.event.inputs.sha }}
          fetch-depth: 0
      - run: |
          git reset --soft `git merge-base "${{github.event.inputs.base_sha}}" HEAD`
          git diff --name-only --cached > changes.txt
      - uses: actions/upload-artifact@v4
        with:
          name: changes
          path: changes.txt
 
      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        if: failure() || cancelled()
        with:
          status: 'failure'
 
  test:
    timeout-minutes: 30
    needs: [build, changes]
    runs-on: latchkey-small
    environment: CI
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: changes
      - uses: actions/github-script@v6
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            function getInputs () {
              const { sha, merged_sha } = context.payload.inputs;
 
              return {
                ...merged_sha ? { merged_sha } : {},
                sha,
                deploy_run_id: '${{github.run_id}}'
              }
            }
 
            async function dispatchWorkflow (workflowName) {
              await github.rest.actions.createWorkflowDispatch({
                owner: context.repo.owner,
                repo: context.repo.repo,
                ref: 'master',
                workflow_id: workflowName,
                inputs: getInputs()
              });
            }
 
            // TODO: Optimize by running only necessary tests for corresponding changes
            const fileList = require('fs').readFileSync('changes.txt').toString().split('\n').filter(line => line);
 
            const tasks = [];
 
            tasks.push('test-client-desktop.yml');
            tasks.push('test-client-mobile.yml');
            tasks.push('test-functional-docker.yml');
            tasks.push('test-functional-local-safari.yml');
            tasks.push('test-functional-local-esm.yml');
            tasks.push('test-functional-local-chrome.yml');
            tasks.push('test-functional-local-edge.yml');
            tasks.push('test-functional-local-firefox.yml');
            tasks.push('test-functional-local-multiple-windows.yml');
            tasks.push('test-functional-local-multiple-windows-na.yml');
            tasks.push('test-functional-local-native-automation.yml');
            tasks.push('test-functional-local-headed-browsers.yml');
            tasks.push('test-functional-local-legacy.yml');
            tasks.push('test-functional-remote-mobile.yml');
            tasks.push('test-server-docker.yml');
            tasks.push('test-server-minimal.yml');
            tasks.push('test-server-latest.yml');
            tasks.push('license-check.yml');
 
            await Promise.all(tasks.map(task => dispatchWorkflow(task)));
 
      - uses: DevExpress/testcafe-build-system/actions/set-status@main
        if: always()
        with:
          status: ${{ fromJSON('["failure", "success"]')[job.status == 'success'] }}
          artifacts-path: ${{ fromJSON('["", "#artifacts"]')[job.status == 'success'] }}
 

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 3 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow