diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fd682c0..af9cab3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -103,8 +103,8 @@ jobs: strategy: matrix: go-version: - - "1.18" - "1.19" + - "1.20" steps: - uses: actions/checkout@v3 # We need the Go version and Go cache location for the actions/cache step, diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5994f24..a35456a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,34 +11,29 @@ env: jobs: build: - name: go-build + name: go-build ${{ matrix.goos }}-${{ matrix.arch }} runs-on: ubuntu-latest strategy: matrix: - bin: - - pca-linux-amd64 - - pca-linux-arm64 - - pca-osx-amd64 - - pca-osx-arm64 include: - - bin: pca-linux-amd64 + - arch: amd64 + bin: pca-linux-amd64 goos: linux - arch: amd64 - - os: pca-linux-arm64 + - arch: arm64 + bin: pca-linux-arm64 goos: linux - arch: arm64 - - bin: pca-osx-amd64 + - arch: amd64 + bin: pca-osx-amd64 goos: darwin - arch: amd64 - - bin: pca-osx-arm64 + - arch: arm64 + bin: pca-osx-arm64 goos: darwin - arch: arm64 steps: - uses: actions/checkout@v3 - id: setup-go uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" cache: true - name: Lookup Go cache directory id: go-cache @@ -56,7 +51,7 @@ jobs: ${{ hashFiles('go.sum') }}" restore-keys: | ${{ env.BASE_CACHE_KEY }} - - name: Build ${{ matrix.os }} + - name: Build ${{ matrix.bin }} run: go build -o ${{ matrix.bin }} env: GOOS: ${{ matrix.goos }} @@ -64,20 +59,29 @@ jobs: - name: Upload to artifacts uses: actions/upload-artifact@v3 with: - name: ${{ matrix.os }} + name: ${{ matrix.bin }} path: ${{ matrix.bin }} release: name: go-release runs-on: ubuntu-latest needs: build + env: + EXECUTABLE: bin/pca-linux-amd64/pca-linux-amd64 steps: - uses: actions/checkout@v3 - name: Download to artifacts uses: actions/download-artifact@v3 with: path: bin + - name: Make retrieved artifact executable + run: chmod +x ./${{ env.EXECUTABLE }} - name: Set Tag Version - run: echo "VERSION=$(cat ./VERSION)" >> $GITHUB_ENV + run: | + echo "VERSION=v$($EXECUTABLE -version)" \ + >> $GITHUB_ENV + - name: Setup tmate debug session + uses: mxschmitt/action-tmate@v3 + if: env.RUN_TMATE - name: Create Release uses: actions/github-script@v6 with: diff --git a/VERSION b/VERSION deleted file mode 100644 index 45c7a58..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -v0.0.1 diff --git a/go.mod b/go.mod index 585103a..36ab5fe 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/cisagov/con-pca-tasks -go 1.19 +go 1.20 -require github.com/go-chi/chi v1.5.4 +require github.com/go-chi/chi/v5 v5.0.8 diff --git a/go.sum b/go.sum index 874ed9a..2ad8d91 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs= -github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg= +github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= +github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= diff --git a/main.go b/main.go index afb643c..1405cd2 100644 --- a/main.go +++ b/main.go @@ -5,14 +5,17 @@ import ( "net/http" "github.com/cisagov/con-pca-tasks/controllers" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v5" ) func main() { + // Print the version and exit if the -version flag is provided + version() + mux := chi.NewRouter() mux.Get("/", controllers.HealthCheckHandler) port := ":8080" - log.Printf("listening on port %s", port) + log.Printf("listening on port %s, version %s", port, Version) log.Println(http.ListenAndServe(port, mux)) } diff --git a/version.go b/version.go new file mode 100644 index 0000000..e3ae6c1 --- /dev/null +++ b/version.go @@ -0,0 +1,18 @@ +package main + +import ( + "flag" + "fmt" + "os" +) + +var Version = "0.0.1" + +func version() { + v := flag.Bool("version", false, "prints current app version") + flag.Parse() + if *v { + fmt.Println(string(Version)) + os.Exit(0) + } +}