name: Publish
on:
push:
branches: [master]
paths:
- '**.md'
- 'publish.toml'
- '_redirects'
- '.github/workflows/publish.yml'
workflow_dispatch:
concurrency:
group: publish
cancel-in-progress: true
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Clone cyber
run: |
mkdir -p "$HOME/cyber"
git clone --depth 1 https://github.com/cyberia-to/cyber.git "$HOME/cyber/cyber"
- name: Install Rust
run: |
rustup update stable
rustup default stable
- name: Cache optica build
uses: actions/cache@v4
with:
path: |
/tmp/optica-target-cache
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-optica-v4
- name: Build optica
run: |
rm -rf "$HOME/cyber/optica"
git clone --depth 1 https://github.com/cyberia-to/optica.git "$HOME/cyber/optica"
if [ -d /tmp/optica-target-cache ]; then
mv /tmp/optica-target-cache "$HOME/cyber/optica/target"
fi
cd "$HOME/cyber/optica" && cargo build --release
cp -r "$HOME/cyber/optica/target" /tmp/optica-target-cache
- name: Build site
run: |
"$HOME/cyber/optica/target/release/optica" build "$HOME/cyber/cyber" \
--output "$HOME/cyber/cyber/build"
cp "$HOME/cyber/cyber/_redirects" "$HOME/cyber/cyber/build/_redirects"
touch "$HOME/cyber/cyber/build/.nojekyll"
- name: Deploy to Netlify
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
cd "$HOME/cyber/cyber/build"
zip -r -q /tmp/site.zip .
deploy_id=$(curl -sf -X POST \
-H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary "@/tmp/site.zip" \
"https://api.netlify.com/api/v1/sites/$NETLIFY_SITE_ID/deploys" | jq -r .id)
test -n "$deploy_id" && test "$deploy_id" != null
echo "deploy $deploy_id"
for i in $(seq 1 90); do
state=$(curl -s -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
"https://api.netlify.com/api/v1/deploys/$deploy_id" | jq -r .state)
echo "state: $state"
case "$state" in
ready) exit 0;;
error) exit 1;;
esac
sleep 10
done
echo "timeout waiting for netlify processing"; exit 1
- name: Dispatch cyberia-blog rebuild
continue-on-error: true
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.CYBER_DISPATCH_TOKEN }}
repository: cyberia-to/cyberia-blog
event-type: content-changed