-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
177 lines (164 loc) · 6.16 KB
/
action.yml
File metadata and controls
177 lines (164 loc) · 6.16 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: 'Setup mockd'
description: 'Install and optionally start the mockd mock server for integration testing'
author: 'Mockd LLC'
branding:
icon: 'server'
color: 'purple'
inputs:
version:
description: 'mockd version to install (e.g., "0.4.4"). Default: latest release.'
required: false
default: 'latest'
github-token:
description: 'GitHub token for API requests (avoids rate limiting when resolving latest version)'
required: false
default: ${{ github.token }}
start:
description: 'Start mockd server in background after install'
required: false
default: 'false'
config:
description: 'Path to mockd.yaml config file to load on start'
required: false
port:
description: 'Mock server port (default: 4280)'
required: false
default: '4280'
admin-port:
description: 'Admin API port (default: 4290)'
required: false
default: '4290'
log-level:
description: 'Server log level: debug, info, warn, error'
required: false
default: 'warn'
outputs:
version:
description: 'Installed mockd version'
value: ${{ steps.install.outputs.version }}
mockd-url:
description: 'Mock server base URL (e.g., http://localhost:4280)'
value: ${{ steps.start-server.outputs.mockd-url }}
admin-url:
description: 'Admin API base URL (e.g., http://localhost:4290)'
value: ${{ steps.start-server.outputs.admin-url }}
cache-hit:
description: 'Whether the binary was found in cache'
value: ${{ steps.cache.outputs.cache-hit }}
runs:
using: 'composite'
steps:
- name: Resolve version
id: resolve
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ inputs.github-token }}
run: |
if [ "$INPUT_VERSION" = "latest" ]; then
VERSION=$(gh api repos/getmockd/mockd/releases/latest --jq '.tag_name' | sed 's/^v//')
echo "Resolved latest version: $VERSION"
else
VERSION=$(echo "$INPUT_VERSION" | sed 's/^v//')
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Detect platform
id: platform
shell: bash
run: |
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) echo "::error::Unsupported architecture: $ARCH"; exit 1 ;;
esac
case "$OS" in
linux|darwin) ;;
mingw*|msys*|cygwin*) OS="windows" ;;
*) echo "::error::Unsupported OS: $OS"; exit 1 ;;
esac
BINARY="mockd-${OS}-${ARCH}"
[ "$OS" = "windows" ] && BINARY="${BINARY}.exe"
echo "os=$OS" >> "$GITHUB_OUTPUT"
echo "arch=$ARCH" >> "$GITHUB_OUTPUT"
echo "binary=$BINARY" >> "$GITHUB_OUTPUT"
- name: Cache mockd binary
id: cache
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/mockd-bin
key: mockd-${{ steps.resolve.outputs.version }}-${{ steps.platform.outputs.os }}-${{ steps.platform.outputs.arch }}
- name: Download mockd
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
env:
VERSION: ${{ steps.resolve.outputs.version }}
BINARY: ${{ steps.platform.outputs.binary }}
run: |
mkdir -p "$RUNNER_TEMP/mockd-bin"
BASE_URL="https://github.com/getmockd/mockd/releases/download/v${VERSION}"
URL="${BASE_URL}/${BINARY}"
echo "Downloading mockd v${VERSION} from ${URL}"
curl -fsSL -o "$RUNNER_TEMP/mockd-bin/mockd" "$URL"
# Try per-binary .sha256 sidecar first, fall back to checksums.txt
EXPECTED=""
if curl -fsSL -o "$RUNNER_TEMP/mockd-bin/mockd.sha256" "${URL}.sha256" 2>/dev/null; then
EXPECTED=$(awk '{print $1}' "$RUNNER_TEMP/mockd-bin/mockd.sha256")
echo "Using per-binary checksum sidecar"
elif curl -fsSL -o "$RUNNER_TEMP/mockd-bin/checksums.txt" "${BASE_URL}/checksums.txt" 2>/dev/null; then
EXPECTED=$(grep " ${BINARY}$" "$RUNNER_TEMP/mockd-bin/checksums.txt" | awk '{print $1}')
echo "Using checksums.txt (sidecar not found)"
fi
if [ -z "$EXPECTED" ]; then
echo "::warning::No checksum found for ${BINARY} — skipping verification"
else
ACTUAL=$(sha256sum "$RUNNER_TEMP/mockd-bin/mockd" | awk '{print $1}')
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "::error::SHA256 checksum mismatch! Expected: $EXPECTED, Got: $ACTUAL"
exit 1
fi
echo "Checksum verified: $ACTUAL"
fi
chmod +x "$RUNNER_TEMP/mockd-bin/mockd"
- name: Install mockd
id: install
shell: bash
env:
VERSION: ${{ steps.resolve.outputs.version }}
run: |
echo "$RUNNER_TEMP/mockd-bin" >> "$GITHUB_PATH"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
"$RUNNER_TEMP/mockd-bin/mockd" version
echo "::notice::mockd v${VERSION} installed"
- name: Start mockd server
id: start-server
if: inputs.start == 'true'
shell: bash
env:
PORT: ${{ inputs.port }}
ADMIN_PORT: ${{ inputs.admin-port }}
LOG_LEVEL: ${{ inputs.log-level }}
CONFIG: ${{ inputs.config }}
run: |
ARGS="--no-auth --port $PORT --admin-port $ADMIN_PORT --log-level $LOG_LEVEL"
[ -n "$CONFIG" ] && ARGS="$ARGS --config $CONFIG"
echo "Starting mockd serve $ARGS"
nohup "$RUNNER_TEMP/mockd-bin/mockd" serve $ARGS > "$RUNNER_TEMP/mockd.log" 2>&1 &
PID=$!
echo "$PID" > "$RUNNER_TEMP/mockd.pid"
echo "mockd started with PID $PID"
# Wait for health check
for i in $(seq 1 30); do
if curl -sf "http://localhost:${ADMIN_PORT}/health" > /dev/null 2>&1; then
echo "mockd is healthy after ${i}s"
echo "mockd-url=http://localhost:${PORT}" >> "$GITHUB_OUTPUT"
echo "admin-url=http://localhost:${ADMIN_PORT}" >> "$GITHUB_OUTPUT"
echo "::notice::mockd server running on :${PORT} (admin :${ADMIN_PORT})"
exit 0
fi
sleep 1
done
echo "::error::mockd failed to start within 30s"
cat "$RUNNER_TEMP/mockd.log"
exit 1