Skip to content

Deploy PR preview

Deploy PR preview #56

# PR deployment splitted into two actions so that PRs of forks can be previewed as well
# This workflow will be started on each PR, but it will run on branch "main", so that
# it has the necessary rights to access repository secrets
name: Deploy PR preview
on:
workflow_run:
workflows: ["Build PR preview"]
types:
- completed
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: false
# Sets permissions of the GITHUB_TOKEN to allow writing a pull request comment
permissions:
pull-requests: write
jobs:
deploy-preview:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
# Download PR build artifact from last run
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{github.event.workflow_run.id }}
name: pr
skip_unpack: true
# Extract artifact, get PR number and store it in env
- name: Extract artifact and PR number
run: |
unzip pr.zip
echo "pr=$(cat ./NR)" >> $GITHUB_ENV
- name: Deploy preview
uses: peaceiris/actions-gh-pages@v3
with:
# Generate key with e.g. 'ssh-keygen -t ed25519 -C "OPA GH Actions Deploy Key" -f gh-pages'
# deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
personal_token: ${{ secrets.PR_DEPLOY_TOKEN }}
publish_dir: ./html
external_repository: OpenPodcastAPI/pr-previews
destination_dir: pr-${{ env.pr }}/
keep_files: true
# With inspiration from https://github.com/rossjrw/pr-preview-action
- name: Get Pages URL and datetime
run: |
org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
echo "org=$org" >> $GITHUB_ENV
echo "datetime=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
shell: bash
- name: Create PR comment
env:
preview-repo: 'pr-previews'
preview-branch: 'gh-pages'
preview-folder: 'pr-${{ env.pr }}'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
number: ${{ env.pr }}
message: |
| PR Preview |
| :---: |
| :rocket: Deployed preview to https://${{ env.org }}.github.io/${{ env.preview-repo }}/${{ env.preview-folder }} |
| on [`${{ env.preview-repo }}`](${{ github.server_url }}/${{ env.org }}/${{ env.preview-repo }}/tree/${{ env.preview-branch }}/pr-${{ env.pr }}) at ${{ env.datetime }} |