name: Hugo Publish CI on: push: branches: - master workflow_dispatch: jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Add SSH Key run: | echo "${{ secrets.SSH_KEY }}" > $HOME/.ssh/id_rsa chmod 600 $HOME/.ssh/id_rsa ssh-keyscan -H git.ericxliu.me >> $HOME/.ssh/known_hosts - name: Checkout code uses: actions/checkout@v4 with: ssh-key: ${{ secrets.SSH_KEY }} persist-credentials: false submodules: true # Fetch Hugo themes (true OR recursive) fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod - name: Fix nested quotes in post titles run: | # Find markdown files with titles containing at least 3 double quotes (indicating nesting) # and replace internal double quotes with single quotes. find content -type f -name "*.md" -print0 | \ xargs -0 grep -lZ '^title: .*".*".*"' | \ xargs -0 -r sed -i "/^title: \"/{s/\"/\\\\\"/g;s/^\(title: *\)\\\\\"/\1\"/;s/\\\\\" *$/\"/;}" - name: Build site with Hugo uses: peaceiris/actions-hugo@v3 with: hugo-version: "latest" extended: true - name: Build run: hugo --minify - name: Replace [commit] with short commit hash and hyperlink run: | SHORT_COMMIT=$(git rev-parse --short HEAD) COMMIT_URL="https://git.ericxliu.me/eric/ericxliu-me/commit/$SHORT_COMMIT" find ./public -type f -exec sed -i "s|\[commit\]|\[$SHORT_COMMIT\]|g" {} + - name: Publish uses: peaceiris/actions-gh-pages@v4 with: personal_token: ${{ secrets.GIT_PAGES_TOKEN }} publish_dir: ./public publish_branch: gitea-pages - name: Deploy run: | K8S_TOKEN="${{secrets.K8S_TOKEN}}" echo "K8S_TOKEN length: $(echo "$K8S_TOKEN" | wc -c)" echo "K8S_TOKEN starts with: $(echo "$K8S_TOKEN" | head -c 20)..." curl -X DELETE "https://10.10.0.10:6443/api/v1/namespaces/hugo/pods?labelSelector=app.kubernetes.io/name=hugo" \ --header "Authorization: Bearer $K8S_TOKEN" \ --insecure --fail-with-body --show-error --verbose