Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/pr-preview-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PR Preview Build
on: pull_request

jobs:
build-pr-preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install trunk
run: |
curl -sL https://github.com/thedodd/trunk/releases/download/v0.16.0/trunk-x86_64-unknown-linux-gnu.tar.gz -o trunk-x86_64-unknown-linux-gnu.tar.gz
tar xzf trunk-x86_64-unknown-linux-gnu.tar.gz
sudo install trunk /usr/bin/trunk
- uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install NPM dependencies
working-directory: spog/ui
run: npm install

- name: Set build timestamp
run: echo "BUILD_TIMESTAMP=$(date --rfc-3339=seconds --utc)" >> $GITHUB_ENV
- name: Build page
env:
BUILD_COMMIT: ${{ github.sha }}
working-directory: spog/ui
run: |
rustup target add wasm32-unknown-unknown
trunk build --public-url /
cat << EOF > dist/endpoints/backend.json
{
"url": "https://api.trustification.dev",
"vexination": "https://api.trustification.dev",
"bombastic": "https://api.trustification.dev"
}
EOF

- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR

- uses: actions/upload-artifact@v3
with:
name: dist
path: spog/ui/dist/
- uses: actions/upload-artifact@v3
with:
name: pr
path: pr/
88 changes: 88 additions & 0 deletions .github/workflows/pr-preview-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: PR Preview Deploy
on:
workflow_run:
workflows: ["PR Preview Build"]
types:
- completed

jobs:
deploy-pr-preview:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download dist
uses: actions/github-script@v3
with:
script: |
var artifacts = await github.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 == "dist"
})[0];
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}}/dist.zip', Buffer.from(download.data));
- name: Download PR number
uses: actions/github-script@v3
with:
script: |
var artifacts = await github.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 == "pr"
})[0];
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}}/pr.zip', Buffer.from(download.data));

- run: unzip dist.zip -d dist/
- run: unzip pr.zip

- name: Generate issue_number
uses: actions/github-script@v3
id: issue_number
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
return Number(fs.readFileSync('./NR'));
result-encoding: string

- name: Generate Surge URL
uses: actions/github-script@v3
id: surge-url
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = ${{steps.issue_number.outputs.result}};
return `trustification-pr-${issue_number}-preview.surge.sh`;
result-encoding: string
- name: Install Surge
run: npm install -g surge
- name: Deploy to Surge
run: surge ./dist/ "${{steps.surge-url.outputs.result}}" --token ${{ secrets.SURGE_TOKEN }}

- name: Post URL as PR comment
uses: mshick/add-pr-comment@v2
with:
message: "🚀 Deployed Preview: http://${{steps.surge-url.outputs.result}} ✨"
repo-token: ${{ secrets.BOT_TOKEN }}
issue: ${{steps.issue_number.outputs.result}}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Trustification

[![CI](https://github.com/trustification/trustification/workflows/CI/badge.svg)](https://github.com/trustification/trustification/actions?query=workflow%3A%22CI%22)
Expand Down