Fix: Make CI startup test more robust against set -e and timeout exit… #234
Workflow file for this run
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: Build and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| goos: [linux, windows, darwin, freebsd] | |
| goarch: [amd64, arm64] | |
| exclude: | |
| - goos: windows | |
| goarch: arm64 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Build binary | |
| run: | | |
| mkdir -p dist | |
| EXT="" | |
| if [ "${{ matrix.goos }}" = "windows" ]; then | |
| EXT=".exe" | |
| fi | |
| GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o dist/tinyice-${{ matrix.goos }}-${{ matrix.goarch }}${EXT} main.go | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: tinyice-${{ matrix.goos }}-${{ matrix.goarch }} | |
| path: dist/* | |
| test_startup: | |
| name: Test TinyIce Startup | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Determine Runner Architecture | |
| id: arch_detect | |
| run: | | |
| RUNNER_ARCH=$(uname -m) | |
| case "$RUNNER_ARCH" in | |
| x86_64) GOARCH="amd64" ;; | |
| aarch64) GOARCH="arm64" ;; | |
| arm64) GOARCH="arm64" ;; | |
| *) echo "Unsupported runner architecture: $RUNNER_ARCH"; exit 1 ;; | |
| esac | |
| echo "GOARCH=$GOARCH" >> "$GITHUB_OUTPUT" | |
| - name: Download Linux Artifact for Runner Arch | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: tinyice-linux-${{ steps.arch_detect.outputs.GOARCH }} | |
| path: artifacts_to_test | |
| - name: Run TinyIce startup test | |
| run: | | |
| GOARCH="${{ steps.arch_detect.outputs.GOARCH }}" | |
| BINARY_PATH="artifacts_to_test/tinyice-linux-${GOARCH}" | |
| echo "Starting TinyIce in background for 5 seconds to check for startup errors..." | |
| chmod +x "$BINARY_PATH" # Add execute permissions | |
| # Run TinyIce, preventing set -e from failing the script immediately if timeout returns 124. | |
| # We want to pass if it exits 0 (graceful stop) or 124 (timeout). | |
| # We fail if it exits with any other non-zero code. | |
| if timeout 5s sh -c "$BINARY_PATH -port 8080 -config /tmp/tinyice-test-linux-${GOARCH}.json"; then | |
| TIMEOUT_EXIT_CODE=0 # timeout succeeded, meaning inner command exited 0 | |
| else | |
| TIMEOUT_EXIT_CODE=$? # timeout failed (either non-zero from inner command or 124 for timeout) | |
| fi | |
| if [ $TIMEOUT_EXIT_CODE -eq 0 ]; then | |
| echo "TinyIce exited gracefully within 5 seconds. Test passed." | |
| exit 0 # Pass | |
| elif [ $TIMEOUT_EXIT_CODE -eq 124 ]; then | |
| echo "TinyIce ran for more than 5 seconds or was killed by timeout. Test passed (successful startup)." | |
| exit 0 # Pass | |
| else | |
| echo "TinyIce exited with an unexpected error code: $TIMEOUT_EXIT_CODE within 5 seconds. This indicates a startup failure." | |
| exit 1 # Fail | |
| fi | |
| release: | |
| name: Create Release | |
| needs: [build, test_startup] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Generate Checksums | |
| run: | | |
| cd artifacts | |
| # Generate checksums for all binaries in subdirectories | |
| sha256sum tinyice-*/* | sed 's|tinyice-[^/]*/||' > ../checksums.txt | |
| cd .. | |
| - name: Release | |
| uses: softprops/action-gh-release@v2 | |
| if: startsWith(github.ref, 'refs/tags/') | |
| with: | |
| files: | | |
| artifacts/**/tinyice* | |
| checksums.txt | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |