diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 63c4707..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:1.14 - working_directory: /go/src/github.com/recrsn/coffee-beans - steps: - - checkout - - run: cd server - - run: go build ./... - - run: go test -v ./... - - run: go vet ./... diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..7650a3f --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,42 @@ +on: + push: + branches: + - master + tags: + - v* + pull_request: + branches: + - master + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: 1.21 + - name: Build + run: | + mkdir -p ./coffee-beans + cp coffee-beans.yaml ./coffee-beans + go build -o ./coffee-beans/coffee-beans -ldflags "-X main.version=${GITHUB_REF#refs/*/}" "-X main.commit=${GITHUB_SHA}" + - name: Test + run: | + go test -v ./... + - name: Package + run: | + tar -czf coffee-beans.tar.gz ./coffee-beans + - name: Upload + if: github.ref == 'refs/heads/master' || github.ref == 'refs/tags/v*' + uses: actions/upload-artifact@v2 + with: + name: coffee-beans + path: coffee-beans.tar.gz + - name: Release + uses: softprops/action-gh-release@v1 + if: github.ref == 'refs/tags/v*' + with: + files: coffee-beans.tar.gz diff --git a/.gitignore b/.gitignore index ea97ed0..5c56a0e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,6 @@ vendor/ /server /data/ -/tmp/ \ No newline at end of file +/tmp/ +/coffee-beans/ +coffee-beans.tar.gz diff --git a/handlers/ping.go b/handlers/ping.go index f5599b7..cdd7f79 100644 --- a/handlers/ping.go +++ b/handlers/ping.go @@ -2,11 +2,11 @@ package handlers import "github.com/gin-gonic/gin" -// Ping handles a ping for healthcheck and discovery purposes -func Ping() func(*gin.Context) { +// HealthCheck handles a ping for healthcheck and discovery purposes +func HealthCheck() func(*gin.Context) { return func(c *gin.Context) { c.JSON(200, gin.H{ - "message": "pong", + "message": "OK", }) } } diff --git a/main.go b/main.go index d5c324c..33b57e9 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/recrsn/coffee-beans/repositories" + "log" "github.com/gin-gonic/gin" @@ -11,14 +12,21 @@ import ( "github.com/recrsn/coffee-beans/utils" ) +var ( + version = "dev" + commit = "HEAD" +) + func main() { + log.Printf("Coffee Beans %s (%s)\n", version, commit) + cfg, err := config.Load() utils.Must(err) router := gin.Default() router.LoadHTMLGlob("templates/*") - router.GET("/ping", handlers.Ping()) + router.GET("/health", handlers.HealthCheck()) manager := repositories.NewRepositoryManager(cfg.Server.BaseURL, cfg.Repositories)