Compare commits

...
11 Commits
Author SHA1 Message Date
skruecken 59584f3928 Dont remove build dir anymore
Build / Build (push) Successful in 1m20s
2025-05-19 21:51:32 +02:00
skruecken 77bcf116fb Removed creation of build dir 2025-05-19 21:51:07 +02:00
skruecken 41437f0f2f Embedded the Templates in the go binary
Build / Build (push) Successful in 1m26s
2025-05-19 21:46:38 +02:00
skruecken 1f05960ffc Reworked Gitea Actions
Build / Build (push) Successful in 1m52s
2025-05-19 21:24:23 +02:00
skruecken ae2879de41 Fixed Branchname
ProtoGen Action Runner / build (push) Failing after 56s
2025-05-19 21:21:36 +02:00
skruecken efd3916fb4 Reworked Actions Build 2025-05-19 21:20:37 +02:00
skruecken 52238f9aaf Added Workflow
ProtoGen Action Runner / build (push) Failing after 0s
2025-05-19 21:17:05 +02:00
skruecken a887d76dd9 Added build cli 2025-05-19 21:13:11 +02:00
skruecken 014186b65a Removed Default write to build dir 2025-05-19 21:11:36 +02:00
skruecken e6763a6d4b Modified Makefile with PHONY targets 2025-05-19 21:05:11 +02:00
skruecken e80cba9110 Added -i for Input File 2025-05-19 21:04:54 +02:00
4 changed files with 50 additions and 10 deletions
+28
View File
@@ -0,0 +1,28 @@
name: Build
on: [push]
jobs:
Build:
runs-on: ubuntu-latest
container:
image: golang:latest
options: --network host
steps:
- run: |
apt-get update
apt-get install -y nodejs npm
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "The ${{ gitea.repository }} repository has been cloned to the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: go mod tidy
- run: make build
- run: ls -lah ${{ gitea.workspace }}
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: alox.protogen
path: ./alox.protogen
- run: echo "This job's status is ${{ job.status }}."
+4 -2
View File
@@ -1,8 +1,10 @@
.PHONY: build build_win clean
build: build:
go build . GOOS=linux go build .
build_win: build_win:
GOOS=windows go build . GOOS=windows go build .
clean: clean:
rm -rf build rm -rf build/*
+15 -6
View File
@@ -1,6 +1,7 @@
package main package main
import ( import (
"embed"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
@@ -13,11 +14,15 @@ import (
"github.com/knadh/koanf/providers/file" "github.com/knadh/koanf/providers/file"
) )
//go:embed templates/*
var embeddedTemplates embed.FS
var appConfig = koanf.New(".") var appConfig = koanf.New(".")
func main() { func main() {
confPath := flag.String("c", "testdata/conf.yaml", "Config File") confPath := flag.String("c", "testdata/conf.yaml", "Config File")
outFileName := flag.String("o", "", "Name of the Output File") outFileName := flag.String("o", "", "Name of the Output File")
inputFile := flag.String("i", "testdata/prot1.json", "Name of the Input File")
flag.Parse() flag.Parse()
@@ -27,7 +32,11 @@ func main() {
log.Printf("CONF: %v", appConfig) log.Printf("CONF: %v", appConfig)
} }
file, _ := os.ReadFile("testdata/prot1.json") file, err := os.ReadFile(*inputFile)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
var cfg proto.Proto var cfg proto.Proto
json.Unmarshal(file, &cfg) json.Unmarshal(file, &cfg)
@@ -35,7 +44,7 @@ func main() {
if *outFileName != "" { if *outFileName != "" {
cfg.FileName = *outFileName cfg.FileName = *outFileName
} else { } else {
*outFileName = "proto" *outFileName = "build/proto"
} }
// If filename not set in json take it from cli or default // If filename not set in json take it from cli or default
@@ -43,19 +52,19 @@ func main() {
cfg.FileName = *outFileName cfg.FileName = *outFileName
} }
proto.InitTemplates() proto.InitTemplates(embeddedTemplates, "templates/*.tmpl")
header, err := proto.CreateCStyleHeader(&cfg) header, err := proto.CreateCStyleHeader(&cfg)
if err != nil { if err != nil {
log.Printf("ERROR: %v", err) log.Printf("ERROR: %v", err)
} }
err = os.MkdirAll("build", 0755)
if err != nil { if err != nil {
log.Printf("ERROR: %v", err) log.Printf("ERROR: %v", err)
return return
} }
err = os.WriteFile(fmt.Sprintf("build/%s.h", *outFileName), []byte(header), 0666) err = os.WriteFile(fmt.Sprintf("%s.h", *outFileName), []byte(header), 0666)
if err != nil { if err != nil {
log.Printf("ERROR: %v", err) log.Printf("ERROR: %v", err)
return return
@@ -65,7 +74,7 @@ func main() {
if err != nil { if err != nil {
log.Printf("ERROR: %v", err) log.Printf("ERROR: %v", err)
} }
err = os.WriteFile(fmt.Sprintf("build/%s.c", *outFileName), []byte(source), 0666) err = os.WriteFile(fmt.Sprintf("%s.c", *outFileName), []byte(source), 0666)
if err != nil { if err != nil {
log.Printf("ERROR: %v", err) log.Printf("ERROR: %v", err)
return return
+3 -2
View File
@@ -3,6 +3,7 @@ package proto
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/fs"
"log" "log"
"strconv" "strconv"
"text/template" "text/template"
@@ -73,13 +74,13 @@ type CStyleData struct {
var tmpl *template.Template var tmpl *template.Template
func InitTemplates() { func InitTemplates(fsys fs.FS, pattern string) {
funcs := template.FuncMap{ funcs := template.FuncMap{
"snake": toSnakeCase, "snake": toSnakeCase,
"isLast": isLast, "isLast": isLast,
} }
Ntmpl, err := template.New("all").Funcs(funcs).ParseGlob("templates/*.tmpl") Ntmpl, err := template.New("all").Funcs(funcs).ParseFS(fsys, pattern)
if err != nil { if err != nil {
log.Fatalf("failed to parse templates: %v", err) log.Fatalf("failed to parse templates: %v", err)
} }