CI: Refactor startup test to separate job with dynamic architecture d… #230
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}/tinyice-linux-${GOARCH}" | |
| echo "Starting TinyIce in background for 5 seconds to check for startup errors..." | |
| # Use a non-default port and tmp config to avoid conflicts | |
| timeout 5s sh -c "$BINARY_PATH -port 8080 -config /tmp/tinyice-test-linux-${GOARCH}.json" & | |
| PID=$! | |
| # Wait for the process to finish for up to 6 seconds (slightly more than timeout) | |
| if ! wait $PID; then | |
| EXIT_CODE=$? | |
| if [ $EXIT_CODE -eq 124 ]; then | |
| echo "TinyIce ran for more than 5 seconds or was killed by timeout. This is considered a pass (successful startup)." | |
| exit 0 # Treat timeout as success (program didn't crash immediately) | |
| else | |
| echo "TinyIce exited with an unexpected error code: $EXIT_CODE within 5 seconds. This indicates a startup failure." | |
| exit 1 # Treat any other non-zero exit code as failure | |
| fi | |
| else | |
| # Process exited naturally within 5 seconds | |
| EXIT_CODE=$? | |
| if [ $EXIT_CODE -eq 0 ]; then | |
| echo "TinyIce exited gracefully within 5 seconds. This is considered a pass (successful short-lived execution)." | |
| exit 0 # Treat graceful exit as success | |
| else | |
| echo "TinyIce exited with an error code: $EXIT_CODE within 5 seconds. This indicates a startup failure." | |
| exit 1 # Treat non-zero exit code as failure | |
| fi | |
| 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 }} |