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

feat: added new features #4

Merged
merged 1 commit into from
Sep 20, 2024
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
38 changes: 38 additions & 0 deletions .github/workflows/.chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ 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 -}}
28 changes: 28 additions & 0 deletions .github/workflows/.chglog/config.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
96 changes: 96 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
11 changes: 9 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -98,4 +105,4 @@ func getModelFields(reader *bufio.Reader) []string {
fields = append(fields, field)
}
return fields
}
}
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ func ConnectDB() {

file.WriteString(content)
fmt.Println("Config file created successfully!")
}
}
2 changes: 1 addition & 1 deletion controllers/generateController.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ func Delete%s(c *gin.Context) {

file.WriteString(content)
fmt.Printf("Controller for %s created successfully!\n", modelName)
}
}
22 changes: 11 additions & 11 deletions docker/docker.go
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
}
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>

*/
package main

import (
"Utkarsh4517/ginister/cmd"

)

func main() {
cmd.Execute()
// config.ConnectDB()
// router := routes.SetupRouter()

// router.Run(":8080")
// router.Run(":8080")
}
2 changes: 1 addition & 1 deletion models/generateModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ func GenerateModelFile(projectName, modelName string, fields []string) {

file.WriteString(content)
fmt.Printf("Model for %s created successfully!\n", modelName)
}
}
2 changes: 1 addition & 1 deletion routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ func SetupRouter() *gin.Engine {

file.WriteString(content)
fmt.Println("Routes file created successfully!")
}
}
31 changes: 31 additions & 0 deletions start/main.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading