Upload temporary docs to GCP #2549
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: Upload temporary docs to GCP | |
on: | |
workflow_run: | |
workflows: ["Continuous Integration"] | |
types: | |
- completed | |
jobs: | |
docs-upload-to-gcp-preview: | |
timeout-minutes: 5 | |
runs-on: ubuntu-latest | |
if: > | |
${{ github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- run: sudo apt update -y && sudo apt install -y unzip | |
- run: mkdir docs | |
- id: download-artifact | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
console.log(github.event); | |
var { data } = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = data.artifacts.filter((artifact) => { | |
return artifact.name.startsWith("docs-pr-") | |
})[0]; | |
var download = await github.rest.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)); | |
return matchArtifact.name.split("-")[2] | |
- run: unzip docs.zip -d docs | |
- name: Setup Google Auth 🔧 | |
uses: "google-github-actions/auth@v1" | |
with: | |
credentials_json: "${{ secrets.GCP_DOCS_CREDENTIAL_JSON }}" | |
- name: Deploy 🚀 | |
uses: google-github-actions/upload-cloud-storage@v1.0.3 | |
with: | |
path: docs | |
destination: mergify-docs-preview/${{steps.download-artifact.outputs.result}} | |
- uses: actions/github-script@v6 | |
if: always() | |
with: | |
script: | | |
var target_url = ""; | |
var state = "error"; | |
if ("${{ job.status }}" === "success") { | |
var pr = "${{ steps.download-artifact.outputs.result }}"; | |
target_url = `https://docs-preview.mergify.com/${pr}/docs`, | |
state = "success"; | |
} else { | |
const { data } = await github.rest.actions.listJobsForWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.runId | |
}); | |
target_url = data.jobs[0].html_url ; | |
state = "failure"; | |
} | |
var resp = await github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: "${{ github.event.workflow_run.head_sha }}", | |
context: "Documentation Preview", | |
state: state, | |
target_url: target_url | |
}); | |
console.log(resp) |