Skip to content

Commit

Permalink
feat: add versioning system, improve environment management
Browse files Browse the repository at this point in the history
  • Loading branch information
seppzer0 committed Sep 10, 2024
1 parent 697368c commit f7bfc81
Show file tree
Hide file tree
Showing 18 changed files with 987 additions and 66 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23"
cache: true
- name: Export Environment Variables
run: |
echo "APP_VERSION=$(bash scripts/get_version.sh)" >> $GITHUB_ENV
echo "GO_VERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/release_candidate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release Candidate

on:
push:
branches:
- main

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23"
cache: true
- name: Export Environment Variables
run: |
echo "APP_VERSION=$(bash scripts/get_version.sh)" >> $GITHUB_ENV
echo "GO_VERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/cache
/build
agb/dist
lint_report.json
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions .goreleaser.yaml → agb/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ before:
- go mod tidy
- go mod download

upx:
- enabled: true
compress: best
lzma: true
# TODO: delete this string when upx fix segfault
# https://github.com/upx/upx/issues/612
goos: [linux, windows]

builds:
- id: "agb"
main: ./cmd/agb
binary: agb
flags:
- -o=./build
ldflags:
- -X 'agb/config.appVersion={{ .Env.APP_VERSION }}' -X 'agb/config.goVersion={{ .Env.GO_VERSION }}'
env:
- CGO_ENABLED=0
goos:
Expand All @@ -32,11 +28,14 @@ archives:
format: zip
builds:
- "agb"
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
name_template: "{{ .ProjectName }}_{{ .Env.APP_VERSION }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: "{{ .ProjectName }}_{{ .Env.APP_VERSION }}_{{ .Os }}_{{ .Arch }}"
files:
- docs/
- scripts/
- Dockerfile
- LICENSE.md
- README.md

