Skip to content

Commit 2215dbd

Browse files
authored
Merge pull request #23 from code-with-amirhossein/amir78729-patch-24
Update deploy.yml
2 parents 76fea55 + bf4832b commit 2215dbd

File tree

1 file changed

+55
-40
lines changed

1 file changed

+55
-40
lines changed

.github/workflows/deploy.yml

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
# Sample workflow for building and deploying a VitePress site to GitHub Pages
2-
#
3-
name: Deploy VitePress site to Pages
1+
name: Deploy & Announce Release
42

53
on:
6-
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
7-
# using the `master` branch as the default branch.
4+
# Runs on pushes to the `main` branch
85
push:
96
branches: [main]
107

11-
# Allows you to run this workflow manually from the Actions tab
8+
# Allow manual triggering from the Actions tab
129
workflow_dispatch:
1310

14-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
11+
# Permissions needed for GitHub Pages deployment
1512
permissions:
1613
contents: read
1714
pages: write
1815
id-token: write
1916

17+
# Prevent overlapping deploys
2018
concurrency:
2119
group: pages
2220
cancel-in-progress: false
@@ -25,80 +23,98 @@ jobs:
2523
build:
2624
runs-on: ubuntu-latest
2725
steps:
28-
- name: "☁️ checkout repository"
26+
- name: ☁️ Checkout repository
2927
uses: actions/checkout@v4
3028
with:
31-
fetch-depth: 0
32-
29+
fetch-depth: 0 # Needed for full commit history (e.g. for changelogs)
3330

34-
35-
- name: "🔧 setup pnpm"
31+
- name: 🔧 Setup pnpm
3632
uses: pnpm/action-setup@v3
3733
with:
3834
version: 9
3935

40-
- name: "🔧 setup node"
36+
- name: 🔧 Setup Node.js
4137
uses: actions/setup-node@v4
4238
with:
4339
node-version: 20
44-
cache: "pnpm"
40+
cache: pnpm
4541

46-
- name: "🔧 setup pages"
42+
- name: 🔧 Setup GitHub Pages
4743
uses: actions/configure-pages@v4
4844

49-
- name: "📦 install dependencies"
45+
- name: 📦 Install dependencies
5046
run: pnpm install
5147

52-
# Set up GitHub Actions caching for Wireit.
53-
- name: "🔌 setup wireit cache"
48+
- name: 🔌 Setup Wireit cache
5449
uses: google/wireit@setup-github-actions-caching/v2
5550

56-
- name: "🧱 build docs"
51+
- name: 🧱 Build docs
5752
run: pnpm docs:build
5853

59-
- name: "🗄️ upload pages artifact"
54+
- name: 🗄️ Upload Pages artifact
6055
uses: actions/upload-pages-artifact@v3
6156
with:
6257
path: .vitepress/dist
6358

64-
65-
6659
deploy:
60+
name: 🚀 Deploy to GitHub Pages
61+
needs: build
62+
runs-on: ubuntu-latest
6763
environment:
6864
name: github-pages
6965
url: ${{ steps.deployment.outputs.page_url }}
70-
needs: build
71-
runs-on: ubuntu-latest
72-
name: Deploy
7366
steps:
74-
- name: "🚀 deploy to github pages"
67+
- name: 🔄 Deploy to GitHub Pages
7568
id: deployment
7669
uses: actions/deploy-pages@v4
7770

78-
79-
telegram-announcement:
80-
name: 📣 Announcement on Telegram
71+
telegram:
72+
name: 📣 Announce on Telegram
8173
needs: build
8274
runs-on: ubuntu-latest
8375
steps:
84-
- name: 📦 Extract released packages
76+
- name: 🔍 Fetch latest merged PR via GitHub API
77+
id: fetch_pr
78+
env:
79+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
REPO: ${{ github.repository }}
81+
run: |
82+
# Fetch latest merged PR to main
83+
curl -s -H "Authorization: token $GH_TOKEN" \
84+
"https://api.github.com/repos/$REPO/pulls?state=closed&base=main&sort=updated&direction=desc&per_page=1" \
85+
-o pr.json
86+
87+
# Extract relevant fields
88+
PR_NUMBER=$(grep '"number":' pr.json | head -n 1 | awk '{print $2}' | tr -d ',')
89+
PR_TITLE=$(grep '"title":' pr.json | head -n 1 | cut -d ':' -f2- | sed 's/^ "//;s/",$//')
90+
PR_URL=$(grep '"html_url":' pr.json | head -n 1 | cut -d '"' -f4)
91+
sed -n '/"body":/,$p' pr.json | sed '1s/.*"body": "//; s/",$//' > pr_body.md
92+
93+
# Export to env
94+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
95+
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV
96+
echo "PR_URL=$PR_URL" >> $GITHUB_ENV
97+
98+
- name: 📦 Extract released packages from PR body
8599
id: extract
86100
run: |
87101
REPO="https://github.com/${{ github.repository }}"
88-
echo "${{ github.event.pull_request.body }}" > pr_body.md
89-
# Extract all lines starting with '## '
102+
103+
# Extract lines starting with '## ' from PR body (i.e., package names)
90104
grep '^## ' pr_body.md | sed 's/^## //' > packages.txt
91-
# Generate HTML list of links to releases
105+
106+
# Generate Telegram HTML links to each released package
92107
while read -r line; do
93-
ENCODED_TAG=$(echo "$line" | jq -sRr @uri) # encode the tag for URL safety
108+
ENCODED_TAG=$(printf "%s" "$line" | jq -sRr @uri)
94109
echo " • <a href=\"$REPO/releases/tag/$ENCODED_TAG\">$line</a>"
95110
done < packages.txt > release_links.html
111+
112+
# Export formatted list to env
96113
{
97114
echo "RELEASE_LINKS<<EOF"
98115
cat release_links.html
99116
echo "EOF"
100117
} >> "$GITHUB_ENV"
101-
102118
103119
- name: 💬 Send Telegram Message
104120
uses: appleboy/telegram-action@master
@@ -107,8 +123,7 @@ jobs:
107123
token: ${{ secrets.TELEGRAM_TOKEN }}
108124
format: html
109125
message: |
110-
🚀 <b><a href="https://github.com/${{ github.repository }}">${{ github.repository }}</a></b> was just released!
111-
${{ env.RELEASE_LINKS }}
112-
113-
🔗 PR: <a href="${{ github.event.pull_request.html_url }}"><b>${{ github.event.pull_request.title }}</b>#${{ github.event.pull_request.number }}</a>
114-
126+
🚀 <b><a href="https://github.com/${{ github.repository }}">${{ github.repository }}</a></b> was just released!\n
127+
📦 <b>Released Packages:</b>\n
128+
${{ env.RELEASE_LINKS }}\n
129+
🔗 PR: <a href="${{ env.PR_URL }}"><b>${{ env.PR_TITLE }}</b> #${{ env.PR_NUMBER }}</a>

0 commit comments

Comments
 (0)