-
-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (143 loc) · 6.39 KB
/
pr.yml
File metadata and controls
180 lines (143 loc) · 6.39 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
178
179
180
name: Pull Request
on:
pull_request:
branches:
- main
permissions:
contents: read
pull-requests: read
jobs:
test:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: ./go.mod
- name: Test
run: go test -v -race -tags=unit ./...
- name: Build CLI
run: go build -v -o ${{ runner.temp }}/machineid${{ matrix.os == 'windows-latest' && '.exe' || '' }} ./cmd/machineid/
- name: Generate machine ID (smoke test)
shell: bash
run: |
BIN="${{ runner.temp }}/machineid${{ matrix.os == 'windows-latest' && '.exe' || '' }}"
echo "--- Version ---"
"$BIN" -version
echo "--- Default ID (CPU + motherboard + UUID) ---"
ID=$("$BIN")
echo "ID: $ID"
echo "Length: ${#ID}"
# Verify the ID is a 64-char hex string
if [[ ${#ID} -ne 64 ]]; then
echo "ERROR: expected 64-char ID, got ${#ID}"
exit 1
fi
if [[ ! "$ID" =~ ^[0-9a-f]{64}$ ]]; then
echo "ERROR: ID is not a valid hex string"
exit 1
fi
echo "--- Validate round-trip ---"
"$BIN" -validate "$ID"
# Exercise additional CLI modes.
# On Windows CI, WMI can be transiently unavailable after repeated
# invocations, so these are non-fatal — the core validation above
# already proved the binary works.
ERRORS=0
echo "--- All components (JSON + diagnostics) ---"
"$BIN" -all -json -diagnostics || { echo "WARN: -all failed (non-fatal)"; ERRORS=$((ERRORS+1)); }
echo "--- VM-friendly ---"
"$BIN" -vm || { echo "WARN: -vm failed (non-fatal)"; ERRORS=$((ERRORS+1)); }
echo "--- Format 32 ---"
"$BIN" -format 32 || { echo "WARN: -format 32 failed (non-fatal)"; ERRORS=$((ERRORS+1)); }
echo "--- Salt ---"
"$BIN" -salt "ci-test" || { echo "WARN: -salt failed (non-fatal)"; ERRORS=$((ERRORS+1)); }
if [[ $ERRORS -gt 0 ]]; then
echo "WARN: $ERRORS non-critical exercise(s) failed on ${{ matrix.os }} (WMI transient issue)"
fi
echo "Smoke test passed on ${{ matrix.os }}"
report:
name: Report
needs: test
runs-on: ubuntu-latest
env:
MAKE_DEBUG: true
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: ./go.mod
- name: Summary Information
run: |
echo "# Pull Request Summary" > $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Repository:** ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
echo "**Pull Request:** ${{ github.event.pull_request.title }}" >> $GITHUB_STEP_SUMMARY
echo "**Author:** ${{ github.event.pull_request.user.login }}" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ github.event.pull_request.head.ref }}" >> $GITHUB_STEP_SUMMARY
echo "**Base:** ${{ github.event.pull_request.base.ref }}" >> $GITHUB_STEP_SUMMARY
echo "**Commits:** ${{ github.event.pull_request.commits }}" >> $GITHUB_STEP_SUMMARY
echo "**Changed Files:** ${{ github.event.pull_request.changed_files }}" >> $GITHUB_STEP_SUMMARY
echo "**Additions:** ${{ github.event.pull_request.additions }}" >> $GITHUB_STEP_SUMMARY
echo "**Deletions:** ${{ github.event.pull_request.deletions }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Tools and versions
run: |
echo "## Tools and versions" >> $GITHUB_STEP_SUMMARY
ubuntu_version=$(lsb_release -a 2>&1 | grep "Description" | awk '{print $2, $3, $4}')
echo "Ubuntu version: $ubuntu_version"
echo "**Ubuntu Version:** $ubuntu_version" >> $GITHUB_STEP_SUMMARY
bash_version=$(bash --version | head -n 1 | awk '{print $4}')
echo "Bash version: $bash_version"
echo "**Bash Version:** $bash_version" >> $GITHUB_STEP_SUMMARY
git_version=$(git --version | awk '{print $3}')
echo "Git version: $git_version"
echo "**Git Version:** $git_version" >> $GITHUB_STEP_SUMMARY
go_version=$(go version | awk '{print $3}')
echo "Go version: $go_version"
echo "**Go Version:** $go_version" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Lines of code
env:
GH_TOKEN: ${{ github.token }}
run: |
export TOOL_NAME="scc"
export GIT_ORG="boyter"
export GIT_REPO="scc"
export OS=$(uname -s)
export OS_ARCH=$(uname -m)
# Normalize architecture names to match asset naming
[[ "$OS_ARCH" == "aarch64" ]] && OS_ARCH="arm64"
[[ "$OS_ARCH" == "x86_64" ]] && OS_ARCH="x86_64"
export ASSETS_NAME=$(gh release view --repo ${GIT_ORG}/${GIT_REPO} --json assets -q "[.assets[] | select(.name | contains(\"${TOOL_NAME}\") and contains(\"${OS}\") and contains(\"${OS_ARCH}\"))] | sort_by(.createdAt) | last.name")
gh release download --repo $GIT_ORG/$GIT_REPO --pattern $ASSETS_NAME
# Extract based on file extension
if [[ "$ASSETS_NAME" == *.tar.gz ]]; then
tar -xzf $ASSETS_NAME
elif [[ "$ASSETS_NAME" == *.zip ]]; then
unzip $ASSETS_NAME
fi
rm $ASSETS_NAME
mv $TOOL_NAME ~/go/bin/$TOOL_NAME
~/go/bin/$TOOL_NAME --version
scc --format html-table . | tee -a $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Test Coverage
run: |
set -o pipefail
echo "## Test Coverage" >> $GITHUB_STEP_SUMMARY
make test 2>&1 | tee -a $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
go install github.com/vladopajic/go-test-coverage/v2@latest
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Coverage report" >> $GITHUB_STEP_SUMMARY
go-test-coverage --config=./.testcoverage.yml | sed 's/PASS/PASS ✅/g' | sed 's/FAIL/FAIL ❌/g' | tee -a $GITHUB_STEP_SUMMARY