diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60a9551..eb55427 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,19 +4,51 @@ on: branches: - main jobs: + version: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + - name: setup node/npm + uses: actions/setup-node@v2 + with: + node-version: 12 + - name: install yarn + run: npm install --global yarn + - name: install semantic-release + run: yarn install + - name: semantic release dry run to check next version + run: npx semantic-release --dryRun | tee results + - name: show semanti release results + run: cat results + - name: determine next version + run: cat results | grep -oP 'Published release \K.*? ' >> version + - name: Check next version + run: cat version + - name: upload version file as an artifact + uses: actions/upload-artifact@v2 + with: + name: version + path: version build-linux-amd64: runs-on: ubuntu-latest steps: - name: checkout uses: actions/checkout@v2 + - name: download next version artifact + uses: actions/download-artifact@v2 + name: version + path: ./ + - name: Check next version + run: cat version - name: setup go uses: actions/setup-go@v2 with: - go-version: '^1.13.1' + go-version: '^1.16.5' - name: make release folder run: mkdir -p .releases/linux-amd64 - name: build - run: GOOS=linux GOARCH=amd64 go build -o .releases/linux-amd64 github.com/nosebit/act + run: GOOS=linux GOARCH=amd64 go build -o .releases/linux-amd64 -ldflags="-X 'github.com/nosebit/act/cmd.BinVersion=v$(cat version)' -X 'github.com/nosebit/act/cmd.BinOS=v$GOOS' -X 'github.com/nosebit/act/cmd.BinArch=v$GOARCH'" github.com/nosebit/act - name: compress release folder run: tar czfv .releases/linux-amd64.tar.gz .releases/linux-amd64/ - name: upload release artifact @@ -29,14 +61,20 @@ jobs: steps: - name: checkout uses: actions/checkout@v2 + - name: download next version artifact + uses: actions/download-artifact@v2 + name: version + path: ./ + - name: Check next version + run: cat version - name: setup go uses: actions/setup-go@v2 with: - go-version: '^1.13.1' + go-version: '^1.16.5' - name: make release folder run: mkdir -p .releases/darwin-amd64 - name: build - run: GOOS=darwin GOARCH=amd64 go build -o .releases/darwin-amd64 github.com/nosebit/act + run: GOOS=darwin GOARCH=amd64 go build -o .releases/linux-amd64 -ldflags="-X 'github.com/nosebit/act/cmd.BinVersion=v$(cat version)' -X 'github.com/nosebit/act/cmd.BinOS=v$GOOS' -X 'github.com/nosebit/act/cmd.BinArch=v$GOARCH'" github.com/nosebit/act - name: compress release folder run: tar czfv .releases/darwin-amd64.tar.gz .releases/darwin-amd64/ - name: upload release artifact diff --git a/cmd/cmd.go b/cmd/cmd.go index eb17bb0..c5aa63b 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -5,7 +5,9 @@ package cmd import ( "flag" + "fmt" "os" + "runtime" "github.com/nosebit/act/run" ) @@ -19,6 +21,13 @@ import ( */ var cmdName string +//############################################################ +// Exposed Variables +//############################################################ +var BinVersion = "development" +var BinOS = "" +var BinArch = "" + //############################################################ // Exposed Functions //############################################################ @@ -30,6 +39,19 @@ func Exec(args []string) { cmdName = args[0] switch cmdName { + case "version": + binOS := BinOS + binArch := BinArch + + if binOS == "" { + binOS = runtime.GOOS + } + + if binArch == "" { + binArch = runtime.GOARCH + } + + fmt.Printf("act version %s %s/%s\n", BinVersion, binOS, binArch) case "run": run.Exec(args[1:]) case "log":