Skip to content

Instantly share code, notes, and snippets.

@bioform
Forked from alexedwards/Makefile
Created November 3, 2024 09:57
Show Gist options
  • Select an option

  • Save bioform/236d29a37fe6d66240550beffcdfe025 to your computer and use it in GitHub Desktop.

Select an option

Save bioform/236d29a37fe6d66240550beffcdfe025 to your computer and use it in GitHub Desktop.

Revisions

  1. @alexedwards alexedwards revised this gist Aug 18, 2024. 1 changed file with 41 additions and 41 deletions.
    82 changes: 41 additions & 41 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Change these variables as necessary.
    MAIN_PACKAGE_PATH := ./cmd/example
    BINARY_NAME := example
    main_package_path = ./cmd/example
    binary_name = example

    # ==================================================================================== #
    # HELPERS
    @@ -9,72 +9,73 @@ BINARY_NAME := example
    ## help: print this help message
    .PHONY: help
    help:
    @echo 'Usage:'
    @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
    @echo 'Usage:'
    @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

    .PHONY: confirm
    confirm:
    @echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
    @echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]

    .PHONY: no-dirty
    no-dirty:
    git diff --exit-code
    @test -z "$(shell git status --porcelain)"


    # ==================================================================================== #
    # QUALITY CONTROL
    # ==================================================================================== #

    ## tidy: format code and tidy modfile
    .PHONY: tidy
    tidy:
    go fmt ./...
    go mod tidy -v

    ## audit: run quality control checks
    .PHONY: audit
    audit:
    go mod verify
    go vet ./...
    go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./...
    go run golang.org/x/vuln/cmd/govulncheck@latest ./...
    go test -race -buildvcs -vet=off ./...


    # ==================================================================================== #
    # DEVELOPMENT
    # ==================================================================================== #
    audit: test
    go mod tidy -diff
    go mod verify
    test -z "$(shell gofmt -l .)"
    go vet ./...
    go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./...
    go run golang.org/x/vuln/cmd/govulncheck@latest ./...

    ## test: run all tests
    .PHONY: test
    test:
    go test -v -race -buildvcs ./...
    go test -v -race -buildvcs ./...

    ## test/cover: run all tests and display coverage
    .PHONY: test/cover
    test/cover:
    go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./...
    go tool cover -html=/tmp/coverage.out
    go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./...
    go tool cover -html=/tmp/coverage.out


    # ==================================================================================== #
    # DEVELOPMENT
    # ==================================================================================== #

    ## tidy: tidy modfiles and format .go files
    .PHONY: tidy
    tidy:
    go mod tidy -v
    go fmt ./...

    ## build: build the application
    .PHONY: build
    build:
    # Include additional build steps, like TypeScript, SCSS or Tailwind compilation here...
    go build -o=/tmp/bin/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
    # Include additional build steps, like TypeScript, SCSS or Tailwind compilation here...
    go build -o=/tmp/bin/${binary_name} ${main_package_path}

    ## run: run the application
    .PHONY: run
    run: build
    /tmp/bin/${BINARY_NAME}
    /tmp/bin/${binary_name}

    ## run/live: run the application with reloading on file changes
    .PHONY: run/live
    run/live:
    go run github.com/cosmtrek/[email protected] \
    --build.cmd "make build" --build.bin "/tmp/bin/${BINARY_NAME}" --build.delay "100" \
    --build.exclude_dir "" \
    --build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico" \
    --misc.clean_on_exit "true"
    go run github.com/cosmtrek/[email protected] \
    --build.cmd "make build" --build.bin "/tmp/bin/${binary_name}" --build.delay "100" \
    --build.exclude_dir "" \
    --build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico" \
    --misc.clean_on_exit "true"


    # ==================================================================================== #
    @@ -83,13 +84,12 @@ run/live:

    ## push: push changes to the remote Git repository
    .PHONY: push
    push: tidy audit no-dirty
    git push
    push: confirm audit no-dirty
    git push

    ## production/deploy: deploy the application to production
    .PHONY: production/deploy
    production/deploy: confirm tidy audit no-dirty
    GOOS=linux GOARCH=amd64 go build -ldflags='-s' -o=/tmp/bin/linux_amd64/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
    upx -5 /tmp/bin/linux_amd64/${BINARY_NAME}
    # Include additional deployment steps here...

    production/deploy: confirm audit no-dirty
    GOOS=linux GOARCH=amd64 go build -ldflags='-s' -o=/tmp/bin/linux_amd64/${binary_name} ${main_package_path}
    upx -5 /tmp/bin/linux_amd64/${binary_name}
    # Include additional deployment steps here...
  2. @alexedwards alexedwards revised this gist May 3, 2023. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -70,7 +70,11 @@ run: build
    ## run/live: run the application with reloading on file changes
    .PHONY: run/live
    run/live:
    go run github.com/cosmtrek/[email protected] --build.cmd "make build" --build.bin "/tmp/bin/${BINARY_NAME}" --build.delay "100" --build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico"
    go run github.com/cosmtrek/[email protected] \
    --build.cmd "make build" --build.bin "/tmp/bin/${BINARY_NAME}" --build.delay "100" \
    --build.exclude_dir "" \
    --build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico" \
    --misc.clean_on_exit "true"


    # ==================================================================================== #
    @@ -87,4 +91,5 @@ push: tidy audit no-dirty
    production/deploy: confirm tidy audit no-dirty
    GOOS=linux GOARCH=amd64 go build -ldflags='-s' -o=/tmp/bin/linux_amd64/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
    upx -5 /tmp/bin/linux_amd64/${BINARY_NAME}
    # Include additional deployment steps here...
    # Include additional deployment steps here...

  3. @alexedwards alexedwards created this gist May 2, 2023.
    90 changes: 90 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,90 @@
    # Change these variables as necessary.
    MAIN_PACKAGE_PATH := ./cmd/example
    BINARY_NAME := example

    # ==================================================================================== #
    # HELPERS
    # ==================================================================================== #

    ## help: print this help message
    .PHONY: help
    help:
    @echo 'Usage:'
    @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

    .PHONY: confirm
    confirm:
    @echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]

    .PHONY: no-dirty
    no-dirty:
    git diff --exit-code


    # ==================================================================================== #
    # QUALITY CONTROL
    # ==================================================================================== #

    ## tidy: format code and tidy modfile
    .PHONY: tidy
    tidy:
    go fmt ./...
    go mod tidy -v

    ## audit: run quality control checks
    .PHONY: audit
    audit:
    go mod verify
    go vet ./...
    go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./...
    go run golang.org/x/vuln/cmd/govulncheck@latest ./...
    go test -race -buildvcs -vet=off ./...


    # ==================================================================================== #
    # DEVELOPMENT
    # ==================================================================================== #

    ## test: run all tests
    .PHONY: test
    test:
    go test -v -race -buildvcs ./...

    ## test/cover: run all tests and display coverage
    .PHONY: test/cover
    test/cover:
    go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./...
    go tool cover -html=/tmp/coverage.out

    ## build: build the application
    .PHONY: build
    build:
    # Include additional build steps, like TypeScript, SCSS or Tailwind compilation here...
    go build -o=/tmp/bin/${BINARY_NAME} ${MAIN_PACKAGE_PATH}

    ## run: run the application
    .PHONY: run
    run: build
    /tmp/bin/${BINARY_NAME}

    ## run/live: run the application with reloading on file changes
    .PHONY: run/live
    run/live:
    go run github.com/cosmtrek/[email protected] --build.cmd "make build" --build.bin "/tmp/bin/${BINARY_NAME}" --build.delay "100" --build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico"


    # ==================================================================================== #
    # OPERATIONS
    # ==================================================================================== #

    ## push: push changes to the remote Git repository
    .PHONY: push
    push: tidy audit no-dirty
    git push

    ## production/deploy: deploy the application to production
    .PHONY: production/deploy
    production/deploy: confirm tidy audit no-dirty
    GOOS=linux GOARCH=amd64 go build -ldflags='-s' -o=/tmp/bin/linux_amd64/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
    upx -5 /tmp/bin/linux_amd64/${BINARY_NAME}
    # Include additional deployment steps here...