Skip to content

Commit

Permalink
adds version command
Browse files Browse the repository at this point in the history
  • Loading branch information
benammann committed May 31, 2022
1 parent bf7213f commit aab0b3e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ jobs:
run: echo "CR_TOKEN=$(docker run -v $PWD/.git-secrets.json:/git-secrets/.git-secrets.json "$IMAGE_NAME:latest" --secret gitsecretspublic=${GIT_SECRETS_PUBLIC_DEFAULT} get secret crToken)" >> $GITHUB_ENV
env:
GIT_SECRETS_PUBLIC_DEFAULT: ${{ secrets.GIT_SECRETS_PUBLIC_DEFAULT }}
- name: Remove ref from tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Remove v from release version
run: echo "IMAGE_TAG=${RELEASE_VERSION:1}" >> $GITHUB_ENV
- name: Docker login
run: echo $CR_TOKEN | docker login -u $CR_USER --password-stdin
- name: Docker Build
run: docker build --pull -t "$IMAGE_NAME:latest" .
run: docker build --pull -t "$IMAGE_NAME:latest" . --build-arg BUILD_VERSION=$RELEASE_VERSION --build-arg BUILD_COMMIT=$GITHUB_SHA --build-arg DATE=$(date)
- name: Docker Push (latest tag)
run: docker push "$IMAGE_NAME:latest"
- name: Remove ref from tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Remove v from release version
run: echo "IMAGE_TAG=${RELEASE_VERSION:1}" >> $GITHUB_ENV
- name: Docker Tag latest as build tag
run: docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:$IMAGE_TAG"
- name: Docker Push build tag
Expand Down
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ RUN go mod download
# Copy the go source
COPY . .

ARG BUILD_VERSION="n/a"
ARG BUILD_COMMIT="n/a"
ARG BUILD_DATE="n/a"

ENV BUILD_VERSION="$BUILD_VERSION"
ENV BUILD_COMMIT="$BUILD_COMMIT"
ENV BUILD_DATE="$BUILD_DATE"

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o git-secrets main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o git-secrets main.go -ldflags "-X main.version=$BUILD_VERSION -X main.commit=$BUILD_COMMIT -X main.date=$BUILD_DATE"

FROM alpine:latest
WORKDIR /git-secrets
Expand Down
9 changes: 8 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/spf13/viper"
)

var version string
var commit string
var date string

var globalCfgFile string
var projectCfgFile string
var projectCfg *config_generic.Repository
Expand Down Expand Up @@ -50,7 +54,10 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(buildVersion string, buildCommit string, buildDate string) {
version = buildVersion
commit = buildCommit
date = buildDate
cobra.CheckErr(rootCmd.Execute())
}

Expand Down
52 changes: 52 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"
"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "prints the version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(`
________.__ __ _________ __
/ _____/|__|/ |_ / _____/ ____ ___________ _____/ |_ ______
/ \ ___| \ __\ \_____ \_/ __ \_/ ___\_ __ \_/ __ \ __\/ ___/
\ \_\ \ || | / \ ___/\ \___| | \/\ ___/| | \___ \
\______ /__||__| /_______ /\___ >\___ >__| \___ >__| /____ >
\/ \/ \/ \/ \/ \/
`)
fmt.Println(version, commit, date)
},
}

func init() {
rootCmd.AddCommand(versionCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// versionCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package main

import (
"github.com/benammann/git-secrets/cmd"
"time"
)

var version string = "v0.0.0-local"
var commit string = "local-rev"
var date string = time.Now().Format(time.RFC3339)

func main() {
cmd.Execute()
cmd.Execute(version, commit, date)
}
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ The configuration is made in a json file called `.git-secrets.json` you can also

```bash
# Create a new global encoder secret (which you can later share with your team)
git secrets global-secret mySecret --value $(pwgen -c 32 -n -s -y)
git secrets set global-secret mySecret --value $(pwgen -c 32 -n -s -y)

# Create a new .git-secrets.json
git secrets init

# Get the initial information of the config file
git secrets info

# Get the CLI's current version
git secrets version
```

### Encode a secret and add a config entry
Expand Down

0 comments on commit aab0b3e

Please sign in to comment.