Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Follows these guidelines precisely to ensure consistency and maintainability of

## Stack

- Language: Go (Go 1.22+)
- Language: Go (Go 1.26+)
- Framework: Go standard library
- Testing: Go's built-in testing package
- Dependency Management: Go modules
Expand Down
66 changes: 10 additions & 56 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"
name: CodeQL Advanced

on:
push:
Expand All @@ -19,23 +8,18 @@ on:
schedule:
- cron: "08 12 * * 4"

env:
# Opt in to the new CodeQL default: skip file coverage on PRs for faster analysis.
# Coverage is still computed on push and schedule analyses.
CODEQL_ACTION_FILE_COVERAGE_ON_PRS: false

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

Expand All @@ -47,51 +31,21 @@ jobs:
build-mode: none
- language: go
build-mode: autobuild
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages

steps:
- name: Checkout repository
- name: Check out code
uses: actions/checkout@v6

# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
echo 'Manual build mode is not configured. Set build-mode to "autobuild" or add build commands here.'
exit 1

- name: Perform CodeQL Analysis
Expand Down
106 changes: 86 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,86 @@ permissions:
contents: read

jobs:
build:
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 & Build
needs: test
runs-on: ubuntu-latest
env:
MAKE_DEBUG: true
steps:
- name: Checkout
- name: Check out code
uses: actions/checkout@v6

- name: Set up Go
Expand Down Expand Up @@ -82,39 +158,29 @@ jobs:
mv $TOOL_NAME ~/go/bin/$TOOL_NAME
~/go/bin/$TOOL_NAME --version

# go install github.com/boyter/scc/v3@latest

scc --format html-table . | tee -a $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

- name: Test
- name: Test Coverage
run: |
echo "### Test report" >> $GITHUB_STEP_SUMMARY
set -o pipefail

echo "## Test Coverage" >> $GITHUB_STEP_SUMMARY

go test -race -coverprofile=coverage.txt -covermode=atomic -tags=unit ./... | tee -a $GITHUB_STEP_SUMMARY
make test 2>&1 | tee -a $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

- name: Test coverage
run: |
echo "## Test Coverage" >> $GITHUB_STEP_SUMMARY
go install github.com/vladopajic/go-test-coverage/v2@latest

# Generate coverage report using standard library tools
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Coverage report" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
go tool cover -func=coverage.txt | tee -a $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

# Calculate total coverage percentage
total_coverage=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}')
echo "**Total Coverage:** $total_coverage" >> $GITHUB_STEP_SUMMARY
go-test-coverage --config=./.testcoverage.yml | sed 's/PASS/PASS ✅/g' | sed 's/FAIL/FAIL ❌/g' | tee -a $GITHUB_STEP_SUMMARY

- name: Build
run: |
echo "## Build" >> $GITHUB_STEP_SUMMARY

go build ./... | tee -a $GITHUB_STEP_SUMMARY
make build 2>&1 | tee -a $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Build completed successfully." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
102 changes: 84 additions & 18 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,85 @@ permissions:

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: Checkout
- name: Check out code
uses: actions/checkout@v6

- name: Set up Go
Expand Down Expand Up @@ -85,30 +161,20 @@ jobs:
mv $TOOL_NAME ~/go/bin/$TOOL_NAME
~/go/bin/$TOOL_NAME --version

# go install github.com/boyter/scc/v3@latest

scc --format html-table . | tee -a $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

- name: Test
- name: Test Coverage
run: |
echo "### Test report" >> $GITHUB_STEP_SUMMARY
set -o pipefail

echo "## Test Coverage" >> $GITHUB_STEP_SUMMARY

make test | tee -a $GITHUB_STEP_SUMMARY
make test 2>&1 | tee -a $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

- name: Test coverage
run: |
echo "## Test Coverage" >> $GITHUB_STEP_SUMMARY
go install github.com/vladopajic/go-test-coverage/v2@latest

# Generate coverage report using standard library tools
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Coverage report" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
go tool cover -func=coverage.txt | tee -a $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

# Calculate total coverage percentage
total_coverage=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}')
echo "**Total Coverage:** $total_coverage" >> $GITHUB_STEP_SUMMARY
go-test-coverage --config=./.testcoverage.yml | sed 's/PASS/PASS ✅/g' | sed 's/FAIL/FAIL ❌/g' | tee -a $GITHUB_STEP_SUMMARY
Loading
Loading