PR Preview #174
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: PR Preview | |
on: | |
workflow_run: | |
workflows: | |
- valid | |
types: | |
- completed | |
jobs: | |
deploy: | |
name: Deploy Preview | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: potiuk/get-workflow-origin@v1_1 | |
id: source-run-info | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
sourceRunId: ${{ github.event.workflow_run.id }} | |
- run: echo sourceHeadSha = ${{ steps.source-run-info.outputs.sourceHeadSha }} | |
- name: Set env | |
run: echo "GITHUB_SHA_SHORT=$(echo ${{ steps.source-run-info.outputs.sourceHeadSha }} | cut -c 1-20)" >> $GITHUB_ENV | |
- run: echo Short hash = ${{ env.GITHUB_SHA_SHORT }} | |
- name: Show pending status check | |
uses: Sibz/[email protected] | |
with: | |
authToken: ${{ secrets.GITHUB_TOKEN }} | |
context: Netlify preview | |
sha: ${{ steps.source-run-info.outputs.sourceHeadSha }} | |
description: Deploying site to Netlify. Please wait... | |
state: pending | |
- name: 'Download artifact' | |
uses: actions/[email protected] | |
with: | |
script: | | |
var artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
console.log("Target artifact: " + "build-${{ steps.source-run-info.outputs.sourceHeadSha }}") | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
console.log("Found artifacts: " + artifact.name) | |
return artifact.name == "build-${{ steps.source-run-info.outputs.sourceHeadSha }}" | |
})[0]; | |
if (matchArtifact == undefined) { | |
core.setFailed('Artifact not found!'); | |
} | |
var download = await github.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/docs.zip', Buffer.from(download.data)); | |
- run: rm -rf docs | |
- run: unzip -d docs/ docs.zip | |
- run: echo Deploy Alias = ${{ env.GITHUB_SHA_SHORT }} | |
- uses: jsmrcaga/action-netlify-deploy@master | |
with: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
deploy_alias: ${{ env.GITHUB_SHA_SHORT }} | |
build_directory: docs/ | |
install_command: ls | |
build_command: ls | |
#- uses: geekyeggo/delete-artifact@v1 | |
# with: | |
# name: build-${{ github.event.workflow_run.head_branch }} | |
# Creates a status check with link to preview | |
- name: Status check | |
uses: Sibz/[email protected] | |
with: | |
authToken: ${{ secrets.GITHUB_TOKEN }} | |
context: Netlify preview | |
description: Click link to preview ⇒ | |
sha: ${{ steps.source-run-info.outputs.sourceHeadSha }} | |
state: success | |
target_url: https://${{ env.GITHUB_SHA_SHORT }}--scinim-getting-started.netlify.app |