From 047a5fdabd6c0eb6b6a40c859590f1b36c420710 Mon Sep 17 00:00:00 2001 From: Dhruv Thakur <13575379+dhth@users.noreply.github.com> Date: Mon, 5 Aug 2024 23:05:17 +0530 Subject: [PATCH] ci: add backwards compatibility tests (#23) --- .github/workflows/back-compat-pr.yml | 43 ++++++++++++++++++++++++++++ .github/workflows/back-compat.yml | 41 ++++++++++++++++++++++++++ .github/workflows/build.yml | 5 ++++ cmd/root.go | 4 +-- main.go | 9 ++++-- 5 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/back-compat-pr.yml create mode 100644 .github/workflows/back-compat.yml diff --git a/.github/workflows/back-compat-pr.yml b/.github/workflows/back-compat-pr.yml new file mode 100644 index 0000000..51aca4f --- /dev/null +++ b/.github/workflows/back-compat-pr.yml @@ -0,0 +1,43 @@ +name: back-compat PR + +on: + pull_request: + paths: + - "go.*" + - "**/*.go" + - ".github/workflows/*.yml" + +permissions: + contents: read + +env: + GO_VERSION: '1.22.5' + +jobs: + check-back-compat: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: build head + run: | + go build -o omm_head + cp omm_head /var/tmp + - uses: actions/checkout@v4 + with: + ref: main + - name: build main + run: | + go build -o omm_main + cp omm_main /var/tmp + - name: Run last version + run: | + /var/tmp/omm_main --db-path=/var/tmp/throwaway.db 'test: a task from main' + - name: Run current version + run: | + /var/tmp/omm_head --db-path=/var/tmp/throwaway.db 'test: a task from PR HEAD' + /var/tmp/omm_head --db-path=/var/tmp/throwaway.db tasks diff --git a/.github/workflows/back-compat.yml b/.github/workflows/back-compat.yml new file mode 100644 index 0000000..32f98e2 --- /dev/null +++ b/.github/workflows/back-compat.yml @@ -0,0 +1,41 @@ +name: back-compat + +on: + push: + branches: [ "main" ] + +permissions: + contents: read + +env: + GO_VERSION: '1.22.5' + +jobs: + check-back-compat: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: build head + run: | + go build -o omm_head + cp omm_head /var/tmp + rm omm_head + - run: git checkout HEAD~1 + - name: build main + run: | + go build -o omm_prev + cp omm_prev /var/tmp + - name: Run last version + run: | + /var/tmp/omm_prev --db-path=/var/tmp/throwaway.db 'test: a task from previous commit' + - name: Run current version + run: | + /var/tmp/omm_head --db-path=/var/tmp/throwaway.db 'test: a task from main HEAD' + /var/tmp/omm_head --db-path=/var/tmp/throwaway.db tasks diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 947aacf..dff109d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,3 +33,8 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: v1.58 + - name: run omm + run: | + go build . + ./omm 'test: a task' + ./omm tasks diff --git a/cmd/root.go b/cmd/root.go index d4ff921..99515a3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -50,7 +50,7 @@ var ( updateContents string ) -func Execute(version string) { +func Execute(version string) error { rootCmd, err := NewRootCommand() rootCmd.Version = version @@ -59,7 +59,7 @@ func Execute(version string) { os.Exit(1) } - _ = rootCmd.Execute() + return rootCmd.Execute() } func setupDB(dbPathFull string) (*sql.DB, error) { diff --git a/main.go b/main.go index a4f01d9..476d444 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,10 @@ package main import ( - "github.com/dhth/omm/cmd" + "os" "runtime/debug" + + "github.com/dhth/omm/cmd" ) var ( @@ -17,5 +19,8 @@ func main() { v = info.Main.Version } } - cmd.Execute(v) + err := cmd.Execute(v) + if err != nil { + os.Exit(1) + } }