surge #249
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: surge | |
on: | |
workflow_run: | |
workflows: | |
- pullrequest | |
- pullrequest-close | |
types: | |
- completed | |
jobs: | |
surge: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./ | |
steps: | |
# Get the pull-request number | |
- name: download-pr | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr_number | |
- run: echo "PRNUM=$(cat pr_number)" >> $GITHUB_ENV | |
- run: echo "DOMAIN=random-cat-${{ env.PRNUM }}.surge.sh" >> $GITHUB_ENV | |
- run: echo "LOGIN=$(cat login)" >> $GITHUB_ENV | |
- run: echo "NAME=$(cat name)" >> $GITHUB_ENV | |
- run: echo "REPO=$(cat repo)" >> $GITHUB_ENV | |
- run: echo "HEAD_REF=$(cat head_ref)" >> $GITHUB_ENV | |
- uses: actions/[email protected] | |
with: | |
repository: ${{ env.REPO }} | |
ref: ${{ env.HEAD_REF }} | |
- uses: cachix/[email protected] | |
with: | |
nix_path: nixpkgs=channel:nixos-unstable | |
# Can't use pfhub sub domain here so need to change baseurl: | |
# 'pfhub' to baseurl: ''. jekyll build no longer takes a | |
# --baseurl arugment. | |
- if: ${{ env.NAME == 'pullrequest' }} | |
run: > | |
sed -i "2s/.*/baseurl: ''/" _config.yml | |
# Push to Surge | |
- env: | |
SURGE_LOGIN: "${{ secrets.SURGE_LOGIN }}" | |
SURGE_TOKEN: "${{ secrets.SURGE_TOKEN }}" | |
run: | | |
nix-shell shell-surge.nix --command " \ | |
if [[ ${{ env.NAME }} == 'pullrequest' ]]; then \ | |
rm -rf ./_site && \ | |
jekyll build && \ | |
surge --project _site --domain ${{ env.DOMAIN }}; \ | |
else \ | |
surge teardown ${{ env.DOMAIN }}; \ | |
fi \ | |
" | |
- run: | | |
if [[ ${{ env.NAME }} == 'pullrequest' ]]; then \ | |
echo "COMMENT=@${{ env.LOGIN }}, the new version of the PFHub website is available at https://${{ env.DOMAIN }}" >> $GITHUB_ENV; \ | |
else \ | |
echo "COMMENT=Successful teardown of ${{ env.DOMAIN }}" >> $GITHUB_ENV; \ | |
fi | |
# Comment back to the PR with link to Surge | |
- name: comment | |
uses: peter-evans/create-or-update-comment@v2 | |
with: | |
issue-number: ${{ env.PRNUM }} | |
token: ${{ secrets.PFHUB_UPLOAD_USER }} | |
body: ${{ env.COMMENT }} |