1
- name : Create and Upload Release Archive
1
+ name : Auto Create and Upload tar.gz Archives for Latest Release
2
2
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
4
3
on :
4
+ workflow_dispatch :
5
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
6
+ tags :
7
+ - ' v*' # Trigger on new version tags (e.g., v1.0.0)
9
8
10
9
jobs :
11
- build_and_upload :
10
+ build-and-upload :
12
11
runs-on : ubuntu-latest
13
12
permissions :
14
13
contents : write
15
14
16
15
steps :
17
16
- name : Checkout repository
18
17
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}"
19
27
20
- - name : Create archives
28
+ - name : Create tar.gz archives from each directory
21
29
run : |
22
- # ... (lệnh tar để nén file) ...
23
30
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"
27
38
done
28
39
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
40
41
env :
41
42
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