Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add basic CI functionalities #4

Merged
merged 3 commits into from
Feb 14, 2025
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
39 changes: 39 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Go
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
linters:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.x'
- name: Check vendored dependencies
run: |
go mod tidy
go mod verify
- name: gofmt
run: test -z "$(gofmt -s -l $(find -name '*.go' | grep -v /vendor/))"

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.x'

- name: Build Example
run: go run -mod=mod -v examples/*.go

- name: Vet Test
run: go vet -composites=false -mod=mod ./...
28 changes: 28 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: golangci-lint
on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.63.4
args: --out-format=line-number --timeout=5m
28 changes: 17 additions & 11 deletions cpuid.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2015 Intel Corporation.
// Copyright 2025 the u-root authors. All rights reserved.
// Copyright 2025 the u-root Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -297,16 +297,22 @@ var brandStrings = map[string]int{
"XenVMMXenVMM": XEN,
}

var maxInputValue uint32
var maxExtendedInputValue uint32
var extendedModelId uint32
var extendedFamilyId uint32
var brandIndex uint32
var brandId int
var featureFlags uint64
var thermalAndPowerFeatureFlags uint32
var extendedFeatureFlags uint64
var extraFeatureFlags uint64
// golanci-lint triggers false positives for ”unused” variables
var (
maxInputValue uint32
maxExtendedInputValue uint32
//nolint:unused
extendedModelId uint32
//nolint:unused
extendedFamilyId uint32
//nolint:unused
brandIndex uint32
brandId int
featureFlags uint64
thermalAndPowerFeatureFlags uint32
extendedFeatureFlags uint64
extraFeatureFlags uint64
)

const (
UKNOWN = iota
Expand Down
12 changes: 1 addition & 11 deletions cpuid_amd64.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2015 Intel Corporation.
// Copyright 2025 the u-root Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -39,17 +40,6 @@ func detectFeatures() {
}
}

var leaf02Names = [...]string{
"NULL",
"DATA_CACHE",
"INSTRUCTION_CACHE",
"UNIFIED_CACHE",
"TLB",
"DTLB",
"STLB",
"PREFETCH",
}

func leaf0() {

eax, ebx, ecx, edx := cpuid_low(0, 0)
Expand Down
11 changes: 0 additions & 11 deletions cpuid_amd64_tinygo.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ func detectFeatures() {
}
}

var leaf02Names = [...]string{
"NULL",
"DATA_CACHE",
"INSTRUCTION_CACHE",
"UNIFIED_CACHE",
"TLB",
"DTLB",
"STLB",
"PREFETCH",
}

func leaf0() {

eax, ebx, ecx, edx := cpuid_low(0, 0)
Expand Down
34 changes: 34 additions & 0 deletions examples/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"github.com/u-root/cpuid"
)

func main() {
fmt.Printf("VendorString: %s\n", cpuid.VendorIdentificatorString)

fmt.Printf("Features: ")
for i := uint64(0); i < 64; i++ {
if cpuid.HasFeature(1 << i) {
fmt.Printf("%s ", cpuid.FeatureNames[1<<i])
}
}
fmt.Printf("\n")

fmt.Printf("ExtendedFeatures: ")
for i := uint64(0); i < 64; i++ {
if cpuid.HasExtendedFeature(1 << i) {
fmt.Printf("%s ", cpuid.ExtendedFeatureNames[1<<i])
}
}
fmt.Printf("\n")

fmt.Printf("ExtraFeatures: ")
for i := uint64(0); i < 64; i++ {
if cpuid.HasExtraFeature(1 << i) {
fmt.Printf("%s ", cpuid.ExtraFeatureNames[1<<i])
}
}
fmt.Printf("\n")
}
Loading