Jelajahi Sumber

🔄ci: remove old build before publishing new release

Naz 2 bulan lalu
induk
melakukan
690c68a7c7
1 mengubah file dengan 37 tambahan dan 3 penghapusan
  1. 37 3
      .github/workflows/build-packages.yml

+ 37 - 3
.github/workflows/build-packages.yml

@@ -4,7 +4,11 @@ on:
   workflow_dispatch:
   push:
     paths:
-      - 'srcpkgs/**'
+      - "srcpkgs/**"
+
+permissions:
+  contents: write
+  packages: write
 
 env:
   ARCH: x86_64
@@ -27,7 +31,7 @@ jobs:
           sed -i 's|repo-default|repo-ci|g' /etc/xbps.d/*-repository-*.conf
           xbps-install -Syu xbps
           xbps-install -Syu
-          xbps-install -y tar curl openssh unzip git jq
+          xbps-install -y tar curl openssh unzip git jq github-cli
 
       - name: Checkout repositories
         uses: actions/checkout@v4
@@ -40,6 +44,36 @@ jobs:
         with:
           path: custom-packages
 
+      - name: Delete existing release assets
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          # Get the release ID for the 'latest' tag
+          RELEASE_ID=$(gh api \
+            -H "Accept: application/vnd.github+json" \
+            /repos/$GITHUB_REPOSITORY/releases/tags/latest \
+            --jq '.id' || echo "")
+
+          if [ ! -z "$RELEASE_ID" ]; then
+            # Get all assets for this release
+            assets=$(gh api \
+              -H "Accept: application/vnd.github+json" \
+              /repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID/assets \
+              --jq '.[].id' || echo "")
+            
+            # Delete each asset
+            for asset_id in $assets; do
+              gh api \
+                --method DELETE \
+                -H "Accept: application/vnd.github+json" \
+                /repos/$GITHUB_REPOSITORY/releases/assets/$asset_id
+            done
+            
+            echo "All assets from the latest release have been deleted"
+          else
+            echo "No release with tag 'latest' found or unable to access release"
+          fi
+
       - name: Setup and build packages
         run: |
           # Setup void-packages
@@ -79,7 +113,7 @@ jobs:
       - name: Create Release
         uses: softprops/action-gh-release@v1
         env:
-          GITHUB_TOKEN: ${{ secrets.TOKEN }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         with:
           files: |
             /github/home/packages/*.xbps