-
Notifications
You must be signed in to change notification settings - Fork 28
63 lines (54 loc) · 1.84 KB
/
deploy-preview.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
name: Deploy Web Previews
on:
workflow_dispatch:
push:
branches:
- preview-**
workflow_call:
inputs:
branch:
required: true
type: string
jobs:
Deploy-Web-Preview:
if: ${{ github.repository_owner == 'path-cc' }}
runs-on: ubuntu-latest
env:
preview_url: https://github.com/path-cc/web-preview.git
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
ref: ${{ inputs.branch }}
- name: Get branch name
run: echo "BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
bundler-cache: true
- name: Configure for Dev Preview
run: |
rm CNAME -f
sed -i "s|baseurl: ''|baseurl: '/web-preview/${{ env.BRANCH_NAME }}'|" _config.yml
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git commit -am "GHA: path-cc/path-cc.github.io #$GITHUB_RUN_NUMBER"
- name: Setup SSH Keys and known_hosts
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.WEB_PREVIEW_DEPLOY_KEY }}
- name: Build and Deploy
run: |
git checkout -b temp-branch
bundle exec jekyll build
mkdir temp-dir
mv _site ${{ env.BRANCH_NAME }}
mv ${{ env.BRANCH_NAME }} temp-dir
git add temp-dir
git commit -m "Build Branch Website"
SPLIT_BRANCH=$(git subtree split --prefix temp-dir temp-branch)
git remote add web-preview ${{ env.preview_url }}
git fetch --all
git checkout -b preview web-preview/main
git merge $SPLIT_BRANCH -m "Merge Split Branch" --allow-unrelated-histories -X theirs
git push web-preview HEAD:main