release:
draft: true
23 changes: 19 additions & 4 deletions agb/cmd/agb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// newBuildCmd registers the "build" command.
func newBuildCmd() *cobra.Command {
var (
linuxKernelVersion float64
linuxKernelVersion string
androidVersion int
patchVersion string
defconfigPath string
Expand Down Expand Up @@ -54,11 +54,11 @@ func newBuildCmd() *cobra.Command {
}

flags := command.Flags()
flags.Float64VarP(
flags.StringVarP(
&linuxKernelVersion,
"linux-kernel-version",
"l",
0,
"",
"Linux kernel version number (required)",
)
flags.IntVarP(
Expand Down Expand Up @@ -94,7 +94,7 @@ func newBuildCmd() *cobra.Command {
"clang-url",
"c",
"https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/eed2fff8b93ce059eea7ccd8fc5eee37f8adb432/clang-r458507.tar.gz",
"path to a Clang pre-build zip",
"URL to a prebuilt Clang",
)
flags.StringVarP(
&sourceLocation,
Expand Down Expand Up @@ -134,13 +134,28 @@ func newCleanCmd() *cobra.Command {
}
}

// newVersionCmd registers the "version" command.
func newVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Show version information.",
RunE: func(cmd *cobra.Command, args []string) error {
command_obj := command.NewVersionCommand()

res := command_obj.Execute()
return res
},
}
}

func main() {
rootCmd := &cobra.Command{
Use: "agb",
Short: "Android GKI Builder.",
}

rootCmd.AddCommand(newBuildCmd())
rootCmd.AddCommand(newVersionCmd())
rootCmd.AddCommand(newCleanCmd())

rootCmd.Execute()
Expand Down
6 changes: 3 additions & 3 deletions agb/command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// BuildCommand is a representation of "build" command.
type BuildCommand struct {
LinuxKernelVersion float64
LinuxKernelVersion string
AndroidVersion int
PatchVersion string
DefconfigPath string
Expand All @@ -17,9 +17,9 @@ type BuildCommand struct {
KernelSu bool
}

// Create new instance of BuildCommand.
// NewBuildCommand creates new instance of BuildCommand.
func NewBuildCommand(
lkv float64,
lkv string,
av int,
pv string,
dp string,
Expand Down
6 changes: 6 additions & 0 deletions agb/command/clean.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package command

// CleanCommand is a representation of "version" command.
type CleanCommand struct{}

// NewCleanCommand creates new instance of CleanCommand
func NewCleanCommand() *CleanCommand {
return &CleanCommand{}
}
23 changes: 23 additions & 0 deletions agb/command/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package command

import (
"agb/config"
"fmt"
)

// VersionCommand is a representation of "version" command.
type VersionCommand struct{}

// NewVersionCommand creates new instance of VersionCommand
func NewVersionCommand() *VersionCommand {
return &VersionCommand{}
}

// Execute runs "version" command's logic.
func (vc *VersionCommand) Execute() error {
version_config := config.NewVersionConfig()
app_version, go_version := version_config.AppVersion, version_config.GoVersion

fmt.Printf("agb version %s, built with %s\n", app_version, go_version)
return nil
}
21 changes: 21 additions & 0 deletions agb/config/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package config

var (
// this data should be overriden during compilation
appVersion = "v0.0.0"
goVersion = "v0.0.0"
)

// VersionConfig is a version info holder updated dynamically during compilation.
type VersionConfig struct {
AppVersion string
GoVersion string
}

// NewVersionConfig returns new instance of VersionConfig
func NewVersionConfig() *VersionConfig {
return &VersionConfig{
AppVersion: appVersion,
GoVersion: goVersion,
}
}
53 changes: 19 additions & 34 deletions agb/core/gki.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
cerror "agb/error"
"agb/manager"
"agb/tool"
"strconv"
)

// GkiBuilder is a core module responsible for building GKI.
type GkiBuilder struct {
LinuxKernelVersion float64
LinuxKernelVersion string
AndroidVersion int
PatchVersion string
DefconfigPath string
Expand All @@ -18,9 +19,9 @@ type GkiBuilder struct {
resourceManager *manager.ResourceManager
}

// NewGkiBuilder creates a new instance of GkiBuilder.
// NewGkiBuilder creates new instance of GkiBuilder.
func NewGkiBuilder(
lkv float64,
lkv string,
av int,
pv string,
dp string,
Expand All @@ -41,56 +42,40 @@ func NewGkiBuilder(
}
}

// validateEnd checks that everything necessary is present in build environment.
func (gb *GkiBuilder) validateEnv() bool {
return true
}

// CleanEnvironment resets the build environment.
func (gb *GkiBuilder) CleanEnvironment() error {
return nil
}

// patchAnyKernel3 patches AnyKernel3's files to package the kernel image.
func (gb *GkiBuilder) patchAnykernel3() error {
return nil
}

// AddKsu introduces KernelSU support into the kernel (GKI mode).
func (gb *GkiBuilder) addKsu() error {
return nil
}

// determineKernelVersion determines Linux kernel version directly from sources.
func (gb *GkiBuilder) determineKernelVersion() float64 {
return 3.14
}

// Patch applies all necessary modifications for the kernel build.
func (gb *GkiBuilder) Patch() error {
return nil
}

// Prepare runs all the preparations for the build.
func (gb *GkiBuilder) Prepare() error {
// by default, assume that Clang is not required
clang_required := false

lkv_float, err := strconv.ParseFloat(gb.LinuxKernelVersion, 32)
if err != nil {
return cerror.ErrGeneric{Message: "Could not convert kernel version to float"}
}

// for regular GKI sources, separate Clang is not required
if !(gb.LinuxKernelVersion >= 5.10) {
if !(lkv_float >= 5.10) {
clang_required = true
if err := gb.resourceManager.GetCompiler(); err != nil {
return err
}
}

if err := gb.resourceManager.CleanKernelSource(); err != nil {
if err := gb.resourceManager.ValidateEnv(clang_required); err != nil {
return err
}

if err := gb.resourceManager.GetSource(gb.AndroidVersion, gb.LinuxKernelVersion, gb.PatchVersion); err != nil {
if err := gb.resourceManager.CleanArtifacts(); err != nil {
return err
}

//if gb.determineKernelVersion() != gb.LinuxKernelVersion {
// return cerror.ErrGeneric{Message: "Specified Linux Kernel version does not match the actual one."}
//}
if err := gb.resourceManager.GetSource(gb.AndroidVersion, gb.LinuxKernelVersion, gb.PatchVersion); err != nil {
return err
}

return nil
}
Expand Down
10 changes: 8 additions & 2 deletions agb/manager/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ func (gm *GitManager) Clone(url string, path string, shallow bool) error {

// Reset hard resets the state of the cloned git repository.
func (gm *GitManager) Reset(path string) error {
_, err := tool.RunCmdWDir("git clean -fdx && git reset --hard", path)
if _, err := tool.RunCmdWDir("git clean -fdx", path); err != nil {
return err
}

if _, err := tool.RunCmdWDir("git reset --soft", path); err != nil {
return err
}

return err
return nil
}
Loading

0 comments on commit f7bfc81

Please sign in to comment.