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

Chore/move golang code #447

Merged
merged 6 commits into from
Jan 8, 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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ updates:
- 'patch'

- package-ecosystem: gomod
directory: '/action'
directory: '/cmd/firmware-action'
schedule:
interval: 'daily'
time: '00:00'
Expand Down
24 changes: 12 additions & 12 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dependencies:
- changed-files:
- any-glob-to-any-file:
- '.dagger-ci/daggerci/requirements.txt'
- 'action/go.mod'
- 'action/go.sum'
- 'cmd/firmware-action/go.mod'
- 'cmd/firmware-action/go.sum'
docker:
- any:
- changed-files:
Expand Down Expand Up @@ -37,38 +37,38 @@ go:
- changed-files:
- any-glob-to-any-file:
- '*.go'
- 'action/.golangci.yml'
- 'action/.goreleaser.yaml'
- 'action/go.mod'
- 'action/go.sum'
- 'cmd/firmware-action/.golangci.yml'
- 'cmd/firmware-action/.goreleaser.yaml'
- 'cmd/firmware-action/go.mod'
- 'cmd/firmware-action/go.sum'
module/coreboot:
- any:
- changed-files:
- any-glob-to-any-file:
- 'action/recipes/coreboot*'
- 'cmd/firmware-action/recipes/coreboot*'
- 'docker/coreboot/**'
module/edk2:
- any:
- changed-files:
- any-glob-to-any-file:
- 'action/recipes/edk2*'
- 'cmd/firmware-action/recipes/edk2*'
- 'docker/edk2/**'
module/linux:
- any:
- changed-files:
- any-glob-to-any-file:
- 'action/recipes/linux*'
- 'cmd/firmware-action/recipes/linux*'
- 'docker/linux/**'
module/stitching:
- any:
- changed-files:
- any-glob-to-any-file:
- 'action/recipes/stitching*'
- 'cmd/firmware-action/recipes/stitching*'
module/u-root:
- any:
- changed-files:
- any-glob-to-any-file:
- 'action/recipes/uroot*'
- 'cmd/firmware-action/recipes/uroot*'
- 'docker/uroot/**'
python:
- any:
Expand All @@ -89,7 +89,7 @@ testing:
- '.markdownlint.json'
- '.mega-linter.yml'
- '.trivy.yaml'
- 'action/**/*_test.go'
- 'cmd/firmware-action/**/*_test.go'
- 'tests/**'
- head-branch:
- '^test'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- 'docker/**'
- 'tests/**'
- 'action.yml'
- 'action/**'
- 'cmd/firmware-action/**'

# Change detection in action golang code
changes:
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
with:
filters: |
action:
- 'action/**'
- 'cmd/firmware-action/**'
- name: Compile
id: compile
# Require compilation if changes in action golang code or if any breaking changes since last release
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ jobs:
filters: |
changes:
- '.github/workflows/go-test.yml'
- 'action/**'
- 'cmd/firmware-action/**'

go-test-resource-hogs:
# Run tests that take up a lot of system resources separately
runs-on: ubuntu-latest
needs: skip-check
strategy:
fail-fast: false
matrix:
testregex: ['TestLinux', 'TestEdk2', 'TestCoreboot', 'TestStitching', 'TestURoot', 'TestUniversal']
if: ${{ ! (github.event_name == 'pull_request_review' && github.actor != 'github-actions[bot]') && needs.skip-check.outputs.changes == 'true' }}
Expand All @@ -69,11 +70,11 @@ jobs:
go-version: stable
- name: Install go dependencies
run: |
cd action
cd cmd/firmware-action
go get -d ./...
- name: Run go test
run: |
cd action
cd cmd/firmware-action
go test -race -v -timeout 60m -shuffle=on -covermode=atomic -coverprofile coverage.out -run ${{ matrix.testregex }} ./...

