1- name : Create and Upload Release Archive
1+ name : Auto Create and Upload tar.gz Archives for Latest Release
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
43on :
4+ workflow_dispatch :
55 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
6+ tags :
7+ - ' v*' # Trigger on new version tags (e.g., v1.0.0)
98
109jobs :
11- build_and_upload :
10+ build-and-upload :
1211 runs-on : ubuntu-latest
1312 permissions :
1413 contents : write
1514
1615 steps :
1716 - name : Checkout repository
1817 uses : actions/checkout@v4
18+ with :
19+ fetch-depth : 0 # Needed to get all tags for version comparison
20+
21+ - name : Get the latest tag
22+ id : get_tag
23+ run : |
24+ latest_tag=$(git describe --tags --abbrev=0)
25+ echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT
26+ echo "📌 Latest tag: ${latest_tag}"
1927
20- - name : Create archives
28+ - name : Create tar.gz archives from each directory
2129 run : |
22- # ... (lệnh tar để nén file) ...
2330 for dir in */; do
24- if [ "$dir" == ".github/" ]; then continue; fi
25- ARCHIVE_NAME="${dir%/}.tar.gz"
26- tar -czvf "${ARCHIVE_NAME}" --exclude='README.md' "${dir}"
31+ dirname="${dir%/}"
32+ if [ "$dirname" == ".github" ]; then
33+ echo "⏩ Skipping .github directory"
34+ continue
35+ fi
36+ echo "📦 Creating '${dirname}.tar.gz'..."
37+ tar --exclude="${dirname}/README.md" -czf "${dirname}.tar.gz" "$dirname"
2738 done
2839
29- # BƯỚC NÀY RẤT QUAN TRỌNG, KHÔNG ĐƯỢC XÓA
30- - name : Get latest release
31- id : get_latest_release
32- uses :
pozetroninc/[email protected] 33- with :
34- repository : ${{ github.repository }}
35- token : ${{ secrets.GITHUB_TOKEN }}
36-
37- # Bước này cần 'upload_url' từ bước trên
38- - name : Upload archives to latest release
39- uses : actions/upload-release-asset@v1
40+ - name : Upload tar.gz files to release
4041 env :
4142 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
42- with :
43- upload_url : ${{ steps.get_latest_release.outputs.upload_url }}
44- asset_path : ./*.tar.gz
45- asset_content_type : application/gzip
43+ run : |
44+ gh release upload ${{ steps.get_tag.outputs.latest_tag }} *.tar.gz --clobber
45+ echo "✅ Successfully uploaded tar.gz files to release '${{ steps.get_tag.outputs.latest_tag }}'"
46+
47+ - name : Clean up artifacts
48+ run : rm -f *.tar.gz
0 commit comments