@@ -118,7 +118,7 @@ jobs:
118118 runs-on : ubuntu-latest
119119 strategy :
120120 matrix :
121- arch : [x86_64, aarch64, i686 ]
121+ arch : [x86_64, aarch64]
122122 steps :
123123 - name : Checkout repository
124124 uses : actions/checkout@v4
@@ -163,6 +163,15 @@ jobs:
163163 out-file-path : ./downloaded
164164 token : ${{ secrets.GITHUB_TOKEN }}
165165
166+ - name : Verify downloaded file
167+ run : |
168+ ls -la ./downloaded/
169+ if [ ! -s ./downloaded/apisnip-linux-*.tar.gz ]; then
170+ echo "Error: Downloaded file is empty or does not exist"
171+ exit 1
172+ fi
173+ file ./downloaded/apisnip-linux-*.tar.gz
174+
166175 - name : Setup RPM build environment
167176 run : |
168177 mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
@@ -191,6 +200,7 @@ jobs:
191200 URL: https://github.com/Tuurlijk/apisnip
192201 Source0: %{name}-%{version}.tar.gz
193202
203+ # Specify architecture explicitly
194204 BuildArch: ${{ matrix.arch }}
195205
196206 %description
@@ -218,10 +228,22 @@ jobs:
218228 - name : Build RPM package
219229 id : build_rpm
220230 run : |
221- rpmbuild -ba ~/rpmbuild/SPECS/apisnip.spec
231+ rpmbuild -ba ~/rpmbuild/SPECS/apisnip.spec || {
232+ echo "RPM build failed, checking issues..."
233+ cat ~/rpmbuild/SPECS/apisnip.spec
234+ ls -la ~/rpmbuild/SOURCES/
235+ echo "Contents of source tarball:"
236+ tar -tvzf ~/rpmbuild/SOURCES/apisnip-${{ steps.extract_version.outputs.VERSION }}.tar.gz
237+ exit 1
238+ }
222239
223240 # Find the built RPM
224241 RPM_PATH=$(find ~/rpmbuild/RPMS -name "*.rpm" | head -1)
242+ if [ -z "$RPM_PATH" ]; then
243+ echo "No RPM package found in the build directory"
244+ exit 1
245+ fi
246+
225247 RPM_FILENAME=$(basename "$RPM_PATH")
226248 cp "$RPM_PATH" .
227249
@@ -251,7 +273,7 @@ jobs:
251273 steps :
252274 - name : Install build tools
253275 run : |
254- apk add --no-cache alpine-sdk sudo tar curl jq bash
276+ apk add --no-cache alpine-sdk sudo tar curl jq bash file
255277
256278 - name : Checkout repository
257279 uses : actions/checkout@v4
@@ -273,7 +295,10 @@ jobs:
273295 VERSION=$(curl -s ${GITHUB_API} | jq -r '.tag_name' | sed 's/^v//')
274296 echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
275297 fi
276- echo "Using version: $(cat $GITHUB_OUTPUT | grep VERSION | cut -d= -f2)"
298+ VERSION=$(cat $GITHUB_OUTPUT | grep VERSION | cut -d= -f2)
299+ echo "Using version: $VERSION"
300+ # Export as environment variable for easier use in subsequent steps
301+ echo "VERSION=$VERSION" >> $GITHUB_ENV
277302
278303 - name : Download Linux binary
279304 run : |
@@ -283,7 +308,48 @@ jobs:
283308 ARCH_NAME="arm64"
284309 fi
285310
286- curl -L "https://github.com/${GITHUB_REPOSITORY}/releases/download/v$(cat $GITHUB_OUTPUT | grep VERSION | cut -d= -f2)/apisnip-linux-${ARCH_NAME}.tar.gz" -o downloaded/apisnip-linux.tar.gz
311+ DOWNLOAD_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/v${VERSION}/apisnip-linux-${ARCH_NAME}.tar.gz"
312+ echo "Downloading from: $DOWNLOAD_URL"
313+
314+ curl -L -o downloaded/apisnip-linux.tar.gz "$DOWNLOAD_URL"
315+
316+ # Verify the download
317+ ls -la downloaded/
318+ file downloaded/apisnip-linux.tar.gz
319+
320+ - name : Extract binary manually
321+ run : |
322+ mkdir -p pkg/usr/bin
323+ cd pkg
324+
325+ # Extract the tar file directly
326+ BINARY_PATH="$(pwd)/usr/bin/apisnip"
327+ mkdir -p usr/bin
328+
329+ cd ..
330+ tar -xvf downloaded/apisnip-linux.tar.gz -C pkg
331+
332+ if [ -f "pkg/apisnip" ]; then
333+ # If the binary is directly at the root, move it to the right location
334+ mkdir -p pkg/usr/bin
335+ mv pkg/apisnip pkg/usr/bin/
336+ fi
337+
338+ # Verify extraction
339+ find pkg -type f | sort
340+
341+ # Copy binary to a known location for build step
342+ cp pkg/usr/bin/apisnip ./apisnip || {
343+ echo "Binary not found at pkg/usr/bin/apisnip, checking other locations";
344+ find pkg -name "apisnip" -type f -exec cp {} ./apisnip \;
345+ }
346+
347+ if [ ! -f "./apisnip" ]; then
348+ echo "Failed to locate the apisnip binary after extraction"
349+ exit 1
350+ fi
351+
352+ chmod +x ./apisnip
287353
288354 - name : Setup APK build environment
289355 run : |
@@ -300,7 +366,7 @@ jobs:
300366 cat > APKBUILD << EOF
301367 # Maintainer: Michiel Roos <apisnip.zumble.frap@michielroos.com>
302368 pkgname=apisnip
303- pkgver=${{ steps.extract_version.outputs. VERSION } }
369+ pkgver=${VERSION}
304370 pkgrel=0
305371 pkgdesc="A terminal user interface (TUI) tool for trimming OpenAPI specifications down to size"
306372 url="https://github.com/Tuurlijk/apisnip"
@@ -321,14 +387,6 @@ jobs:
321387 }
322388 EOF
323389
324- - name : Extract binary
325- run : |
326- mkdir -p pkg/usr/bin
327- mkdir -p pkg/usr/share/doc/apisnip
328- tar -xzf downloaded/apisnip-linux.tar.gz -C ./pkg
329- cp pkg/apisnip ~/apkbuild/
330- cp README.md LICENSE pkg/usr/share/doc/apisnip/ || true
331-
332390 - name : Build APK package
333391 id : build_apk
334392 run : |
@@ -339,6 +397,14 @@ jobs:
339397
340398 # Find the built APK
341399 APK_PATH=$(find /home/$(whoami)/packages -name "*.apk" | grep apisnip | head -1)
400+
401+ if [ -z "$APK_PATH" ]; then
402+ echo "No APK package found in the build directory"
403+ ls -la /home/$(whoami)/packages
404+ abuild -v # Show more verbose output about what might have gone wrong
405+ exit 1
406+ fi
407+
342408 APK_FILENAME=$(basename "$APK_PATH")
343409
344410 # Copy the package
@@ -356,7 +422,7 @@ jobs:
356422 files : |
357423 ${{ steps.build_apk.outputs.APK_FILENAME }}
358424 ${{ steps.build_apk.outputs.APK_FILENAME }}.sha256
359- tag_name : v${{ steps.extract_version.outputs .VERSION }}
425+ tag_name : v${{ env .VERSION }}
360426 env :
361427 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
362428
@@ -625,4 +691,163 @@ jobs:
625691
626692 # Note: To actually publish to AUR, you would need to set up SSH keys
627693 # and use git to push to the AUR. This is not implemented here as it
628- # requires AUR account credentials.
694+ # requires AUR account credentials.
695+
696+ # Add a final job to organize release assets in the description
697+ organize-release-assets :
698+ name : Organize Release Assets
699+ needs : [create-debian-package, create-rpm-package, create-apk-package, create-macos-package, create-aur-package]
700+ runs-on : ubuntu-latest
701+ if : always() # Run even if some of the previous jobs failed
702+ steps :
703+ - name : Get Release Info
704+ id : get_release
705+ uses : octokit/request-action@v2.x
706+ with :
707+ route : GET /repos/${{ github.repository }}/releases/latest
708+ env :
709+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
710+
711+ - name : Extract Version
712+ id : extract_version
713+ run : |
714+ if [ "${{ github.event.inputs.version }}" != "" ]; then
715+ echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
716+ elif [ "${{ github.event_name }}" == "release" ]; then
717+ RELEASE_TAG="${{ github.event.release.tag_name }}"
718+ VERSION=${RELEASE_TAG#v}
719+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
720+ else
721+ RESPONSE='${{ steps.get_release.outputs.data }}'
722+ TAG_NAME=$(echo "$RESPONSE" | grep -o '"tag_name": *"[^"]*"' | cut -d'"' -f4)
723+ VERSION=${TAG_NAME#v}
724+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
725+ fi
726+ echo "Using version: $(cat $GITHUB_OUTPUT | grep VERSION | cut -d= -f2)"
727+
728+ - name : Get All Assets
729+ id : get_assets
730+ run : |
731+ RELEASE_TAG="v${{ steps.extract_version.outputs.VERSION }}"
732+ ASSETS=$(curl -s \
733+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
734+ "https://api.github.com/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" \
735+ | jq -r '.assets[] | "\(.name) \(.browser_download_url)"')
736+
737+ echo "ASSETS<<EOF" >> $GITHUB_ENV
738+ echo "$ASSETS" >> $GITHUB_ENV
739+ echo "EOF" >> $GITHUB_ENV
740+
741+ - name : Get Existing Release Info
742+ id : get_existing_release
743+ run : |
744+ RELEASE_TAG="v${{ steps.extract_version.outputs.VERSION }}"
745+ RELEASE_DATA=$(curl -s \
746+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
747+ "https://api.github.com/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG")
748+
749+ # Extract the current release body
750+ EXISTING_BODY=$(echo "$RELEASE_DATA" | jq -r '.body // ""')
751+
752+ # Check if body already contains our asset tables (to avoid duplicates)
753+ if echo "$EXISTING_BODY" | grep -q "## Binary Downloads"; then
754+ # If our sections already exist, just preserve the original body
755+ echo "EXISTING_BODY<<EOF" >> $GITHUB_ENV
756+ echo "$EXISTING_BODY" >> $GITHUB_ENV
757+ echo "EOF" >> $GITHUB_ENV
758+ echo "CONTAINS_ASSETS=true" >> $GITHUB_OUTPUT
759+ else
760+ # If our sections don't exist, we'll append them
761+ echo "EXISTING_BODY<<EOF" >> $GITHUB_ENV
762+ echo "$EXISTING_BODY" >> $GITHUB_ENV
763+ echo "EOF" >> $GITHUB_ENV
764+ echo "CONTAINS_ASSETS=false" >> $GITHUB_OUTPUT
765+ fi
766+
767+ - name : Organize Assets by Category
768+ id : organize_assets
769+ if : steps.get_existing_release.outputs.CONTAINS_ASSETS != 'true'
770+ run : |
771+ # Function to create a category section with assets
772+ create_category() {
773+ local category=$1
774+ local pattern=$2
775+ local title=$3
776+
777+ echo -e "### $title\n"
778+
779+ # Filter assets matching the pattern and create markdown links
780+ matching_assets=$(echo "$ASSETS" | grep -i "$pattern" | grep -v "\.sha256$" | sort)
781+ if [ -z "$matching_assets" ]; then
782+ echo "No $category packages available."
783+ else
784+ echo "| Package | SHA256 |"
785+ echo "|---------|--------|"
786+ echo "$matching_assets" | while read -r line; do
787+ name=$(echo "$line" | awk '{print $1}')
788+ url=$(echo "$line" | awk '{print $2}')
789+ sha_line=$(echo "$ASSETS" | grep "${name}\.sha256")
790+ if [ -n "$sha_line" ]; then
791+ sha_url=$(echo "$sha_line" | awk '{print $2}')
792+ echo "| [$name]($url) | [SHA256]($sha_url) |"
793+ else
794+ echo "| [$name]($url) | N/A |"
795+ fi
796+ done
797+ fi
798+ echo ""
799+ }
800+
801+ # Generate description file for the assets
802+ cat > assets_section.md << EOF
803+
804+ ## Binary Downloads
805+
806+ $(create_category "Linux" "linux" "Linux Binaries")
807+ $(create_category "Windows" "windows" "Windows Binaries")
808+ $(create_category "macOS" "macos" "macOS Binaries")
809+ $(create_category "FreeBSD" "freebsd" "FreeBSD Binaries")
810+ $(create_category "NetBSD" "netbsd" "NetBSD Binaries")
811+
812+ ## Package Downloads
813+
814+ $(create_category "Debian" "_amd64\.deb\|_arm64\.deb\|_i386\.deb" "Debian/Ubuntu Packages (.deb)")
815+ $(create_category "RPM" "\.rpm" "Red Hat/Fedora/SUSE Packages (.rpm)")
816+ $(create_category "Alpine" "\.apk" "Alpine Linux Packages (.apk)")
817+ $(create_category "AUR" "aur" "Arch Linux Package (AUR)")
818+ $(create_category "Homebrew" "homebrew" "macOS Homebrew Formula")
819+ $(create_category "DMG" "\.dmg" "macOS Disk Image (.dmg)")
820+ EOF
821+
822+ ASSETS_SECTION=$(cat assets_section.md)
823+ echo "assets_section<<EOF" >> $GITHUB_OUTPUT
824+ echo "$ASSETS_SECTION" >> $GITHUB_OUTPUT
825+ echo "EOF" >> $GITHUB_OUTPUT
826+
827+ # Combine existing body with asset tables
828+ if [ -n "$EXISTING_BODY" ]; then
829+ COMBINED_BODY="${EXISTING_BODY}${ASSETS_SECTION}"
830+ else
831+ COMBINED_BODY=$'## ApiSnip v${{ steps.extract_version.outputs.VERSION }}\n\nA terminal user interface (TUI) tool for trimming OpenAPI specifications down to size ✂️${ASSETS_SECTION}'
832+ fi
833+
834+ echo "combined_body<<EOF" >> $GITHUB_OUTPUT
835+ echo "$COMBINED_BODY" >> $GITHUB_OUTPUT
836+ echo "EOF" >> $GITHUB_OUTPUT
837+
838+ - name : Update Release Description
839+ if : steps.get_existing_release.outputs.CONTAINS_ASSETS != 'true'
840+ uses : octokit/request-action@v2.x
841+ with :
842+ route : PATCH /repos/${{ github.repository }}/releases/tags/v${{ steps.extract_version.outputs.VERSION }}
843+ body : ${{ steps.organize_assets.outputs.combined_body }}
844+ env :
845+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
846+
847+ - name : Log Status
848+ run : |
849+ if [ "${{ steps.get_existing_release.outputs.CONTAINS_ASSETS }}" == "true" ]; then
850+ echo "Release description already contains asset tables. No changes made."
851+ else
852+ echo "Release description updated with organized asset tables."
853+ fi
0 commit comments