name: Deploy to Firebase Hosting on PR on: workflow_run: workflows: ["Build Hugo site on PR"] types: - completed jobs: Preview: runs-on: ubuntu-latest if: > ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} steps: - name: Download artifact uses: actions/github-script@v3.1.0 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 == "hugo" })[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}}/hugo.zip', Buffer.from(download.data)); - name: Unzip artifact run: unzip hugo.zip - name: Remove artifact zip run: rm hugo.zip #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 - name: Deploy to Firebase uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: '${{ secrets.GITHUB_TOKEN }}' firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PRIVSEC_356523 }}' projectId: privsec-356523 channelId: prs-${{ env.PR }}-${{ github.event.workflow_run.head_sha }} expires: 30d