diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 69e7910..23fa100 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,22 +1,20 @@ -# 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. + # Runs on pushes to the `main` branch push: branches: [main] - # Allows you to run this workflow manually from the Actions tab + # Allow manual triggering from the Actions tab workflow_dispatch: -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +# Permissions needed for GitHub Pages deployment permissions: contents: read pages: write id-token: write +# Prevent overlapping deploys concurrency: group: pages cancel-in-progress: false @@ -25,80 +23,98 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: "☁️ checkout repository" + - 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" + - 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: 📦 Extract released packages + - 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 from PR body id: extract run: | REPO="https://github.com/${{ github.repository }}" - echo "${{ github.event.pull_request.body }}" > pr_body.md - # Extract all lines starting with '## ' + + # Extract lines starting with '## ' from PR body (i.e., package names) grep '^## ' pr_body.md | sed 's/^## //' > packages.txt - # Generate HTML list of links to releases + + # Generate Telegram HTML links to each released package 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 + + # Export formatted list to env { echo "RELEASE_LINKS<> "$GITHUB_ENV" - - name: 💬 Send Telegram Message uses: appleboy/telegram-action@master @@ -107,8 +123,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 }}