# .github/workflows/build.yml # Build + commit generated site # Important to be able to push back to the repository you need to configure: Settings → Actions → General → Workflow permissions to "Read and write permissions" name: Build # ------------------------------------------------- # Default: staging FTP configuration # ------------------------------------------------- env: HOST: https://staging.vmac.ch TZ: Europe/Paris FTP_HOST: ${{ vars.FTP_HOST_STAGING }} FTP_USER: ${{ vars.FTP_USER_STAGING }} FTP_PASS: ${{ secrets.FTP_PASS_STAGING }} FTP_BASE_PATH: ${{ vars.FTP_BASE_PATH_STAGING }} on: push: branches: [ main ] pull_request: branches: [ main ] concurrency: group: ${{ github.ref }} cancel-in-progress: true jobs: build: runs-on: ubuntu-latest steps: # ------------------------------------------------- # Production override # ------------------------------------------------- - name: Override Env Variables for production if: github.ref == 'refs/heads/main' run: | echo "HOST=https://vmac.ch" >> $GITHUB_ENV echo "FTP_HOST=${{ vars.FTP_HOST_PROD }}" >> $GITHUB_ENV echo "FTP_USER=${{ vars.FTP_USER_PROD }}" >> $GITHUB_ENV echo "FTP_PASS=${{ secrets.FTP_PASS_PROD }}" >> $GITHUB_ENV echo "FTP_BASE_PATH=${{ vars.FTP_BASE_PATH_PROD }}" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v6 with: submodules: true fetch-depth: 0 # ------------------------------------------------- # Update archive tress # ------------------------------------------------- - name: Update archive tree run: | ./scripts/update-archive-dirs.sh # ------------------------------------------------- # Detect files that will change # ------------------------------------------------- - name: Detect files to upload run: | ./scripts/detect-changed-public.sh --debug > changed_files.txt echo "Files detected:" cat changed_files.txt - name: Setup Hugo uses: peaceiris/actions-hugo@v2 with: hugo-version: '0.121.1' extended: true - name: Build run: hugo --minify --baseURL ${HOST} # ------------------------------------------------- # Commit generated site # ------------------------------------------------- - name: Commit and publish public directory if: github.event_name == 'push' run: | git config --global user.name "Github Action" git config --global user.email "v@vmac.ch" git add public .hugo-extra-output-manifest content/archive git commit -m "Build site ($(date -u +'%Y-%m-%d %H:%M:%S UTC'))" || echo "Nothing to commit" git push - name: Build lftp script run: | echo "open -u \"$FTP_USER\",\"$FTP_PASS\" \"$FTP_HOST\"" > lftp.txt echo "set ftp:ssl-force true" >> lftp.txt echo "set ftp:ssl-auth TLS" >> lftp.txt echo "set ftp:ssl-protect-data true" >> lftp.txt echo "set ftp:ssl-protect-list true" >> lftp.txt echo "set ssl:verify-certificate true" >> lftp.txt echo "set net:max-retries 3" >> lftp.txt echo "set net:timeout 20" >> lftp.txt echo "set cmd:trace true" >> lftp.txt while IFS= read -r file; do dir=$(dirname "$file") echo "mkdir -p \"$FTP_BASE_PATH/$dir\"" >> lftp.txt echo "put \"public/$file\" -o \"$FTP_BASE_PATH/$file\"" >> lftp.txt done < changed_files.txt echo "quit" >> lftp.txt echo "===== DEBUG: lftp script (sanitized) =====" sed "s/${FTP_PASS}/****/g" lftp.txt echo "===== END DEBUG =====" - name: Upload via FTP uses: glazrtom/ftp-action@v3.0.0 with: host: ${{ secrets.FTP_HOST }} user: ${{ secrets.FTP_USER }} password: ${{ secrets.FTP_PASS }} command: "source lftp.txt" options: "" localDir: "" remoteDir: "" - name: Ping micro.blog run: curl -sS https://micro.blog/ping -d url=${HOST}/feed.json