Skip to content

Upload preview to OVH Object Storage #2980

Upload preview to OVH Object Storage

Upload preview to OVH Object Storage #2980

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@v2
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@v3
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 }})).