From 64697d304742c1c390ee74fa092bfa22e2c7c86f Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Sat, 14 Jan 2023 15:25:15 -0500 Subject: [PATCH] refactor(scripts): use exit code in scripts instead of echo (#1736) Signed-off-by: Artur Troian --- .github/workflows/release-dry-run.yaml | 3 --- .github/workflows/release.yaml | 19 +++++++++++++++---- Makefile | 4 ++-- script/genchangelog.sh | 4 ++-- script/is_prerelease.sh | 2 +- script/mainnet-from-tag.sh | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release-dry-run.yaml b/.github/workflows/release-dry-run.yaml index f1cf4e0b7b..ab64d68a3d 100644 --- a/.github/workflows/release-dry-run.yaml +++ b/.github/workflows/release-dry-run.yaml @@ -32,8 +32,5 @@ jobs: run: echo "RELEASE_TAG=v$(./script/semver.sh bump patch $(git describe --tags --abbrev=0))" >> $GITHUB_ENV - name: git tag run: git tag -a ${{ env.RELEASE_TAG }} -m ${{ env.RELEASE_TAG }} - - name: detect network from tag - run: echo "MAINNET=$(./script/mainnet-from-tag.sh ${{ env.RELEASE_TAG }})" >> $GITHUB_ENV - - run: echo "Building for MAINNET=${{ env.MAINNET }}" - name: release dry-run run: make release diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b22d646297..df84743d02 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -28,7 +28,7 @@ jobs: - name: release version run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - name: detect network from release - run: echo "MAINNET=$(./script/mainnet-from-tag.sh ${{ env.RELEASE_TAG }})" >> $GITHUB_ENV + run: echo "MAINNET=$(./script/mainnet-from-tag.sh ${{ env.RELEASE_TAG }} && echo 'true' && echo 'false')" >> $GITHUB_ENV - run: echo "Building for MAINNET=${{ env.MAINNET }}" - if: (github.ref == 'refs/heads/master') || (github.ref == 'refs/heads/mainnet/main') name: release dry-run GORELEASER_SKIP_VALIDATE=true @@ -54,13 +54,24 @@ jobs: runs-on: ubuntu-latest needs: [ goreleaser ] steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: release version + run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - name: check if pre-release + id: check run: | - echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - - name: notify homebrew with new release - uses: benc-uk/workflow-dispatch@v121 + is_prerelease=$(./script/is_prerelease.sh ${{ env.RELEASE_TAG }}; echo $?) + is_mainnet=$(./script/mainnet-from-tag.sh ${{ env.RELEASE_TAG }}; echo $?) + echo "is_prerelease=${is_prerelease}" >> $GITHUB_OUTPUT + echo "is_mainnet=${is_mainnet}" >> $GITHUB_OUTPUT + - name: notify homebrew with a new release + if: contains(steps.check.outputs.is_mainnet, '0') && contains(steps.check.outputs.is_prerelease, '1') + uses: benc-uk/workflow-dispatch@v1 with: token: ${{ secrets.GORELEASER_ACCESS_TOKEN }} repo: akash-network/homebrew-tap + ref: refs/heads/master workflow: akash inputs: '{"tag": "${{ env.RELEASE_TAG }}"}' diff --git a/Makefile b/Makefile index b890dec7dd..421864bcc7 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ GIT_HEAD_COMMIT_SHORT := $(shell git rev-parse --short HEAD) GIT_HEAD_ABBREV := $(shell git rev-parse --abbrev-ref HEAD) RELEASE_TAG ?= $(shell git describe --tags --abbrev=0) -IS_PREREL := $(shell $(ROOT_DIR)/script/is_prerelease.sh "$(RELEASE_TAG)") -IS_MAINNET := $(shell $(ROOT_DIR)/script/mainnet-from-tag.sh "$(RELEASE_TAG)") +IS_PREREL := $(shell $(ROOT_DIR)/script/is_prerelease.sh "$(RELEASE_TAG)" && echo "true" || echo "false") +IS_MAINNET := $(shell $(ROOT_DIR)/script/mainnet-from-tag.sh "$(RELEASE_TAG)" && echo "true" || echo "false") IS_STABLE ?= false GO_LINKMODE ?= external diff --git a/script/genchangelog.sh b/script/genchangelog.sh index 269ff809ca..421a3d8844 100755 --- a/script/genchangelog.sh +++ b/script/genchangelog.sh @@ -27,8 +27,8 @@ fi to_tag=$1 # s1 -is_mainnet=$("${SCRIPT_DIR}"/mainnet-from-tag.sh "$to_tag") -if [[ $is_mainnet == false ]]; then +# shellcheck disable=SC1073 +if ! "${SCRIPT_DIR}"/mainnet-from-tag.sh "$to_tag" ; then version_rel="^[v|V]?(0|[1-9][0-9]*)\\.(\\d*[13579])\\.(0|[1-9][0-9]*)$" version_prerel="^[v|V]?(0|[1-9][0-9]*)\\.(\\d*[13579])\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$" else diff --git a/script/is_prerelease.sh b/script/is_prerelease.sh index 363907f7bc..fe88e404a8 100755 --- a/script/is_prerelease.sh +++ b/script/is_prerelease.sh @@ -9,4 +9,4 @@ if [[ $# -ne 1 ]]; then exit 1 fi -[[ -n $("${SCRIPT_DIR}"/semver.sh get prerel "$1") ]] && echo true || echo false +[[ -n $("${SCRIPT_DIR}"/semver.sh get prerel "$1") ]] && exit 0 || exit 1 diff --git a/script/mainnet-from-tag.sh b/script/mainnet-from-tag.sh index 979b8905da..4976956c3c 100755 --- a/script/mainnet-from-tag.sh +++ b/script/mainnet-from-tag.sh @@ -9,4 +9,4 @@ if [[ $# -ne 1 ]]; then exit 1 fi -[[ $(($("${SCRIPT_DIR}"/semver.sh get minor "$1") % 2)) -eq 0 ]] && echo true || echo false +[[ $(($("${SCRIPT_DIR}"/semver.sh get minor "$1") % 2)) -eq 0 ]] && exit 0 && exit 1