Skip to content

Commit cc47933

Browse files
authored
update
1 parent 54e65aa commit cc47933

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed
Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
name: Zip and Upload Folders with GITHUB_TOKEN
1+
# .github/workflows/create-release-zips.yml
22

3+
name: Nén Thư Mục và Tải Lên Release
4+
5+
# 1. Kích hoạt thủ công
36
on:
47
workflow_dispatch:
58

69
jobs:
7-
zip-and-upload:
10+
build-and-upload:
811
runs-on: ubuntu-latest
12+
# Cấp quyền ghi cho job để có thể tải file lên release
13+
permissions:
14+
contents: write
915

1016
steps:
17+
# Bước 1: Checkout mã nguồn của repo
1118
- name: Checkout repository
1219
uses: actions/checkout@v4
1320

14-
- name: Create zip files for each folder (excluding .github and README.md)
21+
# Bước 2: Nén từng thư mục thành file zip riêng
22+
# - Lặp qua tất cả các thư mục ở cấp gốc.
23+
# - Bỏ qua thư mục .github.
24+
# - Nén mỗi thư mục, loại trừ file README.md.
25+
- name: Zip individual folders
1526
run: |
16-
mkdir -p zip_outputs
17-
for dir in */ ; do
18-
folder=$(basename "$dir")
19-
if [ "$folder" != ".github" ]; then
20-
zip -r "zip_outputs/${folder}.zip" "$dir" -x "${dir}README.md"
27+
# Lặp qua tất cả các mục kết thúc bằng dấu gạch chéo (tức là các thư mục)
28+
for dir in */; do
29+
# Lấy tên thư mục không có dấu gạch chéo
30+
dirname="${dir%/}"
31+
32+
# 3. Bỏ qua thư mục .github
33+
if [ "$dirname" == ".github" ]; then
34+
echo "Skipping .github directory..."
35+
continue
2136
fi
37+
38+
echo "Zipping '$dirname'..."
39+
# 2. Nén thư mục thành file zip, loại trừ file README.md
40+
zip -r "${dirname}.zip" "$dirname" -x "*/README.md"
2241
done
2342
24-
- name: Get upload URL of release with tag 'latest'
25-
id: get_upload_url
43+
# Bước 3: Tải các file zip lên release mới nhất
44+
# - Sử dụng GitHub CLI (gh) để tải lên.
45+
# - 'latest' là một alias chỉ đến bản phát hành gần đây nhất.
46+
- name: Upload zip files to latest release
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2649
run: |
27-
api_url="https://api.github.com/repos/${{ github.repository }}/releases/tags/latest"
28-
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$api_url")
29-
30-
upload_url=$(echo "$response" | jq -r .upload_url | sed -e "s/{?name,label}//")
31-
echo "Upload URL: $upload_url"
32-
echo "upload_url=$upload_url" >> "$GITHUB_OUTPUT"
33-
34-
- name: Upload zip files using GitHub API
35-
run: |
36-
for file in zip_outputs/*.zip; do
37-
filename=$(basename "$file")
38-
echo "Uploading $filename..."
39-
curl -s -X POST \
40-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
41-
-H "Content-Type: application/zip" \
42-
--data-binary @"$file" \
43-
"${{ steps.get_upload_url.outputs.upload_url }}?name=$filename"
44-
done
50+
# 4. Upload các file zip vào release cuối cùng (latest)
51+
gh release upload latest *.zip --clobber
52+
echo "✅ All zip files have been uploaded to the latest release."

0 commit comments

Comments
 (0)