From 3566f9767a57059cf1690c2b8c26b79100f2bffd Mon Sep 17 00:00:00 2001 From: Amirhossein Alibakhshi Date: Tue, 6 May 2025 20:34:32 +0330 Subject: [PATCH 1/2] Update deploy.yml --- .github/workflows/deploy.yml | 81 +++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 69e7910..db74d94 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,17 +1,10 @@ -# Sample workflow for building and deploying a VitePress site to GitHub Pages -# -name: Deploy VitePress site to Pages +name: Deploy & Announce Release on: - # Runs on pushes targeting the `main` branch. Change this to `master` if you're - # using the `master` branch as the default branch. push: branches: [main] - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write @@ -25,80 +18,91 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: "☁️ checkout repository" + - name: ☁️ Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - - - - name: "🔧 setup pnpm" + - name: 🔧 Setup pnpm uses: pnpm/action-setup@v3 with: version: 9 - - name: "🔧 setup node" + - name: 🔧 Setup Node.js uses: actions/setup-node@v4 with: node-version: 20 - cache: "pnpm" + cache: pnpm - - name: "🔧 setup pages" + - name: 🔧 Setup GitHub Pages uses: actions/configure-pages@v4 - - name: "📦 install dependencies" + - name: 📦 Install dependencies run: pnpm install - # Set up GitHub Actions caching for Wireit. - - name: "🔌 setup wireit cache" + - name: 🔌 Setup Wireit cache uses: google/wireit@setup-github-actions-caching/v2 - - name: "🧱 build docs" + - name: 🧱 Build docs run: pnpm docs:build - - name: "🗄️ upload pages artifact" + - name: 🗄️ Upload pages artifact uses: actions/upload-pages-artifact@v3 with: path: .vitepress/dist - - deploy: + name: Deploy to GitHub Pages + needs: build + runs-on: ubuntu-latest environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} - needs: build - runs-on: ubuntu-latest - name: Deploy steps: - - name: "🚀 deploy to github pages" + - name: 🚀 Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 - - telegram-announcement: - name: 📣 Announcement on Telegram + telegram: + name: 📣 Announce on Telegram needs: build runs-on: ubuntu-latest steps: + - name: 🔍 Fetch latest merged PR via API + id: fetch_pr + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + run: | + curl -s -H "Authorization: token $GH_TOKEN" \ + "https://api.github.com/repos/$REPO/pulls?state=closed&base=main&sort=updated&direction=desc&per_page=1" \ + -o pr.json + + PR_NUMBER=$(grep '"number":' pr.json | head -n 1 | awk '{print $2}' | tr -d ',') + PR_TITLE=$(grep '"title":' pr.json | head -n 1 | cut -d ':' -f2- | sed 's/^ "//;s/",$//') + PR_URL=$(grep '"html_url":' pr.json | head -n 1 | cut -d '"' -f4) + sed -n '/"body":/,$p' pr.json | sed '1s/.*"body": "//; s/",$//' > pr_body.md + + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV + echo "PR_URL=$PR_URL" >> $GITHUB_ENV + - name: 📦 Extract released packages id: extract run: | REPO="https://github.com/${{ github.repository }}" - echo "${{ github.event.pull_request.body }}" > pr_body.md - # Extract all lines starting with '## ' grep '^## ' pr_body.md | sed 's/^## //' > packages.txt - # Generate HTML list of links to releases + while read -r line; do - ENCODED_TAG=$(echo "$line" | jq -sRr @uri) # encode the tag for URL safety + ENCODED_TAG=$(printf "%s" "$line" | jq -sRr @uri) echo " • $line" done < packages.txt > release_links.html + { echo "RELEASE_LINKS<> "$GITHUB_ENV" - - name: 💬 Send Telegram Message uses: appleboy/telegram-action@master @@ -107,8 +111,7 @@ jobs: token: ${{ secrets.TELEGRAM_TOKEN }} format: html message: | - 🚀 ${{ github.repository }} was just released! - ${{ env.RELEASE_LINKS }} - - 🔗 PR: ${{ github.event.pull_request.title }}#${{ github.event.pull_request.number }} - + 🚀 ${{ github.repository }} was just released!\n + 📦 Released Packages:\n + ${{ env.RELEASE_LINKS }}\n + 🔗 PR: ${{ env.PR_TITLE }} #${{ env.PR_NUMBER }} From bf4832bce73a2800f174c67df49e75c1f595ea1d Mon Sep 17 00:00:00 2001 From: Amirhossein Alibakhshi Date: Tue, 6 May 2025 20:36:17 +0330 Subject: [PATCH 2/2] Update deploy.yml --- .github/workflows/deploy.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index db74d94..23fa100 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,15 +1,20 @@ name: Deploy & Announce Release on: + # Runs on pushes to the `main` branch push: branches: [main] + + # Allow manual triggering from the Actions tab workflow_dispatch: +# Permissions needed for GitHub Pages deployment permissions: contents: read pages: write id-token: write +# Prevent overlapping deploys concurrency: group: pages cancel-in-progress: false @@ -21,7 +26,7 @@ jobs: - name: ☁️ Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 # Needed for full commit history (e.g. for changelogs) - name: 🔧 Setup pnpm uses: pnpm/action-setup@v3 @@ -46,20 +51,20 @@ jobs: - name: 🧱 Build docs run: pnpm docs:build - - name: 🗄️ Upload pages artifact + - name: 🗄️ Upload Pages artifact uses: actions/upload-pages-artifact@v3 with: path: .vitepress/dist deploy: - name: Deploy to GitHub Pages + name: 🚀 Deploy to GitHub Pages needs: build runs-on: ubuntu-latest environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: - - name: 🚀 Deploy to GitHub Pages + - name: 🔄 Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 @@ -68,36 +73,43 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - name: 🔍 Fetch latest merged PR via API + - name: 🔍 Fetch latest merged PR via GitHub API id: fetch_pr env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} run: | + # Fetch latest merged PR to main curl -s -H "Authorization: token $GH_TOKEN" \ "https://api.github.com/repos/$REPO/pulls?state=closed&base=main&sort=updated&direction=desc&per_page=1" \ -o pr.json + # Extract relevant fields PR_NUMBER=$(grep '"number":' pr.json | head -n 1 | awk '{print $2}' | tr -d ',') PR_TITLE=$(grep '"title":' pr.json | head -n 1 | cut -d ':' -f2- | sed 's/^ "//;s/",$//') PR_URL=$(grep '"html_url":' pr.json | head -n 1 | cut -d '"' -f4) sed -n '/"body":/,$p' pr.json | sed '1s/.*"body": "//; s/",$//' > pr_body.md + # Export to env echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV echo "PR_URL=$PR_URL" >> $GITHUB_ENV - - name: 📦 Extract released packages + - name: 📦 Extract released packages from PR body id: extract run: | REPO="https://github.com/${{ github.repository }}" + + # Extract lines starting with '## ' from PR body (i.e., package names) grep '^## ' pr_body.md | sed 's/^## //' > packages.txt + # Generate Telegram HTML links to each released package while read -r line; do ENCODED_TAG=$(printf "%s" "$line" | jq -sRr @uri) echo " • $line" done < packages.txt > release_links.html + # Export formatted list to env { echo "RELEASE_LINKS<