diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml new file mode 100644 index 0000000..66437e7 --- /dev/null +++ b/.github/workflows/build_test.yml @@ -0,0 +1,70 @@ +name: Build Test + +on: + push: + branches: + - main + paths: + - "**/*.go" + - "go.mod" + - "go.sum" + - ".github/workflows/*.yml" + pull_request: + types: [opened, synchronize, reopened] + paths: + - "**/*.go" + - "go.mod" + - "go.sum" + - ".github/workflows/*.yml" + +jobs: + build: + permissions: + contents: write + strategy: + matrix: + # Include amd64 on all platforms. + goos: [linux] + goarch: [amd64, arm64] + include: + # BEGIN Linux ARM64 + - goos: linux + goarch: arm64 + # END Linux ARM64 + # BEGIN Linux AMD64 + - goos: linux + goarch: amd64 + # END Linux AMD64 + fail-fast: false + + runs-on: ubuntu-latest + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + GOARM: ${{ matrix.goarm }} + CGO_ENABLED: 0 + steps: + - name: Checkout codebase + uses: actions/checkout@v4 + with: + ref: main + + - name: Show workflow information + run: | + export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json) + export VERSIONNUM=$(cat main.go | grep "version :=" | awk -F "\"" '{print $2}') + echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME" + echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV + echo "VERSION=$VERSIONNUM" >> $GITHUB_ENV + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + + - name: Get project dependencies + run: go mod download + + - name: Build db_backup_go + run: | + go build \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4e6fb41..87bedb3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,24 +1,12 @@ name: Build and Release on: - workflow_dispatch: - release: - types: [published] - push: + pull_request: branches: - main paths: - - "**/*.go" - - "go.mod" - - "go.sum" - - ".github/workflows/*.yml" - pull_request: - types: [opened, synchronize, reopened] - paths: - - "**/*.go" - - "go.mod" - - "go.sum" - - ".github/workflows/*.yml" + - "../version.go" + jobs: build: permissions: @@ -48,12 +36,16 @@ jobs: steps: - name: Checkout codebase uses: actions/checkout@v4 + with: + ref: main - name: Show workflow information run: | export _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json) - echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME" + export VERSIONNUM=$(cat main.go | grep "version :=" | awk -F "\"" '{print $2}') + echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME" echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV + echo "VERSION=$VERSIONNUM" >> $GITHUB_ENV - name: Set up Go uses: actions/setup-go@v5 with: @@ -66,11 +58,6 @@ jobs: - name: Build db_backup_go run: | go build - - - name: Get Version Number - run: | - versionNum=$(cat main.go | grep "version :=" | awk -F "\"" '{print $2}') - echo "VERSION=$versionNum" >> $GITHUB_ENV - name: Change the name run: | diff --git a/main.go b/main.go index 1cc2e5f..e6e89c4 100644 --- a/main.go +++ b/main.go @@ -16,11 +16,10 @@ var f embed.FS // 程序主入口 func main() { - version := "1.2.1" - printVersion := flag.Bool("version", false, "[--version]") + isPrintVersion := flag.Bool("version", false, "[--version]") flag.Parse() - if *printVersion { - println(version) + if *isPrintVersion { + GetVersion() os.Exit(0) } diff --git a/version.go b/version.go new file mode 100644 index 0000000..fbedfc0 --- /dev/null +++ b/version.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +var ( + x byte = 1 + y byte = 2 + z byte = 1 +) + +func GetVersion() { + fmt.Printf("db_backup_go\nversion: %v.%v.%v", x, y, z) +}