1
- name : Create tar.gz Archives for Release
1
+ name : Create and Upload Release Archive
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
3
4
on :
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
10
9
11
10
jobs :
12
- build-and-upload :
11
+ build_and_upload :
13
12
runs-on : ubuntu-latest
14
13
permissions :
15
- contents : write
14
+ contents : write # Cần quyền ghi để tạo release và upload assets
16
15
17
16
steps :
18
17
- name : Checkout repository
19
18
uses : actions/checkout@v4
20
19
21
- - name : Tạo file .tar.gz từ từng thư mục
20
+ - name : Create archives for each directory
22
21
run : |
22
+ # Lặp qua tất cả các thư mục trong thư mục gốc
23
23
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
27
26
continue
28
27
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}"
31
39
done
32
40
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
34
55
env :
35
56
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