|
1 |
| -name: Zip Folders and Upload to GitHub Release |
| 1 | +name: Zip Folders and Upload to Release |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | workflow_dispatch:
|
5 | 5 |
|
6 | 6 | jobs:
|
7 |
| - zip-and-upload: |
| 7 | + zip-and-release: |
8 | 8 | runs-on: ubuntu-latest
|
9 | 9 |
|
10 | 10 | steps:
|
11 |
| - - name: Checkout repository |
| 11 | + - name: Checkout code |
12 | 12 | uses: actions/checkout@v4
|
13 | 13 |
|
14 |
| - - name: Find folders and zip them |
15 |
| - id: zip |
| 14 | + - name: Zip each folder (excluding .github and README.md) |
16 | 15 | run: |
|
17 | 16 | mkdir -p zip_outputs
|
18 | 17 | for dir in */ ; do
|
19 | 18 | if [[ "$dir" != ".github/" && -d "$dir" ]]; then
|
20 | 19 | name="${dir%/}"
|
21 |
| - echo "Zipping $name..." |
| 20 | + echo "Zipping $name" |
22 | 21 | zip -r "zip_outputs/${name}.zip" "$name" -x "$name/README.md"
|
23 | 22 | fi
|
24 | 23 | done
|
25 | 24 |
|
26 | 25 | - name: Get latest release tag
|
27 | 26 | id: get_release
|
28 | 27 | run: |
|
29 |
| - tag=$(gh release list --limit 1 --json tagName -q '.[0].tagName') |
30 |
| - echo "Latest tag is: $tag" |
| 28 | + tag=$(gh release list --limit 1 --json tagName -q '.[0].tagName' || echo "") |
| 29 | + if [[ -z "$tag" ]]; then |
| 30 | + tag="auto-zip-$(date +%Y%m%d-%H%M%S)" |
| 31 | + echo "No existing release. Creating new release with tag $tag" |
| 32 | + gh release create "$tag" --title "Auto Zip Release $tag" --notes "Auto-generated zip files" |
| 33 | + else |
| 34 | + echo "Found existing release tag: $tag" |
| 35 | + fi |
31 | 36 | echo "tag=$tag" >> $GITHUB_OUTPUT
|
32 | 37 | env:
|
33 | 38 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
34 | 39 |
|
35 |
| - - name: Upload zip files to latest release |
| 40 | + - name: Ensure 'latest' release exists |
| 41 | + run: | |
| 42 | + if ! gh release view latest &>/dev/null; then |
| 43 | + echo "Creating 'latest' release" |
| 44 | + gh release create latest --title "Latest Auto Zip" --notes "Auto-generated zip files (latest)" |
| 45 | + fi |
| 46 | + env: |
| 47 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + - name: Upload zip files to releases |
36 | 50 | run: |
|
37 | 51 | for file in zip_outputs/*.zip; do
|
| 52 | + echo "Uploading $file to tag: ${{ steps.get_release.outputs.tag }} and 'latest'" |
38 | 53 | gh release upload "${{ steps.get_release.outputs.tag }}" "$file" --clobber
|
39 |
| - gh release upload "latest" "$file" --clobber || true |
| 54 | + gh release upload "latest" "$file" --clobber |
40 | 55 | done
|
41 | 56 | env:
|
42 | 57 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
0 commit comments