Create tar.gz Folders for Latest Release #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create and Upload Release Archive | ||
# 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 | ||
on: | ||
push: | ||
branches: | ||
- main # Thay 'main' bằng nhánh mặc định của bạn nếu cần | ||
workflow_dispatch: # Cho phép kích hoạt thủ công từ tab Actions | ||
jobs: | ||
build_and_upload: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write # Cần quyền ghi để tạo release và upload assets | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Create archives for each directory | ||
run: | | ||
# Lặp qua tất cả các thư mục trong thư mục gốc | ||
for dir in */; do | ||
# Bỏ qua thư mục .github | ||
if [ "$dir" == ".github/" ]; then | ||
continue | ||
fi | ||
# Tên file nén sẽ là tên thư mục | ||
ARCHIVE_NAME="${dir%/}.tar.gz" | ||
echo "Compressing ${dir} to ${ARCHIVE_NAME}" | ||
# Nén thư mục, loại trừ các file không cần thiết | ||
# tar -czvf [tên-file-output] [thư-mục-cần-nén] --exclude='[file-cần-loại-bỏ]' | ||
tar -czvf "${ARCHIVE_NAME}" \ | ||
--exclude='.github' \ | ||
--exclude='README.md' \ | ||
"${dir}" | ||
done | ||
- name: Get latest release | ||
id: get_latest_release | ||
uses: pozetroninc/[email protected] | ||
with: | ||
repository: ${{ github.repository }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Upload archives to latest release | ||
uses: actions/upload-release-asset@v1 | ||
with: | ||
upload_url: ${{ steps.get_latest_release.outputs.upload_url }} | ||
asset_path: ./*.tar.gz # Upload tất cả các file .tar.gz trong thư mục gốc | ||
asset_name: ${{ matrix.asset_name }} | ||
asset_content_type: application/gzip | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
strategy: | ||
matrix: | ||
asset_name: ${{ toJSON(fromJSON('{"include":' + toJSON(steps.get_latest_release.outputs.assets.*.name) + '}').include) }} |