www.byjp.me/.github/workflows/publish.yml
JP Hastings-Spital 65e8968a10 Else 🤦‍♂️
2023-11-12 08:23:25 +00:00

136 lines
3.9 KiB
YAML

name: Deploy Hugo site to Pages
on:
push:
branches: ["main"]
schedule:
# Rebuild at the first moment of the new year
# ensures that anywhere I'm using year-relative dates stay accurate.
- cron: '0 0 1 1 *'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.111.3
steps:
- name: Install Golang
uses: actions/setup-go@v4
with:
go-version: '1.21.1'
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup Pages
id: pages
uses: actions/configure-pages@v2
- name: Cache Hugo persistent info
uses: actions/cache@v3
env:
cache-name: hugo-persistent-cache
with:
path: /tmp/hugo
key: ${{ env.cache-name }}
- name: Build with Hugo
env:
# For maximum backward compatibility with Hugo modules
HUGO_ENVIRONMENT: production
HUGO_ENV: production
run: |
set -o allexport; source .env; set +o allexport
hugo \
--cacheDir /tmp/hugo/cache \
--minify \
--baseURL "https://www.byjp.me"
- name: Syndicate
env:
INSTAGRAM_PASSWORD: ${{ secrets.INSTAGRAM_PASSWORD }}
INSTAGRAM_TOTP: ${{ secrets.INSTAGRAM_TOTP }}
PIXELFED_ACCESS_TOKEN: ${{ secrets.PIXELFED_ACCESS_TOKEN }}
run: |
cd tools/syndicate
go mod download
go run .
if git diff-index --quiet HEAD; then
echo "No syndication changes made"
else
echo "Committing syndication changes"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "Syndicate[bot]"
git commit -am "Syndicated post references"
git push
# TODO: Do not upload, but without failing the build
exit 1
fi
- name: Build search index
run: |
# Build the search index
npm_config_yes=true npx pagefind@latest
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
name: site
path: ./public
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
with:
artifact_name: site
ipfs-publish:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v3
with:
name: site
path: ./public
- name: Extract Github Pages artifact
working-directory: ./public
run: tar -xf ./artifact.tar
- name: Publish to IPFS
id: Publish
uses: aquiladev/ipfs-action@master
with:
path: ./public
service: filebase
pinName: ${{ github.event.repository.name }}
filebaseBucket: microsites
filebaseKey: ${{ secrets.FILEBASE_KEY }}
filebaseSecret: ${{ secrets.FILEBASE_SECRET }}
- name: Update DNS record
uses: XueMoMo/actions-coudflare-dns@v1.0.1
with:
name: ${{ github.event.repository.name }}
cid: ${{ steps.Publish.outputs.cid }}
token: ${{ secrets.CLOUDFLARE_TOKEN }}
zone: ${{ secrets.CLOUDFLARE_ZONE_ID }}