From 4cff107a67cae9d83ee3f8b6e97308593ee9e9b0 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <8075870+adityachandelgit@users.noreply.github.com> Date: Fri, 29 Aug 2025 16:26:42 -0600 Subject: [PATCH] Add scripts and update drafter flow --- .github/workflows/docker-build-publish.yml | 19 +++--- scripts/docker-buildx-push.sh | 29 +++++++++ scripts/notify-discord.sh | 73 ++++++++++++++++++++++ 3 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 scripts/docker-buildx-push.sh create mode 100644 scripts/notify-discord.sh diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml index bfe4ba25..e804fd5b 100644 --- a/.github/workflows/docker-build-publish.yml +++ b/.github/workflows/docker-build-publish.yml @@ -181,23 +181,24 @@ jobs: --tag ghcr.io/booklore-app/booklore:latest \ --push . - - name: Create Git Tag (Only for Master) + - name: Update Release Draft (Only for Master) if: github.ref == 'refs/heads/master' - run: | - git config --global user.name "github-actions" - git config --global user.email "github-actions@github.com" - git tag ${{ env.new_tag }} - git push origin ${{ env.new_tag }} + uses: release-drafter/release-drafter@v6 + with: + tag: ${{ env.new_tag }} + name: "Release ${{ env.new_tag }}" + env: + GITHUB_TOKEN: ${{ github.token }} - name: Publish Draft Release (Only for Master) if: github.ref == 'refs/heads/master' env: - GH_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ github.token }} run: | gh release edit ${{ env.new_tag }} --draft=false - name: Notify Discord of New Release - if: github.ref == 'refs/heads/master' + if: false continue-on-error: true shell: bash env: @@ -232,4 +233,4 @@ jobs: color: 3066993 }] }') - curl -H "Content-Type: application/json" -d "$payload" "$DISCORD_WEBHOOK_URL" \ No newline at end of file + curl -H "Content-Type: application/json" -d "$payload" "$DISCORD_WEBHOOK_URL" diff --git a/scripts/docker-buildx-push.sh b/scripts/docker-buildx-push.sh new file mode 100644 index 00000000..f757f8f8 --- /dev/null +++ b/scripts/docker-buildx-push.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -euo pipefail + +# ======================= +# Multi-arch Docker Build & Push for Booklore +# ======================= + +# Ensure a version/tag is passed +if [ -z "${1:-}" ]; then + echo "ERROR: You must provide a version/tag as the first argument." + echo "Usage: $0 " + exit 1 +fi + +VERSION="$1" + +echo "Building Booklore App with multi-arch version: $VERSION" + +# Ensure Docker Buildx builder exists and is used +docker buildx create --use --name multiarch-builder || true + +# Build and push multi-arch Docker image +docker buildx build \ + --platform linux/amd64,linux/arm64 \ + -t retr0spect101/booklore:"$VERSION" \ + --push \ + . + +echo "Multi-arch Docker image retr0spect101/booklore:$VERSION pushed successfully!" \ No newline at end of file diff --git a/scripts/notify-discord.sh b/scripts/notify-discord.sh new file mode 100644 index 00000000..ebe6ef99 --- /dev/null +++ b/scripts/notify-discord.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# notify-discord.sh +# Sends a GitHub release notification to Discord +set -euo pipefail + +# ===== CONFIGURE HERE ===== +if [ -z "${1:-}" ]; then + echo "ERROR: You must provide the release tag as the first argument." + echo "Usage: $0 [discord-webhook-url]" + exit 1 +fi + +NEW_TAG="$1" +DISCORD_WEBHOOK_URL="${2:-https://discord.com/api/webhooks/your_webhook_id/your_webhook_token}" + +# Warn if using placeholder values +if [[ "$DISCORD_WEBHOOK_URL" == *"YOUR_WEBHOOK_ID"* ]] || [[ "$DISCORD_WEBHOOK_URL" == *"YOUR_WEBHOOK_TOKEN"* ]]; then + echo "WARNING: DISCORD_WEBHOOK_URL contains placeholder values; payload will likely fail." +fi + +echo "Preparing Discord notification for release $NEW_TAG" + +# Fetch release data from GitHub +echo "Running gh release view..." +release_json=$(gh release view "$NEW_TAG" --json name,body,url) +echo "Release JSON fetched" + +release_name=$(jq -r '.name' <<< "$release_json") +release_body=$(jq -r '.body' <<< "$release_json") +release_url=$(jq -r '.url' <<< "$release_json") + +dockerhub_image="https://hub.docker.com/r/booklore/booklore/tags/$NEW_TAG" +ghcr_image="https://github.com/booklore-app/booklore/pkgs/container/booklore/$NEW_TAG" + +# Clean up body for Discord +clean_body=$(echo "$release_body" | tr -d '\r') +max_length=1800 +if [ ${#clean_body} -gt $max_length ]; then + clean_body="${clean_body:0:$((max_length-12))}… [truncated]" +fi + +# Prepare Discord payload +payload=$(jq -n \ + --arg title "New Release: $release_name" \ + --arg url "$release_url" \ + --arg desc "$clean_body" \ + --arg hub "[View image]($dockerhub_image)" \ + --arg gh "[View image]($ghcr_image)" \ + '{ + content: null, + embeds: [{ + title: $title, + url: $url, + description: $desc, + color: 3066993, + fields: [ + { name: "Docker Hub", value: $hub, inline: true }, + { name: "GHCR", value: $gh, inline: true } + ] + }] + }') + +# Debug: show payload +echo "=== Discord payload ===" +echo "$payload" +echo "=======================" + +# Send notification +echo "Sending notification to Discord..." +curl -i -H "Content-Type: application/json" -d "$payload" "$DISCORD_WEBHOOK_URL" \ + || echo "⚠️ Request completed with an error; check the above HTTP response" + +echo "Notification sent!" \ No newline at end of file