Bugfix #55
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: Replace paths in CSS files | |
run: | | |
sed -i 's|url(\.\./|url(/antora-assets/|g)' ./build/site/antora-assets/css/site.css | |
sed -i 's|url(\.\./|url(/antora-assets/|g)' ./build/site/antora-assets/css/site-extra.css | |
- 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" | |
find ./build/site/ -name "*.html" | while read -r file; do | |
# Use awk to insert the CSS content after the <head> tag | |
awk -v css="$COMBINED_CSS" '/<head>/ {print; print "<style>" css "</style>"; next} 1' "$file" > "$file".tmp && mv "$file".tmp "$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 |