From 72d2fe9ad832efe83afc4b2ef853c4da2b53dc7f Mon Sep 17 00:00:00 2001 From: Timur Zununbekov Date: Tue, 20 Feb 2024 16:02:52 +0600 Subject: [PATCH] Test env setup --- .github/workflows/build-packages.yml | 44 ++++++++++++++++++++----- .github/workflows/tests-and-linters.yml | 3 +- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-packages.yml b/.github/workflows/build-packages.yml index 957e694235..aafce99fea 100644 --- a/.github/workflows/build-packages.yml +++ b/.github/workflows/build-packages.yml @@ -21,6 +21,9 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Setup Go uses: actions/setup-go@v5 with: @@ -28,14 +31,39 @@ jobs: - name: Prepare environment run: | - echo "BUILD_NUMBER=${{ github.repository }}-${{ github.workflow }}-${{ github.run_id }}-ghactions" >> $GITHUB_ENV - echo "BUILD_COMMIT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV - echo "BUILD_BRANCH_SAFE=${{ github.ref }}" >> $GITHUB_ENV - echo "BUILD_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - echo "BUILD_BRANCH=${{ github.ref }}" >> $GITHUB_ENV + RELEASE_BUILD=false + if [[ "${GITHUB_REF}" == /refs/tags/* ]]; then RELEASE_BUILD=true; fi - - name: Generate env file - run: go run mage.go -v GenerateEnvFile + RC_BUILD=false + if [[ "${GITHUB_REF}" == /refs/tags/*-rc ]]; then RC_BUILD=true; fi + + SNAPSHOT_BUILD=false + if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then SNAPSHOT_BUILD=true; fi + + PR_BUILD=false + if [[ "${SNAPSHOT_BUILD}" == "false" && "${RELEASE_BUILD}" == "false" ]]; then PR_BUILD=true; fi + + BUILD_NUMBER="${{ github.run_id }}"-ghactions + + if [[ "${RELEASE_BUILD}" == "true" ]]; then + BUILD_VERSION="${GITHUB_REF#/refs/tags/}"; + elif [[ "${SNAPSHOT_BUILD}" == "true" ]]; then + BUILD_VERSION="$(git describe --abbrev=0 --tags)"-1snapshot-"$(date '+%Y%m%dT%H%M')"-"$(echo ${GITHUB_SHA} | cut -c1-8)"; + elif [[ "${PR_BUILD}" == "true" ]]; then + BUILD_VERSION="$(git describe --abbrev=0 --tags)"-1branch-"${GITHUB_REF_NAME}"; + fi + + cat <> env.sh + export RELEASE_BUILD=$RELEASE_BUILD; + export RC_BUILD=$RC_BUILD; + export SNAPSHOT_BUILD=$SNAPSHOT_BUILD; + export BUILD_NUMBER=$BUILD_NUMBER; + export BUILD_VERSION=$BUILD_VERSION; + EOT + + + # - name: Generate env file + # run: go run mage.go -v GenerateEnvFile # - name: Create bucket # if: github.event_name == 'push' @@ -44,7 +72,7 @@ jobs: - uses: actions/upload-artifact@v4 with: name: env.sh - path: build/env.sh + path: env.sh build-packages: runs-on: ubuntu-latest diff --git a/.github/workflows/tests-and-linters.yml b/.github/workflows/tests-and-linters.yml index 1e1d6d26ba..798f8e7179 100644 --- a/.github/workflows/tests-and-linters.yml +++ b/.github/workflows/tests-and-linters.yml @@ -1,6 +1,7 @@ name: Tests -# on: +on: # pull_request: + workflow_call: env: GOFLAGS: "-count=1"