-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version command to output build information
Generating the version number before building and embedding it into the executable so that it can be outputted by the following command: `uipath version` `uipathcli v1.0.0 (windows, amd64)`
- Loading branch information
Showing
8 changed files
with
173 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ env: | |
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
UIPATHCLI_VERSION: ${{ steps.version.outputs.UIPATHCLI_VERSION }} | ||
env: | ||
CGO_ENABLED: "0" | ||
steps: | ||
|
@@ -17,10 +19,16 @@ jobs: | |
with: | ||
go-version: '1.22.2' | ||
cache: true | ||
- name: Version | ||
id: version | ||
run: | | ||
UIPATHCLI_VERSION=$(./version.sh "$UIPATHCLI_BASE_VERSION") | ||
echo "UIPATHCLI_VERSION=$(echo $UIPATHCLI_VERSION)" >> $GITHUB_ENV | ||
echo "UIPATHCLI_VERSION=$(echo $UIPATHCLI_VERSION)" >> $GITHUB_OUTPUT | ||
- name: Install dependencies | ||
run: go get . | ||
- name: Build | ||
run: go build . | ||
run: go build -ldflags="-X github.com/UiPath/uipathcli/commandline.Version=$UIPATHCLI_VERSION" . | ||
- name: Lint | ||
run: | | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
|
@@ -74,6 +82,8 @@ jobs: | |
needs: build | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
env: | ||
UIPATHCLI_VERSION: ${{ needs.build.outputs.UIPATHCLI_VERSION }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
@@ -83,6 +93,6 @@ jobs: | |
name: packages | ||
path: build/packages/ | ||
- name: Publish | ||
run: ./publish.sh "$UIPATHCLI_BASE_VERSION" | ||
run: ./publish.sh "$UIPATHCLI_VERSION" | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package commandline | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"runtime" | ||
) | ||
|
||
var Version = "main" | ||
|
||
// The VersionCommandHandler outputs the build information | ||
// | ||
// Example: | ||
// uipath --version | ||
// | ||
// uipathcli v1.0.0 (windows, amd64) | ||
type VersionCommandHandler struct { | ||
StdIn io.Reader | ||
StdOut io.Writer | ||
} | ||
|
||
func (h VersionCommandHandler) Execute() { | ||
fmt.Fprintf(h.StdOut, "uipathcli %s (%s, %s)\n", Version, runtime.GOOS, runtime.GOARCH) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestVersionOutput(t *testing.T) { | ||
context := NewContextBuilder(). | ||
Build() | ||
|
||
result := RunCli([]string{"version"}, context) | ||
|
||
if !strings.HasPrefix(result.StdOut, "uipathcli main") { | ||
t.Errorf("Did not return version information, got: %v", result.StdOut) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#! /bin/bash | ||
############################################################ | ||
# Generates the next version to publish | ||
# | ||
# DESCRIPTION: | ||
# This scripts retrieves the latest tag, increments the | ||
# version and creates a new release on GitHub. | ||
############################################################ | ||
|
||
set -o pipefail | ||
set -e | ||
|
||
############################################################ | ||
# Retrieves the latest version by sorting the git tags | ||
# | ||
# Returns: | ||
# The latest git tag | ||
############################################################ | ||
function get_latest_version() | ||
{ | ||
local version_filter="$1" | ||
|
||
git fetch --all --tags --quiet | ||
git tag | sort -V | grep "^$version_filter.*" | tail -1 || echo "$version_filter" | ||
} | ||
|
||
############################################################ | ||
# Increment patch version on the provided semver string | ||
# | ||
# Arguments: | ||
# - The version (semver format, e.g. 1.0.0) | ||
# | ||
# Returns: | ||
# Incremented patch version (e.g. 1.0.1) | ||
############################################################ | ||
function increment_patch_version() | ||
{ | ||
local version="$1" | ||
|
||
local array | ||
local IFS='.'; read -r -a array <<< "$version" | ||
if [ -z "${array[2]}" ]; then | ||
array[2]="0" | ||
else | ||
array[2]=$((array[2]+1)) | ||
fi | ||
echo "$(local IFS='.'; echo "${array[*]}")" | ||
} | ||
|
||
############################################################ | ||
# Create new tag | ||
# | ||
# Arguments: | ||
# - The tag name | ||
############################################################ | ||
function create_tag() | ||
{ | ||
local tag_name="$1" | ||
|
||
git tag "$tag_name" | ||
} | ||
|
||
############################################################ | ||
# Main | ||
############################################################ | ||
function main() | ||
{ | ||
local base_version="$1" | ||
local latest_version | ||
local new_version | ||
|
||
latest_version=$(get_latest_version "$base_version") | ||
new_version=$(increment_patch_version "$latest_version") | ||
echo "$new_version" | ||
} | ||
main "$1" |