1- name : Create tar.gz Archives for Release
1+ name : Create and Upload Release Archive
22
3+ # Kích hoạt workflow này khi có push vào nhánh main hoặc có thể kích hoạt thủ công
34on :
4- workflow_dispatch :
5- inputs :
6- tag_name :
7- description : ' Nhập tên tag của release (ví dụ: v1.0.0)'
8- required : true
9- type : string
5+ push :
6+ branches :
7+ - main # Thay 'main' bằng nhánh mặc định của bạn nếu cần
8+ workflow_dispatch : # Cho phép kích hoạt thủ công từ tab Actions
109
1110jobs :
12- build-and-upload :
11+ build_and_upload :
1312 runs-on : ubuntu-latest
1413 permissions :
15- contents : write
14+ contents : write # Cần quyền ghi để tạo release và upload assets
1615
1716 steps :
1817 - name : Checkout repository
1918 uses : actions/checkout@v4
2019
21- - name : Tạo file .tar.gz từ từng thư mục
20+ - name : Create archives for each directory
2221 run : |
22+ # Lặp qua tất cả các thư mục trong thư mục gốc
2323 for dir in */; do
24- dirname="${dir%/}"
25- if [ "$dirname" == ".github" ]; then
26- echo "⏩ Bỏ qua thư mục .github"
24+ # Bỏ qua thư mục .github
25+ if [ "$dir" == ".github/" ]; then
2726 continue
2827 fi
29- echo "📦 Đang tạo '${dirname}.tar.gz'..."
30- tar --exclude="${dirname}/README.md" -czf "${dirname}.tar.gz" "$dirname"
28+
29+ # Tên file nén sẽ là tên thư mục
30+ ARCHIVE_NAME="${dir%/}.tar.gz"
31+ echo "Compressing ${dir} to ${ARCHIVE_NAME}"
32+
33+ # Nén thư mục, loại trừ các file không cần thiết
34+ # tar -czvf [tên-file-output] [thư-mục-cần-nén] --exclude='[file-cần-loại-bỏ]'
35+ tar -czvf "${ARCHIVE_NAME}" \
36+ --exclude='.github' \
37+ --exclude='README.md' \
38+ "${dir}"
3139 done
3240
33- - name : Tải file .tar.gz lên release theo tag đã chọn
41+ - name : Get latest release
42+ id : get_latest_release
43+ uses :
pozetroninc/[email protected] 44+ with :
45+ repository : ${{ github.repository }}
46+ token : ${{ secrets.GITHUB_TOKEN }}
47+
48+ - name : Upload archives to latest release
49+ uses : actions/upload-release-asset@v1
50+ with :
51+ upload_url : ${{ steps.get_latest_release.outputs.upload_url }}
52+ asset_path : ./*.tar.gz # Upload tất cả các file .tar.gz trong thư mục gốc
53+ asset_name : ${{ matrix.asset_name }}
54+ asset_content_type : application/gzip
3455 env :
3556 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
36- run : |
37- gh release upload ${{ github.event.inputs.tag_name }} *.tar.gz --clobber
38- echo "✅ Đã tải tệp .tar.gz lên release ' ${{ github.event.inputs.tag_name }}'."
57+ strategy :
58+ matrix :
59+ asset_name : ${{ toJSON(fromJSON('{"include":' + toJSON(steps.get_latest_release.outputs.assets.*.name) + '}').include) }}
0 commit comments