-
Notifications
You must be signed in to change notification settings - Fork 18
129 lines (111 loc) · 4.04 KB
/
Copy pathrelease.yml
File metadata and controls
129 lines (111 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
VERSION="${{ github.ref_name }}"
COMMIT="$(git rev-parse HEAD)"
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w -X main.Version=${VERSION} -X main.Commit=${COMMIT}" -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 }}