Skip to content

Commit

Permalink
Merge pull request #34 from even0306/dev
Browse files Browse the repository at this point in the history
添加编译测试工作流
  • Loading branch information
even0306 authored Apr 6, 2024
2 parents 6fde45c + 618ddb5 commit a18731a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 25 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 8 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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: |
Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
13 changes: 13 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit a18731a

Please sign in to comment.