Skip to content

Commit 40339b3

Browse files
authored
Merge pull request #3 from jpnt/alpha
Alpha
2 parents c58c038 + 894a05a commit 40339b3

File tree

12 files changed

+54
-71
lines changed

12 files changed

+54
-71
lines changed

.github/workflows/cicd.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
architecture: [amd64, arm64, 386, riscv64]
21+
architecture: [amd64, 386, arm64, arm, riscv64, mips, mips64, mips64le, mipsle, ppc64, ppc64le, s390x]
2222

2323
steps:
2424
- name: Checkout code
@@ -27,14 +27,15 @@ jobs:
2727
- name: Set up Go
2828
uses: actions/setup-go@v4
2929
with:
30-
go-version: '1.23'
30+
go-version: '1.24.1'
3131

3232
- name: Run tests
3333
run: go test -v ./...
3434

3535
- name: Build
3636
run: |
37-
GOARCH=${{ matrix.architecture }} GOOS=linux go build -ldflags="-s -w" -v -o kman-${{ matrix.architecture }} ./cmd/kman/kman.go
37+
VERSION=$(echo "${GITHUB_REF#refs/tags/v}" )
38+
GOARCH=${{ matrix.architecture }} GOOS=linux go build -ldflags="-s -w" -v -o kman-${{ matrix.architecture }}-${VERSION} ./cmd/kman/
3839
3940
- name: Display structure of files
4041
run: ls -lRha

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ chmod +x kman-amd64
2222
4. Verify installation
2323

2424
```sh
25-
kman -version
25+
kman --version
2626
```
2727

