-
Notifications
You must be signed in to change notification settings - Fork 11
81 lines (77 loc) · 2.89 KB
/
docs-upload-gcp-temp.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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)