-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (60 loc) · 2.13 KB
/
wf-deploy-pr.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
name: Pull Request Build and Deploy
on:
pull_request:
branches: [ main, integration ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
pr_number:
description: Number of the Pull Request
required: true
# Environment variables
env:
DEPLOY_REPO_NAME: zhaostephen.com-2021-static-pr${{ github.event.pull_request.number || github.event.inputs.pr_number }}
PR_MERGE_BRANCH: refs/pull/${{ github.event.pull_request.number || github.event.inputs.pr_number }}/merge
jobs:
create-page-host:
runs-on: ubuntu-latest
steps:
- name: Create new repository for temporary deployment
uses: octobay/create-repository-action@v1
with:
name: ${{ env.DEPLOY_REPO_NAME }}
org: zhaostephencom-ghp
access-token: ${{ secrets.PAT }}
pr-build-deploy:
needs: create-page-host
runs-on: ubuntu-latest
environment:
name: pr-staging
url: https://zhaostephencom-ghp.github.io/${{ env.DEPLOY_REPO_NAME }}/
steps:
# https://github.com/actions/checkout#push-a-commit-using-the-built-in-token
- name: Set GitHub Actions as Commit Author
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
- name: Checkout PR repository
uses: actions/checkout@v2
with:
path: 'pr-build'
ref: ${{ env.PR_MERGE_BRANCH }}
- name: Checkout deployment repository
uses: actions/checkout@v2
with:
repository: zhaostephencom-ghp/${{ env.DEPLOY_REPO_NAME }}
path: 'pr-deploy'
token: ${{ secrets.PAT }}
- name: Deploy to deployment repository
run: |
cp -r pr-build/* pr-deploy/
cd pr-deploy
touch .nojekyll
git add .
git commit -m $GITHUB_SHA
# Archive to commit-specific branch
git checkout -b commit/$GITHUB_SHA
git push -u origin commit/$GITHUB_SHA
# Publish to gh-pages branch
git checkout -b gh-pages
git push -uf origin gh-pages