-
Notifications
You must be signed in to change notification settings - Fork 42
77 lines (68 loc) · 2.35 KB
/
surge.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
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 }}