2828
### Via Go get (for go devs)
@@ -41,7 +41,9 @@ go build -o kman ./cmd/kman
4141
kman --version
4242
```
4343

44-
## Examples
44+
## kman CLI Usage Examples
45+
46+
TODO
4547

4648
- Run everything (download, compile, install, etc)
4749

@@ -81,17 +83,15 @@ $ kman install,bootloader,initramfs --dir=./kernel-6.9.9 --initramfs=booster
8183

8284
## Pipeline Steps
8385

84-
Each step in the pipeline can be executed indidually, but requires some parameter/s.
85-
86-
- Download (url)
87-
- Verify (archive)
88-
- Extract (archive)
89-
- Patch (optional: directory)
90-
- Configure (optional: .config file, directory, njobs)
91-
- Compile (optional: directory)
92-
- Install (optional: directory)
93-
- Initramfs (optional: initramfs)
94-
- Bootloader (optional: bootloader)
86+
- Download
87+
- Verify
88+
- Extract
89+
- Patch
90+
- Configure
91+
- Compile
92+
- Install
93+
- Initramfs
94+
- Bootloader
9595

9696
### Architecture
9797

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/jpnt/kman
22

3-
go 1.23.0
3+
go 1.24.1

internal/core/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type KernelContext struct {
1616
SignatureURL string
1717
ConfigOptions []string
1818
OldConfigPath string
19-
NumJobs string
2019
Initramfs string
2120
Bootloader string
21+
NumJobs int
2222
}
2323

2424
var _ IKernelContext = (*KernelContext)(nil)

internal/core/pipeline.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ type Pipeline struct {
2121
var _ IPipeline = (*Pipeline)(nil)
2222

2323
func (pl *Pipeline) Run() error {
24-
if len(pl.steps) == 0 {
24+
numSteps := len(pl.steps)
25+
var stepNames []string
26+
27+
if numSteps == 0 {
2528
return fmt.Errorf("no steps were configured")
2629
}
2730

28-
pl.log.Info("The following steps will be executed:")
2931
for _, step := range pl.steps {
30-
pl.log.Info("- %s", step.Name())
32+
stepNames = append(stepNames, step.Name())
3133
}
3234

33-
pl.log.Info("Starting execution ...")
35+
pl.log.Info("Executing %d steps: %v", numSteps, stepNames)
3436

35-
for _, step := range pl.steps {
37+
for i, step := range pl.steps {
3638
start := time.Now()
37-
pl.log.Info("==> Starting step: %s ...", step.Name())
39+
pl.log.Info("==> Starting step [%d/%d]: %s", i+1, numSteps, step.Name())
3840

3941
if err := pl.ctx.Validate(step.Name()); err != nil {
4042
return fmt.Errorf("validation failed for step %q: %w", step.Name(), err)
@@ -45,7 +47,7 @@ func (pl *Pipeline) Run() error {
4547
}
4648

4749
duration := time.Since(start)
48-
pl.log.Info("<== Completed step: %s in %s", step.Name(), duration)
50+
pl.log.Info("<== Completed step [%d/%d]: %s in %s", i+1, numSteps, step.Name(), duration)
4951
}
5052
return nil
5153
}

internal/core/pipeline_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewPipelineBuilder(l logger.ILogger, f IStepFactory, c IKernelContext) IPip
2929
func (b *PipelineBuilder) WithStep(stepName string) IPipelineBuilder {
3030
step, err := b.factory.CreateStep(stepName, b.logger, b.ctx)
3131
if err != nil {
32-
b.logger.Warn("Failed to create step %s: %s", stepName, err)
32+
b.logger.Warn("Could not create step %q: %s", stepName, err)
3333
return b
3434
}
3535
b.steps = append(b.steps, step)

internal/service/compile.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package service
22

33
import (
4-
// "errors"
54
"fmt"
65
"os"
76
"os/exec"
87

98
"github.com/jpnt/kman/internal/core"
109
"github.com/jpnt/kman/pkg/logger"
11-
// "github.com/jpnt/kman/pkg/utils"
1210
)
1311

1412
type CompileStep struct {
1513
log *logger.Logger
16-
ctx *core.KernelContext
14+
ctx *core.KernelContext
1715
}
1816

1917
var _ core.IStep = (*CompileStep)(nil)
@@ -22,24 +20,25 @@ func (s *CompileStep) Name() string {
2220
return "compile"
2321
}
2422

25-
// TODO
2623
func (s *CompileStep) Execute() error {
2724
dir := s.ctx.Directory
28-
// njobs := s.ctx.njobs // TODO
29-
njobs := 1
30-
njobsStr := fmt.Sprintf("-j%d", njobs)
3125

32-
s.log.Info("Compiling Linux kernel: 'make -C %s %s' ...", dir, njobsStr)
26+
if s.ctx.NumJobs == 0 {
27+
defaultNumJobs := 1
28+
s.log.Warn("Number of jobs not configured, defaulting to %d", defaultNumJobs)
29+
s.ctx.NumJobs = defaultNumJobs
30+
}
31+
32+
numJobsStr := fmt.Sprintf("-j%d", s.ctx.NumJobs)
33+
34+
s.log.Info("Compiling Linux kernel using 'make -C %s %s' ...", dir, numJobsStr)
3335

34-
cmd := exec.Command("make", "-C", dir, njobsStr)
36+
cmd := exec.Command("make", "-C", dir, numJobsStr)
3537
cmd.Stdout = os.Stdout
3638
cmd.Stderr = os.Stderr
3739

3840
if err := cmd.Run(); err != nil {
3941
return fmt.Errorf("kernel compilation failed: %w", err)
4042
}
41-
42-
s.log.Info("Compiled Linux kernel")
43-
4443
return nil
4544
}

internal/service/configure.go

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,44 @@ type ConfigureStep struct {
1919

2020
var _ core.IStep = (*ConfigureStep)(nil)
2121

22-
var defaultOptions = []string{"defconfig"}
23-
var validOptions = []string{"defconfig", "menuconfig", "nconfig", "oldconfig"}
24-
2522
func (s *ConfigureStep) Name() string {
2623
return "configure"
2724
}
2825

2926
func (s *ConfigureStep) Execute() error {
3027
if s.ctx.ConfigOptions == nil {
31-
s.log.Info("No config options were detected, setting up default options ...")
32-
s.ctx.ConfigOptions = defaultOptions
33-
}
34-
35-
// TODO: better option than doing this
36-
configOptions := s.ctx.ConfigOptions
37-
for _, opt := range configOptions {
38-
if !isValidOption(opt) {
39-
return fmt.Errorf("invalid configuration option: %s", opt)
40-
}
28+
defaultConfigOptions := []string{"tinyconfig"}
29+
s.log.Warn("Kernel config options not provided, defaulting to %s", defaultConfigOptions)
30+
s.ctx.ConfigOptions = defaultConfigOptions
4131
}
4232

4333
if err := s.copyOldConfig(); err != nil {
4434
return fmt.Errorf("failed to copy .config: %w", err)
4535
}
4636

47-
s.log.Info("Configuring Linux kernel with: %v ...", configOptions)
48-
4937
dir := s.ctx.Directory
5038
if err := os.Chdir(dir); err != nil {
51-
return fmt.Errorf("failed to change directory to %s: %w", dir, err)
39+
return fmt.Errorf("failed to change directory to %q: %w", dir, err)
5240
}
5341

54-
for _, opt := range configOptions {
55-
cmd := exec.Command("make", opt)
42+
for _, option := range s.ctx.ConfigOptions {
43+
s.log.Info("Configuring Linux kernel with: 'make %s' ...", option)
44+
45+
cmd := exec.Command("make", option)
5646
cmd.Stdout = os.Stdout
5747
cmd.Stderr = os.Stderr
5848

5949
if err := cmd.Run(); err != nil {
6050
return fmt.Errorf("kernel configuration failed: %w", err)
6151
}
6252
}
53+
6354
return nil
6455
}
6556

6657
func (s *ConfigureStep) copyOldConfig() error {
6758
if s.ctx.OldConfigPath == "" {
68-
s.log.Warn("Skipping copy of old .config file")
59+
s.log.Warn("Old .config path not provided, skipping ...")
6960
return nil
7061
}
7162

@@ -84,12 +75,3 @@ func (s *ConfigureStep) copyOldConfig() error {
8475
}
8576
return nil
8677
}
87-
88-
func isValidOption(option string) bool {
89-
for _, validOption := range validOptions {
90-
if option == validOption {
91-
return true
92-
}
93-
}
94-
return false
95-
}

internal/service/download.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ func (s *DownloadStep) Execute() error {
2828
return err
2929
}
3030

31-
s.log.Info("Downloaded Linux kernel tarball to: %s", kernelPath)
3231
s.ctx.ArchivePath = kernelPath
33-
32+
s.log.Info("Downloaded Linux kernel tarball to: %s", kernelPath)
3433
return nil
3534
}

internal/service/extract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
type ExtractStep struct {
1414
log *logger.Logger
15-
ctx *core.KernelContext
15+
ctx *core.KernelContext
1616
}
1717

1818
// Ensure struct implements interface

0 commit comments

Comments
 (0)