Bugfix #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Antora Site | |
on: | |
push: | |
branches: | |
- main # adjust this if your primary branch is named differently | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install rsync, zopfli and brotli | |
run: sudo apt-get install -y rsync brotli zopfli | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' # Antora is known to work well with this version, but you can adjust as needed | |
- name: Install Antora | |
run: | | |
npm install -g antora | |
- name: Build the Antora site | |
run: | | |
antora --fetch antora-playbook.yml # Replace 'antora-playbook.yml' with your playbook's name if different | |
- name: Inline CSS and remove original link tags | |
run: | | |
SITE_CSS=$(cat ./build/site/antora-assets/css/site.css) | |
SITE_EXTRA_CSS=$(cat ./build/site/antora-assets/css/site-extra.css) | |
COMBINED_CSS="$SITE_CSS $SITE_EXTRA_CSS" | |
# Use a placeholder for the CSS | |
PLACEHOLDER="CSS_PLACEHOLDER" | |
find ./build/site/ -name "*.html" | while read -r file; do | |
# Insert the placeholder after the <head> tag | |
sed -i "s|<head>|<head><style>$PLACEHOLDER</style>|" "$file" | |
# Replace the placeholder with the actual CSS content | |
sed -i "s|$PLACEHOLDER|$COMBINED_CSS|" "$file" | |
# Remove the original link tags | |
sed -i "/antora-assets\/css\/site.css/d" "$file" | |
sed -i "/antora-assets\/css\/site-extra.css/d" "$file" | |
done | |
- name: Zopfli compress all HTML and CSS files | |
run: | | |
find ./build/site/ \( -name "*.html" -o -name "*.css" \) -exec zopfli {} \; | |
- name: Brotli compress all HTML and CSS files | |
run: | | |
find ./build/site/ \( -name "*.html" -o -name "*.css" \) -exec brotli {} \; | |
- name: Deploy to Linux server via SCP | |
env: | |
DEPLOY_KEY: ${{ secrets.DEPLOY_SSH_KEY }} | |
SERVER: ${{ secrets.SERVER_ADDRESS }} | |
USERNAME: ${{ secrets.SERVER_USERNAME }} | |
TARGET: ${{ secrets.SERVER_TARGET_DIRECTORY }} | |
KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS_ENTRY }} | |
run: | | |
echo "$DEPLOY_KEY" > deploy_key | |
chmod 600 deploy_key | |
echo "$KNOWN_HOSTS" > known_hosts | |
rsync -avz -e 'ssh -i deploy_key -o UserKnownHostsFile=known_hosts' --delete ./build/site/ $USERNAME@$SERVER:$TARGET | |
rm -f deploy_key known_hosts |