diff --git a/.github/workflows/publish-binaries.yml b/.github/workflows/publish-binaries.yml index 255408a..4ed090a 100644 --- a/.github/workflows/publish-binaries.yml +++ b/.github/workflows/publish-binaries.yml @@ -30,3 +30,4 @@ jobs: goarch: ${{ matrix.goarch }} goversion: "https://dl.google.com/go/go1.16.6.linux-amd64.tar.gz" extra_files: LICENSE README.md + ldflags: -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}" -X main.gitCommit=${{ github.sha }} -X main.gitRef=${{ github.ref }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e27a068..8106077 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,18 +17,11 @@ jobs: - name: Build run: | make build - - name: "Build Changelog" - id: build_changelog - uses: mikepenz/release-changelog-builder-action@v2 + - name: Setup Node.js + uses: actions/setup-node@v2 with: - commitMode: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create Release - uses: actions/create-release@v1 - with: - tag_name: v${{ github.run_number }} - release_name: v${{ github.run_number }} - body: ${{steps.github_release.outputs.changelog}} + node-version: "lts/*" + - name: Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: make setup_semantic_release && npx semantic-release diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..0e8769b --- /dev/null +++ b/.releaserc @@ -0,0 +1,16 @@ +{ + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/github", + { + "assets": "bin/*" + } + ], + "@semantic-release/changelog" + ], + "branches": [ + "main" + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 9339d31..957cba3 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,7 @@ run: go run main.go build: - go build -o bin/cli main.go + ./build.sh + +setup_semantic_release: + npm i @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/github @semantic-release/changelog \ No newline at end of file diff --git a/bin/cli b/bin/cli deleted file mode 100755 index e904478..0000000 Binary files a/bin/cli and /dev/null differ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..857c826 --- /dev/null +++ b/build.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +package_name="cloudstate-cli" + +platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/amd64" "linux/386") + +for platform in "${platforms[@]}" +do + platform_split=(${platform//\// }) + GOOS=${platform_split[0]} + GOARCH=${platform_split[1]} + output_name=$package_name'-'$GOOS'-'$GOARCH + if [ $GOOS = "windows" ]; then + output_name+='.exe' + fi + + env GOOS=$GOOS GOARCH=$GOARCH go build -o bin/$output_name $package + if [ $? -ne 0 ]; then + echo 'An error has occurred! Aborting the script execution...' + exit 1 + fi +done \ No newline at end of file