-
Notifications
You must be signed in to change notification settings - Fork 57
100 lines (87 loc) · 3.87 KB
/
upload-preview.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Upload preview to OVH Object Storage
on:
workflow_run:
workflows: ["Preview docs.sekoia.io"]
types:
- completed
jobs:
upload:
name: Upload preview to OVH Object Storage
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/[email protected]
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "site.tar.gz"
})[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}}/site.tar.gz.zip', Buffer.from(download.data));
- run: |
unzip site.tar.gz.zip
mkdir site
tar zxvf site.tar.gz -C ./site
- name: Get PR number
id: pr_number
run: echo "pr_number=$(cat site/.pr_number)" >> $GITHUB_OUTPUT
- name: Fix URLs and relative links
run: |
shopt -s globstar
sed -i 's,src="/assets/,src="/v1/AUTH_741841e1c7da4c50a76152cbc2609bd1/sekoiaio-documentation-previews/${{ steps.pr_number.outputs.pr_number }}/assets/,' site/**/*.html
- name: Install Swift
run: |
pip install python-swiftclient==4.3.0 python-keystoneclient==5.1.0
- name: Delete any previous preview
run: |
swift delete sekoiaio-documentation-previews -p ${{ steps.pr_number.outputs.pr_number }} --object-threads 5
env:
OS_AUTH_URL: "https://auth.cloud.ovh.net/v3/"
OS_IDENTITY_API_VERSION: 3
OS_TENANT_ID: ${{ secrets.PR_OS_TENANT_ID }}
OS_TENANT_NAME: ${{ secrets.PR_OS_TENANT_NAME }}
OS_USERNAME: ${{ secrets.PR_OS_USERNAME }}
OS_PASSWORD: ${{ secrets.PR_OS_PASSWORD }}
OS_REGION_NAME: "GRA"
- name: OVH Object Storage
run: |
swift upload sekoiaio-documentation-previews site --object-name ${{ steps.pr_number.outputs.pr_number }} --object-threads 5
env:
OS_AUTH_URL: "https://auth.cloud.ovh.net/v3/"
OS_IDENTITY_API_VERSION: 3
OS_TENANT_ID: ${{ secrets.PR_OS_TENANT_ID }}
OS_TENANT_NAME: ${{ secrets.PR_OS_TENANT_NAME }}
OS_USERNAME: ${{ secrets.PR_OS_USERNAME }}
OS_PASSWORD: ${{ secrets.PR_OS_PASSWORD }}
OS_REGION_NAME: "GRA"
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ steps.pr_number.outputs.pr_number }}
comment-author: github-actions[bot]
body-includes: Newest code from ${{ github.actor}} has been published to
- name: Get current date
id: date
run: echo "date=$(date +'%F %H:%M:%S')" >> $GITHUB_OUTPUT
- name: Add comment to PR
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.pr_number.outputs.pr_number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
Newest code from ${{ github.actor}} has been published to [preview environment](https://storage.gra.cloud.ovh.net/v1/AUTH_741841e1c7da4c50a76152cbc2609bd1/sekoiaio-documentation-previews/${{ steps.pr_number.outputs.pr_number }}/)
:rocket: Latest deployment was built on ${{ steps.date.outputs.date }} ([${{ github.sha }}](https://github.com/SEKOIA-IO/documentation/commit/${{ github.sha }})).