Skip to content

Commit f139acd

Browse files
committed
feat: init
0 parents  commit f139acd

File tree

11 files changed

+1004
-0
lines changed

11 files changed

+1004
-0
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.yaml]
2+
indent_style = space
3+
indent_size = 2
4+
insert_final_newline = true

.github/workflows/build.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v1
16+
with:
17+
fetch-depth: 0
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: '^1.17'
21+
- name: golangci-lint
22+
uses: golangci/golangci-lint-action@v2
23+
with:
24+
version: latest
25+
skip-go-installation: true
26+
- name: build
27+
uses: goreleaser/goreleaser-action@v2
28+
with:
29+
version: latest
30+
args: build --snapshot --rm-dist

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

.goreleaser.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
- go generate ./...
5+
- go test ./...
6+
project_name: gitops-commit
7+
builds:
8+
- main: ./cmd/gitops-commit
9+
id: "gitops-commit"
10+
binary: gitops-commit
11+
env:
12+
- CGO_ENABLED=0
13+
goos:
14+
- linux
15+
- darwin
16+
archives:
17+
- replacements:
18+
darwin: Darwin
19+
linux: Linux
20+
amd64: x86_64
21+
checksum:
22+
name_template: 'checksums.txt'
23+
snapshot:
24+
name_template: "{{ .Tag }}-next"
25+
changelog:
26+
sort: asc
27+
filters:
28+
exclude:
29+
- '^docs:'
30+
- '^test:'

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: all
2+
default: build;
3+
4+
fmt:
5+
go fmt ./...
6+
7+
tests:
8+
go test ./...
9+
10+
run:
11+
./dist/gitops-commit_darwin_amd64/gitops-commit
12+
13+
build:
14+
goreleaser build --snapshot --skip-validate --rm-dist --single-target
15+
16+
17+
all: build run

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Gitops Commit
2+
3+
[Under Construction]
4+
5+
A utility designed to mutate a version within a yaml file to trigger
6+
gitops operations i.e. update a helm value
7+
8+
## TODO
9+
10+
- [ ] Add web service
11+
- [ ] Add webhook to ingress from slack command
12+
13+
## Limitations
14+
15+
- Github only
16+
- YAML only
17+
- Semver tag only

cmd/gitops-commit/main.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/gsdevme/gitops-commit/internal/pkg/gitops"
6+
"github.com/spf13/cobra"
7+
"io/ioutil"
8+
"os"
9+
"strings"
10+
)
11+
12+
func NewRootCommand() *cobra.Command {
13+
c := cobra.Command{
14+
Use: "test",
15+
Run: func(cmd *cobra.Command, args []string) {
16+
key := cmd.Flag("key").Value.String()
17+
repo := strings.TrimRight(cmd.Flag("repo").Value.String(), "/")
18+
file := strings.TrimLeft(cmd.Flag("file").Value.String(), "/")
19+
20+
options, c, err := gitops.NewGitOptions(key)
21+
22+
if err != nil {
23+
panic(err.Error()) // todo
24+
}
25+
26+
defer c()
27+
28+
r, err := gitops.CloneRepository(options, repo)
29+
30+
if err != nil {
31+
panic(err.Error()) // todo
32+
}
33+
34+
filename := fmt.Sprintf("%s/%s", options.WorkingDirectory, file)
35+
36+
f, err := ioutil.ReadFile(filename)
37+
38+
if err != nil {
39+
panic(fmt.Errorf("cannot read file: %w", err))
40+
}
41+
42+
version, err := gitops.ReadCurrentVersion(f, "foo.woo.wibble.tag")
43+
if err != nil {
44+
panic(err) // todo
45+
}
46+
47+
err = gitops.WriteVersion(f, version, "v2.3.1", filename)
48+
if err != nil {
49+
panic(err) // todo
50+
}
51+
52+
gitops.PushVersion(r, options, file)
53+
},
54+
}
55+
56+
c.Flags().String("key", fmt.Sprintf("%s/.ssh/id_rsa", os.Getenv("HOME")), "Absolute path to the private key")
57+
c.Flags().String("repo", "gsdevme/test", "The org/repo path")
58+
c.Flags().String("file", "/deployments/values.yaml", "The relative path in the repository to the file")
59+
60+
_ = c.MarkFlagRequired("file")
61+
62+
return &c
63+
}
64+
65+
func main() {
66+
if err := NewRootCommand().Execute(); err != nil {
67+
fmt.Println(err)
68+
os.Exit(1)
69+
}
70+
}

go.mod

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module github.com/gsdevme/gitops-commit
2+
3+
go 1.17
4+
5+
require (
6+
github.com/go-git/go-git/v5 v5.4.2
7+
github.com/spf13/cobra v1.2.1
8+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
9+
)
10+
11+
require (
12+
github.com/Microsoft/go-winio v0.4.16 // indirect
13+
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
14+
github.com/acomagu/bufpipe v1.0.3 // indirect
15+
github.com/emirpasic/gods v1.12.0 // indirect
16+
github.com/go-git/gcfg v1.5.0 // indirect
17+
github.com/go-git/go-billy/v5 v5.3.1 // indirect
18+
github.com/imdario/mergo v0.3.12 // indirect
19+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
20+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
21+
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
22+
github.com/mitchellh/go-homedir v1.1.0 // indirect
23+
github.com/sergi/go-diff v1.1.0 // indirect
24+
github.com/spf13/pflag v1.0.5 // indirect
25+
github.com/xanzy/ssh-agent v0.3.0 // indirect
26+
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
27+
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
28+
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
29+
gopkg.in/warnings.v0 v0.1.2 // indirect
30+
)

0 commit comments

Comments
 (0)