Skip to content

Merge pull request #24 from SharmaRithik/main #337

Merge pull request #24 from SharmaRithik/main

Merge pull request #24 from SharmaRithik/main #337

Workflow file for this run

# 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