Skip to content

Commit

Permalink
ci: add ci + fix lint issues
Browse files Browse the repository at this point in the history
* fix: lint issue by adding err handle to required flags
  • Loading branch information
Pradumnasaraf authored Jun 7, 2023
1 parent 5316abf commit 6cf1b3f
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 37 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build-format:
name: Build and Format
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.19
- name: Build
run: go build -v ./...
- name: Format
run: diff <(gofmt -d .) <(echo -n)

golangci-lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.19
cache: false
- name: GolangCI-Lint Check
uses: golangci/golangci-lint-action@v3
5 changes: 3 additions & 2 deletions cmd/docker/docker-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ func init() {
DockerCmd.AddCommand(dockerfileCmd)

dockerfileCmd.Flags().StringVarP(&language, "lang", "l", "", "Programming language to generate Dockerfile for.")
dockerfileCmd.MarkFlagRequired("lang")
err := dockerfileCmd.MarkFlagRequired("lang")
checkNilErr(err)
}

func checkNilErr(err error) {
if err != nil {
log.Fatal(err)
}
}
}
3 changes: 2 additions & 1 deletion cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var DockerCmd = &cobra.Command{
Use: "docker [command] [flags]",
Short: "Docker related commands. Like generating a Dockerfile for a language.",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
err := cmd.Help()
checkNilErr(err)
},
}
17 changes: 5 additions & 12 deletions cmd/docker/dockerfile-skeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package docker

// This go file contains the Dockerfile templates for different languages

var golang string =
`# base image. Change it to latest version of golang
var golang string = `# base image. Change it to latest version of golang
FROM golang:1.14.2-alpine3.11
# set working directory
WORKDIR /go/src/app
Expand All @@ -18,8 +17,7 @@ RUN go build -o main .
# running the executable
CMD ["/go/src/app/main"]`

var node string =
`# base image. Change it to latest version of node
var node string = `# base image. Change it to latest version of node
FROM node:12.16.1-alpine3.9
# set working directory
WORKDIR /usr/src/app
Expand All @@ -34,9 +32,7 @@ EXPOSE 3000
# start app
CMD [ "npm", "start" ]`


var python string =
`# base image. Change it to latest version of python
var python string = `# base image. Change it to latest version of python
FROM python:3.8.2-alpine3.11
# set working directory
WORKDIR /usr/src/app
Expand All @@ -51,8 +47,7 @@ EXPOSE 5000
# start app
CMD [ "python", "./app.py" ]`

var ruby string =
`# base image. Change it to latest version of ruby
var ruby string = `# base image. Change it to latest version of ruby
FROM ruby:2.7.1-alpine3.11
# set working directory
WORKDIR /usr/src/app
Expand All @@ -67,9 +62,7 @@ EXPOSE 3000
# start app
CMD [ "ruby", "app.rb" ]`


var java string =
`# base image. Change it to latest version of java
var java string = `# base image. Change it to latest version of java
FROM openjdk:8-jdk-alpine
# set volume point to /tmp
VOLUME /tmp
Expand Down
3 changes: 2 additions & 1 deletion cmd/jsonToYaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ func init() {
// Flags for the JYT command
jsonToYaml.Flags().StringVarP(&outputYamlFile, "output", "o", "", "Output YAML file name (default is output.yaml)")
jsonToYaml.Flags().StringVarP(&inputJsonFile, "file", "f", "", "Input the JSON file name")
jsonToYaml.MarkFlagRequired("file")
err := jsonToYaml.MarkFlagRequired("file")
checkNilErr(err)
}
5 changes: 3 additions & 2 deletions cmd/keyValueToJson.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var keyValueToJson = &cobra.Command{
// Write the output file
file, err := os.Create(outputJsonFile1)
checkNilErr(err)

defer file.Close()

_, err = file.WriteString(string(jsonString))
Expand All @@ -63,7 +63,8 @@ func init() {

// Flags for the TTJ command
keyValueToJson.Flags().StringVarP(&inputTextFile, "file", "f", "", "Input the text file name. Eg: keys.txt or .env")
keyValueToJson.MarkFlagRequired("file")
err := keyValueToJson.MarkFlagRequired("file")
checkNilErr(err)

keyValueToJson.Flags().StringVarP(&outputJsonFile1, "output", "o", "", "Output JSON file name (default is output.json)")
keyValueToJson.Flags().BoolP("print", "p", false, "Print the output to the console")
Expand Down
4 changes: 3 additions & 1 deletion cmd/kubernetes/kubernetes-manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func init() {
KubernetesCmd.AddCommand(kubernetesManifestCmd)

kubernetesManifestCmd.Flags().StringVarP(&k8Obj, "obj", "o", "", "Kubernetes object to generate manifest for.")
kubernetesManifestCmd.MarkFlagRequired("obj")
err := kubernetesManifestCmd.MarkFlagRequired("obj")
checkNilErr(err)

}

func checkNilErr(err error) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var KubernetesCmd = &cobra.Command{
Use: "k8s [command] [flags]",
Short: "Kubernetes related commands. Like generating manifest files for kubernetes objects.",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
err := cmd.Help()
checkNilErr(err)
},
}
21 changes: 7 additions & 14 deletions cmd/kubernetes/mainifest-skeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ spec:
ports:
- containerPort: <Port>`

var service =
`apiVersion: v1
var service = `apiVersion: v1
kind: Service
metadata:
name: myapp
Expand All @@ -37,8 +36,7 @@ spec:
- port: <Port>
targetPort: <Target Port>`

var ingress =
`apiVersion: networking.k8s.io/v1
var ingress = `apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myingress
Expand All @@ -57,8 +55,7 @@ spec:
port:
number: <Port>`

var secret =
`apiVersion: v1
var secret = `apiVersion: v1
kind: Secret
metadata:
name: mysecret
Expand All @@ -67,16 +64,14 @@ data:
password: <Password> # This should be base64 encoded
`

var configmap =
`apiVersion: v1
var configmap = `apiVersion: v1
kind: ConfigMap
metadata:
name: myapp
data:
key: value`

var pod =
`apiVersion: v1
var pod = `apiVersion: v1
kind: Pod
metadata:
name: myapp
Expand All @@ -93,8 +88,7 @@ spec:
ports:
- containerPort: <Port>`

var pv =
`apiVersion: v1
var pv = `apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv
Expand All @@ -113,8 +107,7 @@ spec:
path: /tmp
server: 172.17.0.2`

var pvc =
`apiVersion: v1
var pvc = `apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var rootCmd = &cobra.Command{
Use: "candy [command]",
Short: "Do all your tedious tasks with a single command",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
err := cmd.Help()
checkNilErr(err)
},
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/yamlToJson.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ func init() {
// Flags for the YTJ command
yamlToJsonCmd.Flags().StringVarP(&outputJsonFile, "output", "o", "", "Output JSON file name (default is output.json)")
yamlToJsonCmd.Flags().StringVarP(&inputYamlFile, "file", "f", "", "Input the YAML file name")
yamlToJsonCmd.MarkFlagRequired("file")

err := yamlToJsonCmd.MarkFlagRequired("file")
checkNilErr(err)

}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright © 2023 Pradumna Saraf <[email protected]>.
/*
Copyright © 2023 Pradumna Saraf <[email protected]>.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 6cf1b3f

Please sign in to comment.