feat: setup zola to deploy website

master
Aravinth Manivannan 2022-03-09 10:41:50 +05:30
parent 53cb808083
commit 88e1bfc146
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
4 changed files with 152 additions and 5 deletions

View File

@ -44,8 +44,10 @@ jobs:
~/.cargo/registry
~/.cargo/git
target
key:
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Zola
run: ./scripts/ci.sh install
- name: Login to DockerHub
if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'realaravinth/gitpad'
@ -109,5 +111,9 @@ jobs:
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: target/doc
FOLDER: deploy-static
- name: deploy
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'realaravinth/realaravinth' }}
run: >-
curl --location --request POST "https://deploy.batsense.net/api/v1/update" --header 'Content-Type: application/json' --data-raw "{ \"secret\": \"${{ secrets.DEPLOY_TOKEN }}\", \"branch\": \"gh-pages\" }"

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ tarpaulin-report.html
**/tmp/
assets
src/cache_buster_data.json
deploy-static

View File

@ -1,3 +1,7 @@
STATIC_DIST = ./deploy-static
WEBSITE = website
WEBSITE_DIST = $(WEBSITE)/public
default: ## Debug build
cargo build
@ -6,6 +10,8 @@ clean: ## Clean all build artifacts and dependencies
@-/bin/rm -rf database/migrator/target/
@-/bin/rm -rf database/*/target/
@-/bin/rm -rf database/*/tmp/
@-/bin/rm -rf $(WEBSITE)
@-/bin/rm -rf $(STATIC_DIST)
@cargo clean
coverage: migrate ## Generate coverage report in HTML format
@ -15,7 +21,13 @@ dev-env: ## Download development dependencies
cargo fetch
doc: ## Prepare documentation
cargo doc --no-deps --workspace --all-features
@-/bin/rm -rf $(STATIC_DIST) || true
@cargo doc --no-deps --workspace --all-features
@-mkdir -p $(WEBSITE)/static/doc || true
cp -r target/doc $(WEBSITE)/static/doc
@./scripts/ci.sh build
mkdir -p $(STATIC_DIST)
cp -r $(WEBSITE_DIST)/* $(STATIC_DIST)
docker: ## Build docker images
docker build -t realaravinth/gitpad:master -t realaravinth/gitpad:latest .

128
scripts/ci.sh Executable file
View File

@ -0,0 +1,128 @@
#!/bin/bash
# Used in CI workflow: install Zola binary from GitHub
# Copyright © 2021 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -euo pipefail
readonly TARBALL=zola.tar.gz
readonly SOURCE="https://github.com/getzola/zola/releases/download/v0.15.3/zola-v0.15.3-x86_64-unknown-linux-gnu.tar.gz"
readonly BIN_PATH=bin
readonly BIN=$BIN_PATH/zola
readonly DIST=public
readonly WEBSITE=website
cd $WEBSITE
help() {
cat << EOF
ci.sh: CI build script
USAGE:
ci.sh <options>
OPTIONS:
b build build website
c clean clean dependencies and build artifacts
h help print this help menu
i install install build dependencies
u url make urls relative
z zola invoke zola
EOF
}
check_arg(){
if [ -z $1 ]
then
help
exit 1
fi
}
match_arg() {
if [ $1 == $2 ] || [ $1 == $3 ]
then
return 0
else
return 1
fi
}
download() {
echo "Downloading Zola"
wget --quiet --output-document=$TARBALL $SOURCE
tar -xvzf $TARBALL > /dev/null
rm $TARBALL
echo "Downloaded zola into $BIN"
}
init() {
if [ ! -d $BIN_PATH ]
then
mkdir $BIN_PATH
fi
if [ ! -f $BIN ]
then
cd $BIN_PATH
download
fi
}
run() {
$BIN "${@:1}"
}
build() {
run build
}
no_absolute_url() {
sed -i 's/https:\/\/batsense.net//g' $(find public -type f | grep html)
}
clean() {
rm -rf $BIN_PATH || true
rm -rf $DIST || true
echo "Workspace cleaned"
}
check_arg $1
if match_arg $1 'i' 'install'
then
init
elif match_arg $1 'c' 'clean'
then
clean
elif match_arg $1 'b' 'build'
then
build
elif match_arg $1 'h' 'help'
then
help
elif match_arg $1 'u' 'url'
then
no_absolute_url
elif match_arg $1 'z' 'zola'
then
$BIN "${@:3}"
else
echo "Error: $1 is not an option"
help
exit 1
fi
exit 0