-
Notifications
You must be signed in to change notification settings - Fork 9
105 lines (92 loc) · 3.8 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
fetch-depth: 0
# Must checkout the theme submodule or site-generation will fail
submodules: recursive
- uses: actions/cache@v2
id: cache
with:
key: hugo-binary-101
path: hugo
- name: Download hugo
if: steps.cache.outputs.cache-hit != 'true'
run: |
set -e -u -o pipefail
set -x
wget https://github.com/gohugoio/hugo/releases/download/v0.49.2/hugo_0.49.2_Linux-64bit.tar.gz -O - | tar --get -xvzf - hugo
./hugo version
- name: Generate site
run: |
set -e -u -o pipefail
set -x
./hugo --cleanDestinationDir --gc --destination ../docs/ # generate site outside of the repo
mv hugo .. # move hugo out of the dir so it doesn't get published with the site
- name: Publish site
if: github.base_ref == '' # only push the rebuilt dir when actually merging to the main branch
run: |
set -e -u -o pipefail
set -x
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
MESSAGE="$(git log -1 --pretty='%B')" # get the commit message before switching to the pubilc branch
git checkout public || git checkout -b public # checkout or create public branch
git rm -rfq $(git ls-files) # remove all the code
ls -lah # expect no files to be listed
mv ../docs/* . # copy the generated site in from outside the repo
git add -A
git commit -m "regenerate after: $MESSAGE" --allow-empty
git push -u origin public -f
- name: Restore hugo for caching
run: |
set -e -u -o pipefail
set -x
mv ../hugo .
# This workflow contains a job called "deploy"
rsync:
# only rsync when actually merging to the main branch
if: github.base_ref == ''
# only rsync after the site is bulit
needs: build
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
# checkout the public branch to rsync it to the prod server
ref: public
fetch-depth: 0
- name: Rsync to UCSC ITS site
env:
KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS }}
REMOTE_DIR: ${{ secrets.ITS_DIR }}
REMOTE_HOST: ${{ secrets.ITS_HOST }}
REMOTE_PWD: ${{ secrets.ITS_PWD }}
REMOTE_USR: ${{ secrets.ITS_USER }}
run: |
set -e -u -o pipefail +o history
set -x
mkdir ~/.ssh
echo "${KNOWN_HOSTS?}" >> ~/.ssh/known_hosts
sudo apt-get install sshpass
sshpass -p "${REMOTE_PWD?}" rsync -Pzca --exclude=".*" --delete-after . "${REMOTE_USR?}@${REMOTE_HOST?}:${REMOTE_DIR?}"
history -c