diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 77c6931..4359462 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,10 @@ jobs: goos: windows steps: - uses: actions/checkout@v3 + - name: Set BUILD_TIME + run: echo BUILD_TIME=$(date +"%Y-%m-%dT%H:%M:%S%z") >> ${GITHUB_ENV} + - name: Set MIG_VERSION + run: echo MIG_VERSION=$(cat version.txt) >> ${GITHUB_ENV} - uses: wangyoucao577/go-release-action@v1.34 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -24,4 +28,5 @@ jobs: goarch: ${{ matrix.goarch }} goversion: "1.19" binary_name: "mig" - md5sum: false \ No newline at end of file + md5sum: false + ldflags: -s -w -X "github.com/tlhunter/mig/commands.Version=${{ env.MIG_VERSION }}" -X "github.com/tlhunter/mig/commands.BuildTime=${{ env.BUILD_TIME }}" \ No newline at end of file diff --git a/Makefile b/Makefile index 27b4878..fddd940 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ MIG_VERSION = $(shell cat version.txt) +BUILD_TIME = $(shell date +"%Y-%m-%dT%H:%M:%S%z") # Strip debug info -GO_FLAGS += "-ldflags=-s -w" - -# Avoid embedding the build path in the executable for more reproducible builds -GO_FLAGS += -trimpath +GO_FLAGS += "-ldflags=-s -w -X 'github.com/tlhunter/mig/commands.Version=$(MIG_VERSION)' -X 'github.com/tlhunter/mig/commands.BuildTime=$(BUILD_TIME)'" build: go build $(GO_FLAGS) -o mig diff --git a/README.md b/README.md index b5420d3..62d3f28 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,9 @@ MIG_MIGRATIONS="./db" mig # create the necessary migration tables mig init +# get version information +mig version + # list all migrations mig list @@ -156,4 +159,15 @@ DROP TABLE accounts; --END MIGRATION DOWN-- ``` -Transactions should only be disabled when a situation calls for it, like when using `CREATE INDEX CONCURRENTLY`. When in doubt, leave transactions enabled. \ No newline at end of file +Transactions should only be disabled when a situation calls for it, like when using `CREATE INDEX CONCURRENTLY`. When in doubt, leave transactions enabled. + + +## Development + +Checkout the project then run the following commands to install dependencies, build, and run the program: + +```sh +go get +make +./mig version +``` \ No newline at end of file diff --git a/commands/dispatch.go b/commands/dispatch.go index 2d569fb..491ee1f 100644 --- a/commands/dispatch.go +++ b/commands/dispatch.go @@ -50,6 +50,9 @@ func Dispatch(cfg config.MigConfig) { case "all": CommandAll(cfg) + case "version": + CommandVersion(cfg) + default: color.White("unsupported command %s", os.Args[1]) os.Exit(10) diff --git a/commands/version.go b/commands/version.go new file mode 100644 index 0000000..f7be718 --- /dev/null +++ b/commands/version.go @@ -0,0 +1,16 @@ +package commands + +import ( + "github.com/fatih/color" + "github.com/tlhunter/mig/config" +) + +var Version string // set at compile time +var BuildTime string // set at compile time + +func CommandVersion(cfg config.MigConfig) error { + color.Green("mig version: " + Version) + color.White("build time: " + BuildTime) + + return nil +} diff --git a/go.mod b/go.mod index 341af19..61597f7 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,12 @@ module github.com/tlhunter/mig go 1.19 require ( - github.com/fatih/color v1.13.0 // indirect - github.com/joho/godotenv v1.4.0 // indirect - github.com/lib/pq v1.10.7 // indirect + github.com/fatih/color v1.13.0 + github.com/joho/godotenv v1.4.0 + github.com/lib/pq v1.10.7 +) + +require ( github.com/mattn/go-colorable v0.1.9 // indirect github.com/mattn/go-isatty v0.0.14 // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect diff --git a/main.go b/main.go index 726fc34..9a409cb 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "os" + "github.com/fatih/color" "github.com/tlhunter/mig/commands" "github.com/tlhunter/mig/config" ) @@ -11,7 +12,7 @@ func main() { cfg, err := config.GetConfig() if err != nil { - os.Stderr.WriteString("unable to parse configuration\n") + color.Red("unable to parse configuration\n") os.Stderr.WriteString(err.Error() + "\n") os.Exit(1) } diff --git a/version.txt b/version.txt index 6e8bf73..17e51c3 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.1.0 +0.1.1