netlify_deploy_preview #287
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
# runs when netlify_build_docs is completed | |
# reason for the split: we do not want to run user code in an environment that has access to netlify secrets | |
name: netlify_deploy_preview | |
on: | |
workflow_run: | |
workflows: | |
- netlify_build_docs | |
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/github-status-action@v1.1.5 | |
with: | |
authToken: ${{ secrets.GITHUB_TOKEN }} | |
context: Netlify preview | |
sha: ${{ steps.source-run-info.outputs.sourceHeadSha }} | |
description: Deploying site to Netlify. Please wait... | |
state: pending | |
- run: rm -rf docs | |
# - name: 'Download artifacts' | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: "build-${{ steps.source-run-info.outputs.sourceHeadSha }}" | |
# path: docs/ | |
- name: 'Download artifacts' | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
github_token: ${{secrets.GITHUB_TOKEN}} | |
workflow: netlify_build_docs.yml # Name of the workflow that created the artifact | |
name: "build-${{ steps.source-run-info.outputs.sourceHeadSha }}" # Name of the artifact | |
path: docs/ # Optional path to extract to | |
# - name: 'Download artifact' | |
# uses: actions/github-script@v3.1.0 | |
# 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: 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 | |
- name: Status check | |
uses: Sibz/github-status-action@v1.1.5 | |
with: | |
authToken: ${{ secrets.GITHUB_TOKEN }} | |
context: Netlify preview | |
description: Click link to preview β | |
sha: ${{ steps.source-run-info.outputs.sourceHeadSha }} | |
state: success | |
# customize with netlify site name | |
target_url: https://${{ env.GITHUB_SHA_SHORT }}--nimib.netlify.app |