Deploy branch to gh-pages #352
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy branch to gh-pages | |
on: | |
workflow_dispatch: | |
inputs: | |
pullNumber: | |
description: 'The PR number' | |
required: true | |
jobs: | |
# Deploys selected branch to GitHub Pages | |
deploy-branch: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/[email protected] | |
with: | |
node-version-file: '.nvmrc' | |
- name: 'Install dependencies' | |
run: npm ci | |
- name: 'Save PR data' | |
uses: actions/github-script@v7 | |
id: prData | |
with: | |
script: | | |
const getData = require('./.github/workflow-scripts/gh-pages/get-pr-data.js'); | |
return await getData({ | |
pullNumber: '${{ github.event.inputs.pullNumber }}', | |
github, | |
context | |
}); | |
- name: 'Download artifacts from PR' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const downloadArtifact = require('./.github/workflow-scripts/gh-pages/download-branch-deploy-artifact.js'); | |
await downloadArtifact({ | |
branch: '${{ fromJSON(steps.prData.outputs.result).branch }}', | |
sha: '${{ fromJSON(steps.prData.outputs.result).sha }}', | |
github, | |
context | |
}); | |
- run: | | |
unzip lg-sb-build.zip -d ./docs/lg-sb-'${{ fromJSON(steps.prData.outputs.result).branch }}' | |
rm lg-sb-build.zip | |
- name: 'Notify GitHub of branch deployment' | |
uses: actions/github-script@v7 | |
id: deploymentId | |
with: | |
script: | | |
const createDeployment = require('./.github/workflow-scripts/gh-pages/create-gh-deployment.js'); | |
return await createDeployment({ | |
sha: '${{ fromJSON(steps.prData.outputs.result).sha }}', | |
github, | |
context, | |
}); | |
- name: 'Notify GitHub of deployment in progress' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const createDeploymentStatus = require('./.github/workflow-scripts/gh-pages/create-gh-deployment-status.js'); | |
await createDeploymentStatus({ | |
deploymentId: ${{ fromJSON(steps.deploymentId.outputs.result) }}, | |
state: 'in_progress', | |
environmentUrl: '${{ fromJSON(steps.prData.outputs.result).environmentUrl }}', | |
github, | |
context, | |
}); | |
- name: 'Branch deployment to GitHub Pages' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const deployBranch = require('./.github/workflow-scripts/gh-pages/deploy.js'); | |
await deployBranch({ | |
branch: '${{ fromJSON(steps.prData.outputs.result).branch }}', | |
sha: '${{ fromJSON(steps.prData.outputs.result).sha }}', | |
pullNumber: ${{ fromJSON(steps.prData.outputs.result).pullNumber }}, | |
github, | |
context, | |
exec, | |
}); | |
- name: 'Checking out current branch' | |
if: always() | |
run: git checkout ${{ github.sha }} | |
- name: 'Notify GitHub of deployment status' | |
if: always() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const createDeploymentStatus = require('./.github/workflow-scripts/gh-pages/create-gh-deployment-status.js'); | |
await createDeploymentStatus({ | |
deploymentId: ${{ fromJSON(steps.deploymentId.outputs.result) }}, | |
state: '${{ job.status }}' === 'success' ? 'success' : 'failure', | |
environmentUrl: '${{ fromJSON(steps.prData.outputs.result).environmentUrl }}', | |
github, | |
context, | |
}); | |
- name: 'Add label to PR' | |
if: success() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const addLabels = require('./.github/workflow-scripts/add-labels.js'); | |
await addLabels({ | |
issueNumber: ${{ fromJSON(steps.prData.outputs.result).pullNumber }}, | |
labels: [ 'deployed' ], | |
github, | |
context | |
}); |