go-test:
Expand All @@ -91,9 +92,9 @@ jobs:
go-version: stable
- name: Install go dependencies
run: |
cd action
cd cmd/firmware-action
go get -d ./...
- name: Run go test
run: |
cd action
cd cmd/firmware-action
go test -race -v -timeout 60m -shuffle=on -covermode=atomic -coverprofile coverage.out -skip '(TestLinux|TestEdk2|TestCoreboot|TestStitching|TestUniversal)' ./...
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: action
working-directory: cmd/firmware-action
2 changes: 1 addition & 1 deletion .github/workflows/release-prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# Bump version
- name: Update main.go
run: |
sed -i -E 's/const firmwareActionVersion = .*/const firmwareActionVersion = "${{ steps.semver.outputs.next }}"/g' action/main.go
sed -i -E 's/const firmwareActionVersion = .*/const firmwareActionVersion = "${{ steps.semver.outputs.next }}"/g' cmd/firmware-action/main.go
- name: Update Taskfile.yml
run: |
sed -i -E "s/^ SEMVER: .*/ SEMVER: '${{ steps.semver.outputs.next }}'/g" Taskfile.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: |
git branch --show-current
git pull
echo "version=$(grep 'const firmwareActionVersion' < action/main.go | sed -E 's/.*= "//g' | sed 's/"//g')" >> "${GITHUB_OUTPUT}"
echo "version=$(grep 'const firmwareActionVersion' < cmd/firmware-action/main.go | sed -E 's/.*= "//g' | sed 's/"//g')" >> "${GITHUB_OUTPUT}"
# Can't really use cocogitto here

- name: Create tag
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.coverage
.task
.example_runs
action/coverage.html
action/coverage.out
cmd/firmware-action/coverage.html
cmd/firmware-action/coverage.out
bin/
megalinter-reports
node_modules
action/recipes/__tmp_files__/
cmd/firmware-action/recipes/__tmp_files__/
output-*/
docker/coreboot/coreboot-*
15 changes: 8 additions & 7 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
version: '3'
vars:
SEMVER: 'v0.10.2'
GOLANG_CODE_PATH: 'cmd/firmware-action'

includes:
containers:
Expand All @@ -17,19 +18,19 @@ includes:
tasks:
build-go-binary:
desc: Template task to build a go binary
dir: action
dir: '{{.GOLANG_CODE_PATH}}'
cmds:
- go build -ldflags="-s -w" -o ../bin/firmware-action-{{OS}}-{{ARCH}}-{{.SEMVER}}
- go build -ldflags="-s -w" -o ../../bin/firmware-action-{{OS}}-{{ARCH}}-{{.SEMVER}}
env:
CGO_ENABLED: 0
sources:
- ./**/*.go
generates:
- ../bin/firmware-action-{{OS}}-{{ARCH}}-{{.SEMVER}}
- ../../bin/firmware-action-{{OS}}-{{ARCH}}-{{.SEMVER}}

lint:
desc: Run the linters
dir: action
dir: '{{.GOLANG_CODE_PATH}}'
cmds:
- revive ./...
- go vet ./...
Expand All @@ -39,19 +40,19 @@ tasks:
format:
desc: Run gofumt (fork of gofmt, stricter)
cmds:
- gofumpt -w action
- gofumpt -w '{{.GOLANG_CODE_PATH}}'

test:
desc: Run tests
dir: action
dir: '{{.GOLANG_CODE_PATH}}'
cmds:
- go test {{.CLI_ARGS}} -race -timeout 60m -shuffle=on -covermode=atomic -coverprofile coverage.out ./...
- go tool cover -func=coverage.out
- go tool cover -html=coverage.out -o coverage.html

godocs:
desc: Start godocs http server
dir: action
dir: '{{.GOLANG_CODE_PATH}}'
cmds:
- godoc -http=:6060

Expand Down
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ runs:
- name: compile_unix
if: ${{ ( runner.os == 'Linux' || runner.os == 'macOS' ) && inputs.compile == 'true' }}
shell: bash
working-directory: ./action
working-directory: ./cmd/firmware-action
run: |
go build -ldflags="-s -w" -o ../firmware-action
go build -ldflags="-s -w" -o ../../firmware-action

