name: Build and Publish Slides on: push: branches: - master workflow_dispatch: permissions: contents: read jobs: build-and-publish: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "22" - name: Install Google Chrome run: | sudo apt-get update sudo apt-get install -y wget wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ -O /tmp/google-chrome.deb sudo apt-get install -y /tmp/google-chrome.deb - name: Build PDF and HTML env: CHROME_PATH: /usr/bin/google-chrome run: | mkdir -p dist npx --yes @marp-team/marp-cli@latest \ --pdf --allow-local-files slides.md \ -o dist/slides.pdf npx --yes @marp-team/marp-cli@latest \ --html --allow-local-files slides.md \ -o dist/slides.html - name: Create or get Gitea release id: release env: BASE_URL: ${{ secrets.TARGET_BASE_URL }} OWNER: ${{ secrets.TARGET_OWNER }} REPO: ${{ secrets.TARGET_REPO }} TOKEN: ${{ secrets.TARGET_TOKEN }} TAG: ${{ github.ref_name }} run: | set -euo pipefail API="${BASE_URL%/}/api/v1/repos/${OWNER}/${REPO}" AUTH=(-H "Authorization: token $TOKEN") # Check for existing release HTTP_CODE=$(curl -sS \ "${AUTH[@]}" \ -o /tmp/release.json \ -w "%{http_code}" \ "$API/releases/tags/$TAG") if [ "$HTTP_CODE" = "200" ]; then RELEASE_ID=$(jq -r '.id' /tmp/release.json) echo "Using existing release: $RELEASE_ID" elif [ "$HTTP_CODE" = "404" ]; then echo "Creating release..." curl --fail-with-body --silent --show-error \ -X POST "$API/releases" \ "${AUTH[@]}" \ -H "Content-Type: application/json" \ -d "$(jq -n \ --arg tag "$TAG" \ --arg name "Slides $TAG" \ '{tag_name:$tag,name:$name,draft:false}')" \ -o /tmp/release.json RELEASE_ID=$(jq -r '.id' /tmp/release.json) else echo "Failed to check release (HTTP $HTTP_CODE)" cat /tmp/release.json exit 1 fi if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then echo "Could not obtain release ID" exit 1 fi echo "release_id=$RELEASE_ID" >> "$GITHUB_OUTPUT" - name: Upload slides to Gitea release env: BASE_URL: ${{ secrets.TARGET_BASE_URL }} OWNER: ${{ secrets.TARGET_OWNER }} REPO: ${{ secrets.TARGET_REPO }} TOKEN: ${{ secrets.TARGET_TOKEN }} RELEASE_ID: ${{ steps.release.outputs.release_id }} run: | set -euo pipefail API="${BASE_URL%/}/api/v1/repos/${OWNER}/${REPO}" AUTH=(-H "Authorization: token $TOKEN") # Get existing release assets curl --fail-with-body --silent --show-error \ "${AUTH[@]}" \ "$API/releases/$RELEASE_ID/assets" \ -o /tmp/assets.json for file in dist/*; do NAME=$(basename "$file") # Remove old asset if it exists ASSET_ID=$(jq -r \ --arg name "$NAME" \ '.[] | select(.name == $name) | .id' \ /tmp/assets.json | head -n 1) if [ -n "$ASSET_ID" ]; then echo "Deleting old asset: $NAME" curl --fail-with-body --silent --show-error \ -X DELETE \ "${AUTH[@]}" \ "$API/releases/$RELEASE_ID/assets/$ASSET_ID" fi # Upload new asset echo "Uploading $NAME..." curl --fail-with-body --silent --show-error \ -X POST \ "$API/releases/$RELEASE_ID/assets?name=$NAME" \ "${AUTH[@]}" \ -H "Content-Type: application/octet-stream" \ --data-binary "@$file" echo "Uploaded $NAME" done - name: Summary run: | echo "## Slides published successfully" >> "$GITHUB_STEP_SUMMARY" echo "- PDF: slides.pdf" >> "$GITHUB_STEP_SUMMARY" echo "- HTML: slides.html" >> "$GITHUB_STEP_SUMMARY" echo "- Tag: ${{ github.ref_name }}" >> "$GITHUB_STEP_SUMMARY"