diff --git a/.github/workflows/.chglog/CHANGELOG.tpl.md b/.github/workflows/.chglog/CHANGELOG.tpl.md
new file mode 100644
index 0000000..a092888
--- /dev/null
+++ b/.github/workflows/.chglog/CHANGELOG.tpl.md
@@ -0,0 +1,38 @@
+{{ range .Versions }}
+
+## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})
+
+{{ range .CommitGroups -}}
+### {{ .Title }}
+
+{{ range .Commits -}}
+* {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
+{{ end }}
+{{ end -}}
+
+{{- if .RevertCommits -}}
+### Reverts
+
+{{ range .RevertCommits -}}
+* {{ .Revert.Header }}
+{{ end }}
+{{ end -}}
+
+{{- if .MergeCommits -}}
+### Pull Requests
+
+{{ range .MergeCommits -}}
+* {{ .Header }}
+{{ end }}
+{{ end -}}
+
+{{- if .NoteGroups -}}
+{{ range .NoteGroups -}}
+### {{ .Title }}
+
+{{ range .Notes }}
+{{ .Body }}
+{{ end }}
+{{ end -}}
+{{ end -}}
+{{ end -}}
\ No newline at end of file
diff --git a/.github/workflows/.chglog/config.yml b/.github/workflows/.chglog/config.yml
new file mode 100644
index 0000000..38acfb6
--- /dev/null
+++ b/.github/workflows/.chglog/config.yml
@@ -0,0 +1,28 @@
+style: github
+template: CHANGELOG.tpl.md
+info:
+ title: CHANGELOG
+ repository_url: https://github.com/deweysasser/golang-program
+options:
+ commits:
+ # filters:
+ # Type:
+ # - feat
+ # - fix
+ # - perf
+ # - refactor
+ commit_groups:
+ # title_maps:
+ # feat: Features
+ # fix: Bug Fixes
+ # perf: Performance Improvements
+ # refactor: Code Refactoring
+ header:
+ pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
+ pattern_maps:
+ - Type
+ - Scope
+ - Subject
+ notes:
+ keywords:
+ - BREAKING CHANGE
\ No newline at end of file
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..c95faff
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,41 @@
+on:
+ push:
+ branches:
+ - "**"
+
+name: Build
+env:
+ GO_VERSION: 1.23
+
+jobs:
+ build:
+ name: Run checks and build
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Set up Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: ${{env.GO_VERSION}}
+
+ - name: Vet
+ run: make vet
+
+ - name: Test
+ run: make test
+
+ - name: Build
+ run: make
+
+ format:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Set up Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: ${{env.GO_VERSION}}
+
+ - run: go fmt ./...
\ No newline at end of file
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index e69de29..c7da472 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -0,0 +1,96 @@
+name: Release
+# on:
+# push:
+# tags: [ v* ]
+on:
+ push:
+ branches:
+ - "**"
+
+env:
+ GO_VERSION: 1.23
+ REPO: ${{ github.repository }}
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ GOOS: [linux, darwin, windows]
+ GOARCH: [amd64, arm64]
+ include:
+ - GOOS: windows
+ ext: .exe
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Set up Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: ${{ env.GO_VERSION }}
+
+ - name: Repo Name
+ id: repo-name
+ run: echo name=$(basename ${{ github.repository }}) >> $GITHUB_OUTPUT
+
+ - name: Test
+ run: go test -v ./...
+
+ - name: Build
+ run: make package PROGRAM=${{ env.GOOS }}-${{ env.GOARCH }}/${{ steps.repo-name.outputs.name }}${{ matrix.ext }} PACKAGE=dist/${{ steps.repo-name.outputs.name }}-${{ matrix.GOOS }}-${{ matrix.GOARCH }}.zip
+ env:
+ GOOS: ${{ matrix.GOOS }}
+ GOARCH: ${{ matrix.GOARCH }}
+
+ - name: 'Upload Artifact'
+ uses: actions/upload-artifact@v4
+ with:
+ name: artifacts-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
+ path: dist
+ retention-days: 1
+ if-no-files-found: error
+
+ release:
+ runs-on: ubuntu-latest
+ needs:
+ - build
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Download Artifacts
+ uses: actions/download-artifact@v4
+ with:
+ path: artifacts
+ pattern: artifacts-*
+ merge-multiple: true
+
+ - name: Install ChangeLog generator
+ run: |
+ wget https://github.com/git-chglog/git-chglog/releases/download/v0.15.1/git-chglog_0.15.1_linux_amd64.tar.gz
+ tar xzf git-chglog*.tar.gz git-chglog
+ - name: "Get Last Release"
+ id: last_release
+ uses: InsonusK/get-latest-release@v1.1.0
+ with:
+ myToken: ${{ github.token }}
+ exclude_types: "draft|prerelease"
+
+ - name: Generate Changelog for ${{ github.ref_name }}
+ id: generate-changelog
+ run: PATH="${PATH}:." make CHANGELOG.md
+
+ - name: Generate checksum
+ run: |
+ cd artifacts
+ for file in *; do shasum -a 256 "$file" >> checksum.txt; done
+
+ - name: Create Release
+ id: create_release
+ uses: softprops/action-gh-release@v2
+ with:
+ files: |
+ ./artifacts/*
+ body_path: ./CHANGELOG.md
+ draft: false
\ No newline at end of file
diff --git a/cmd/root.go b/cmd/root.go
index 6f72446..9d18328 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -6,13 +6,15 @@ package cmd
import (
"Utkarsh4517/ginister/config"
"Utkarsh4517/ginister/controllers"
+ "Utkarsh4517/ginister/docker"
"Utkarsh4517/ginister/models"
"Utkarsh4517/ginister/routes"
+ "Utkarsh4517/ginister/start"
"bufio"
"fmt"
"os"
"strings"
- "Utkarsh4517/ginister/docker"
+
"github.com/spf13/cobra"
)
@@ -53,6 +55,11 @@ func createProject(projectName string, reader *bufio.Reader) {
fmt.Printf("Error creating Dockerfile: %v\n", err)
}
+ err = start.CreateMainFile(projectName)
+ if err != nil {
+ fmt.Printf("Error creating main.go: %v\n", err)
+ }
+
var modelNames []string
for {
@@ -98,4 +105,4 @@ func getModelFields(reader *bufio.Reader) []string {
fields = append(fields, field)
}
return fields
-}
\ No newline at end of file
+}
diff --git a/config/config.go b/config/config.go
index 79ebe81..a7cce1e 100644
--- a/config/config.go
+++ b/config/config.go
@@ -33,4 +33,4 @@ func ConnectDB() {
file.WriteString(content)
fmt.Println("Config file created successfully!")
-}
\ No newline at end of file
+}
diff --git a/controllers/generateController.go b/controllers/generateController.go
index 8d632a7..b0f5079 100644
--- a/controllers/generateController.go
+++ b/controllers/generateController.go
@@ -44,4 +44,4 @@ func Delete%s(c *gin.Context) {
file.WriteString(content)
fmt.Printf("Controller for %s created successfully!\n", modelName)
-}
\ No newline at end of file
+}
diff --git a/docker/docker.go b/docker/docker.go
index 2896d73..2a0359a 100644
--- a/docker/docker.go
+++ b/docker/docker.go
@@ -1,12 +1,12 @@
package docker
import (
- "fmt"
- "os"
+ "fmt"
+ "os"
)
func CreateDockerfile(projectDir string) error {
- content := `FROM golang:1.23
+ content := `FROM golang:1.23
WORKDIR /app
@@ -22,13 +22,13 @@ EXPOSE 8080
CMD ["./main"]
`
- filePath := fmt.Sprintf("%s/Dockerfile", projectDir)
- file, err := os.Create(filePath)
- if err != nil {
- return err
- }
- defer file.Close()
+ filePath := fmt.Sprintf("%s/Dockerfile", projectDir)
+ file, err := os.Create(filePath)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
- _, err = file.WriteString(content)
- return err
+ _, err = file.WriteString(content)
+ return err
}
diff --git a/main.go b/main.go
index 5679cbb..954e92b 100644
--- a/main.go
+++ b/main.go
@@ -1,12 +1,10 @@
/*
Copyright © 2024 NAME HERE
-
*/
package main
import (
"Utkarsh4517/ginister/cmd"
-
)
func main() {
@@ -14,5 +12,5 @@ func main() {
// config.ConnectDB()
// router := routes.SetupRouter()
- // router.Run(":8080")
+ // router.Run(":8080")
}
diff --git a/models/generateModel.go b/models/generateModel.go
index ebc5ecb..4a72f79 100644
--- a/models/generateModel.go
+++ b/models/generateModel.go
@@ -20,4 +20,4 @@ func GenerateModelFile(projectName, modelName string, fields []string) {
file.WriteString(content)
fmt.Printf("Model for %s created successfully!\n", modelName)
-}
\ No newline at end of file
+}
diff --git a/routes/routes.go b/routes/routes.go
index c032ee5..8baecc4 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -40,4 +40,4 @@ func SetupRouter() *gin.Engine {
file.WriteString(content)
fmt.Println("Routes file created successfully!")
-}
\ No newline at end of file
+}
diff --git a/start/main.go b/start/main.go
new file mode 100644
index 0000000..9d3e462
--- /dev/null
+++ b/start/main.go
@@ -0,0 +1,31 @@
+package start
+
+import (
+ "fmt"
+ "os"
+)
+
+func CreateMainFile(projectDir string) error {
+ content := `package main
+
+import (
+ "github.com/gin-gonic/gin"
+)
+
+func main() {
+ r := gin.Default()
+
+ r.Run(":8080")
+}
+`
+
+ filePath := fmt.Sprintf("%s/main.go", projectDir)
+ file, err := os.Create(filePath)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
+
+ _, err = file.WriteString(content)
+ return err
+}
\ No newline at end of file