Deploy Website (Preview) workflow (openlayers/openlayers)
The Deploy Website (Preview) workflow from openlayers/openlayers, 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 Deploy Website (Preview) workflow from the openlayers/openlayers repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-2-Clause license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Deploy Website (Preview)
on:
workflow_run:
workflows: ["Build Preview"]
types:
- completed
jobs:
deploy-preview:
runs-on: ubuntu-latest
if: ${{github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'}}
steps:
- uses: actions/setup-node@v6
with:
node-version: '24'
- run: npm install --global netlify-cli@6
- run: npm install unzipper@0.10
- name: Get pull request number
uses: actions/github-script@v9
id: pull-request-number
with:
result-encoding: string
script: |
const unzipper = require('unzipper');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id}}
});
const artifact = artifacts.data.artifacts.filter(
artifact => artifact.name === 'pr'
)[0];
if (!artifact) {
throw new Error('No pr artifact found');
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip'
});
const directory = await unzipper.Open.buffer(Buffer.from(download.data));
const file = directory.files.find(d => d.path === 'number');
const content = await file.buffer();
return content.toString();
- uses: dawidd6/action-download-artifact@v21
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: build-preview.yml
pr: ${{steps.pull-request-number.outputs.result}}
name: site
path: build/site
allow_forks: true
- name: Deploy to Netlify
env:
NETLIFY_AUTH_TOKEN: ${{secrets.NETLIFY_AUTH_TOKEN}}
NETLIFY_SITE_ID: ${{secrets.NETLIFY_SITE_ID}}
run: netlify deploy --dir=build/site --alias=deploy-preview-${{steps.pull-request-number.outputs.result}}
- name: Add comment to pull request
uses: actions/github-script@v9
with:
script: |
const pullRequestNumber = parseInt(${{steps.pull-request-number.outputs.result}}, 10);
const start = '📦';
const author = 'github-actions[bot]';
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber
});
const commentExists = comments.data.some(
comment => comment.user.login === author && comment.body.startsWith(start)
);
if (!commentExists) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
body: `${start} Preview the website for this branch here: https://deploy-preview-${pullRequestNumber}--ol-site.netlify.app/.`
});
} else {
console.log(`Preview URL comment already added to PR #${pullRequestNumber}`);
}
- name: Clean up artifact
uses: actions/github-script@v9
with:
result-encoding: string
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id}}
});
const artifact = artifacts.data.artifacts.filter(
artifact => artifact.name === 'site'
)[0];
if (!artifact) {
throw new Error('No site artifact found');
}
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});
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 Website (Preview) on: workflow_run: workflows: ["Build Preview"] types: - completed jobs: deploy-preview: timeout-minutes: 30 runs-on: latchkey-small if: ${{github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'}} steps: - uses: actions/setup-node@v6 with: cache: 'npm' node-version: '24' - run: npm install --global netlify-cli@6 - run: npm install unzipper@0.10 - name: Get pull request number uses: actions/github-script@v9 id: pull-request-number with: result-encoding: string script: | const unzipper = require('unzipper'); const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, run_id: ${{github.event.workflow_run.id}} }); const artifact = artifacts.data.artifacts.filter( artifact => artifact.name === 'pr' )[0]; if (!artifact) { throw new Error('No pr artifact found'); } const download = await github.rest.actions.downloadArtifact({ owner: context.repo.owner, repo: context.repo.repo, artifact_id: artifact.id, archive_format: 'zip' }); const directory = await unzipper.Open.buffer(Buffer.from(download.data)); const file = directory.files.find(d => d.path === 'number'); const content = await file.buffer(); return content.toString(); - uses: dawidd6/action-download-artifact@v21 with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: build-preview.yml pr: ${{steps.pull-request-number.outputs.result}} name: site path: build/site allow_forks: true - name: Deploy to Netlify env: NETLIFY_AUTH_TOKEN: ${{secrets.NETLIFY_AUTH_TOKEN}} NETLIFY_SITE_ID: ${{secrets.NETLIFY_SITE_ID}} run: netlify deploy --dir=build/site --alias=deploy-preview-${{steps.pull-request-number.outputs.result}} - name: Add comment to pull request uses: actions/github-script@v9 with: script: | const pullRequestNumber = parseInt(${{steps.pull-request-number.outputs.result}}, 10); const start = '📦'; const author = 'github-actions[bot]'; const comments = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pullRequestNumber }); const commentExists = comments.data.some( comment => comment.user.login === author && comment.body.startsWith(start) ); if (!commentExists) { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pullRequestNumber, body: `${start} Preview the website for this branch here: https://deploy-preview-${pullRequestNumber}--ol-site.netlify.app/.` }); } else { console.log(`Preview URL comment already added to PR #${pullRequestNumber}`); } - name: Clean up artifact uses: actions/github-script@v9 with: result-encoding: string script: | const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, run_id: ${{github.event.workflow_run.id}} }); const artifact = artifacts.data.artifacts.filter( artifact => artifact.name === 'site' )[0]; if (!artifact) { throw new Error('No site artifact found'); } await github.rest.actions.deleteArtifact({ owner: context.repo.owner, repo: context.repo.repo, artifact_id: artifact.id });
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.
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:
- Dependency installs
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.