2022-07-16 19:40:48 -04:00
|
|
|
name: Deploy to Firebase Hosting on PR
|
2022-07-19 07:47:08 -04:00
|
|
|
on:
|
|
|
|
workflow_run:
|
|
|
|
workflows: ["Build Hugo site on PR"]
|
|
|
|
types:
|
|
|
|
- completed
|
|
|
|
|
2022-07-16 19:40:48 -04:00
|
|
|
jobs:
|
2022-07-19 07:47:08 -04:00
|
|
|
Preview:
|
2022-07-16 19:40:48 -04:00
|
|
|
runs-on: ubuntu-latest
|
2022-07-19 07:47:08 -04:00
|
|
|
if: >
|
|
|
|
${{ github.event.workflow_run.event == 'pull_request' &&
|
|
|
|
github.event.workflow_run.conclusion == 'success' }}
|
2022-07-16 19:40:48 -04:00
|
|
|
steps:
|
2022-07-19 07:47:08 -04:00
|
|
|
- name: Download artifact
|
|
|
|
uses: actions/github-script@v3.1.0
|
2022-07-17 19:25:44 -04:00
|
|
|
with:
|
2022-07-19 07:47:08 -04:00
|
|
|
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) => {
|
2022-07-19 07:55:21 -04:00
|
|
|
return artifact.name == "hugo"
|
2022-07-19 07:47:08 -04:00
|
|
|
})[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');
|
2022-07-19 07:55:21 -04:00
|
|
|
fs.writeFileSync('${{github.workspace}}/hugo.zip', Buffer.from(download.data));
|
2022-07-17 19:25:44 -04:00
|
|
|
|
2022-07-19 07:47:08 -04:00
|
|
|
- name: Unzip artifact
|
2022-07-19 07:55:21 -04:00
|
|
|
run: unzip hugo.zip
|
|
|
|
|
|
|
|
- name: Remove artifact zip
|
|
|
|
run: rm hugo.zip
|
2022-07-17 19:25:44 -04:00
|
|
|
|
2022-07-21 02:23:47 -04:00
|
|
|
#Extracting and deployment workflow copied from https://github.com/gpuweb/gpuweb/blob/main/.github/workflows/preview-pull-request.yml
|
|
|
|
- name: Find PR
|
|
|
|
if: ${{ github.event.workflow_run.event == 'pull_request' }}
|
|
|
|
run: |
|
|
|
|
PR=$(curl https://api.github.com/search/issues?q=${{ github.event.workflow_run.head_sha }} |
|
|
|
|
grep -Po "(?<=${{ github.event.workflow_run.repository.full_name }}\/pulls\/)\d*" | head -1)
|
|
|
|
echo "PR=$PR" >> $GITHUB_ENV
|
|
|
|
|
2022-07-19 07:47:08 -04:00
|
|
|
- name: Deploy to Firebase
|
2022-07-17 20:03:35 -04:00
|
|
|
uses: FirebaseExtended/action-hosting-deploy@v0
|
2022-07-16 19:40:48 -04:00
|
|
|
with:
|
|
|
|
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
|
|
|
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PRIVSEC_356523 }}'
|
2022-07-21 02:06:00 -04:00
|
|
|
projectId: privsec-356523
|
2022-07-21 03:06:07 -04:00
|
|
|
channelId: pr${{ env.PR }}
|
2022-07-21 02:06:00 -04:00
|
|
|
expires: 30d
|