- id: fetch_windows
if: ${{ runner.os == 'Windows' && inputs.compile == 'false' }}
Expand All @@ -106,9 +106,9 @@ runs:
- name: compile_windows
if: ${{ runner.os == 'Windows' && inputs.compile == 'true' }}
shell: pwsh
working-directory: ./action
working-directory: ./cmd/firmware-action
run: |
go build -ldflags="-s -w" -o ../firmware-action.exe
go build -ldflags="-s -w" -o ../../firmware-action.exe

- name: run_unix
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/logging"
"github.com/9elements/firmware-action/logging"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/filesystem"
"github.com/9elements/firmware-action/filesystem"
"github.com/stretchr/testify/assert"
)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion action/go.mod → cmd/firmware-action/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/9elements/firmware-action/action
module github.com/9elements/firmware-action

go 1.22.5

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func InitLogger(level slog.Level, opts ...PrettyHandlerOption) {
// TrimNameFunction just trims the name
func TrimNameFunction(pc uintptr) string {
// 'runtime.FuncForPC(pc).Name()' is nice and all, but it will return this monstrosity:
// github.com/9elements/firmware-action/action/<package>.<func>...
// github.com/9elements/firmware-action/<package>.<func>...
// So this function is just to trim it down
// Usage:
// pc, _, _, _ := runtime.Caller(0)
Expand Down
6 changes: 3 additions & 3 deletions action/main.go → cmd/firmware-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"os"
"regexp"

"github.com/9elements/firmware-action/action/filesystem"
"github.com/9elements/firmware-action/action/logging"
"github.com/9elements/firmware-action/action/recipes"
"github.com/9elements/firmware-action/filesystem"
"github.com/9elements/firmware-action/logging"
"github.com/9elements/firmware-action/recipes"
"github.com/alecthomas/kong"
"github.com/go-git/go-git/v5"
"github.com/jedib0t/go-pretty/v6/table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"strings"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/container"
"github.com/9elements/firmware-action/action/logging"
"github.com/9elements/firmware-action/container"
"github.com/9elements/firmware-action/logging"
"github.com/go-playground/validator/v10"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"strings"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/container"
"github.com/9elements/firmware-action/action/filesystem"
"github.com/9elements/firmware-action/action/logging"
"github.com/9elements/firmware-action/container"
"github.com/9elements/firmware-action/filesystem"
"github.com/9elements/firmware-action/logging"
)

// BlobDef is used to store information about a single blob.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/filesystem"
"github.com/9elements/firmware-action/filesystem"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestCoreboot(t *testing.T) {
assert.NoError(t, err)

// Copy over defconfig file into tmpDir
repoRootPath, err := filepath.Abs(filepath.Join(pwd, "../.."))
repoRootPath, err := filepath.Abs(filepath.Join(pwd, "../../.."))
assert.NoError(t, err)
// repoPath = path to end user repository (in this case somewhere in /tmp)
// repoRootPath = path to our repository with this code (contains configuration files for testing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"runtime"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/container"
"github.com/9elements/firmware-action/container"
)

// ANCHOR: Edk2Specific
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"strings"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/container"
"github.com/9elements/firmware-action/action/logging"
"github.com/9elements/firmware-action/container"
"github.com/9elements/firmware-action/logging"
)

var errUnknownArchCrossCompile = errors.New("unknown architecture for cross-compilation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/filesystem"
"github.com/9elements/firmware-action/filesystem"
"github.com/Masterminds/semver"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestLinux(t *testing.T) {

// Copy over defconfig file into tmpDir/linux
defconfigPath := filepath.Join(myLinuxOpts.RepoPath, myLinuxOpts.DefconfigPath)
repoRootPath, err := filepath.Abs(filepath.Join(pwd, "../.."))
repoRootPath, err := filepath.Abs(filepath.Join(pwd, "../../.."))
assert.NoError(t, err)
// common.RepoPath = path to end user repository (in this case somewhere in /tmp)
// repoRootPath = path to our repository with this code (contains configuration files for testing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"sync"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/container"
"github.com/9elements/firmware-action/action/filesystem"
"github.com/9elements/firmware-action/container"
"github.com/9elements/firmware-action/filesystem"
"github.com/heimdalr/dag"
)

Expand Down
Loading
Loading