From dc40be55ef5886883282356565d7daadc3f14074 Mon Sep 17 00:00:00 2001 From: nixargh Date: Fri, 6 Sep 2024 12:05:19 +0300 Subject: [PATCH] CI: adjust build steps --- .github/workflows/ci.yaml | 69 +++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fab7182b..a52a0711 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,29 +1,37 @@ --- name: CI -on: [push, pull_request] +on: + - push + - pull_request jobs: check: name: Check runs-on: ubuntu-latest - # Execute the checks inside the container instead the VM. container: golangci/golangci-lint:v1.60.3 steps: - uses: actions/checkout@v4 + - name: 'Remove .git directory (fix for "error obtaining VCS status: exit status 128")' run: rm -fr ./.git - - run: golangci-lint run -v + + - name: Run GolangCI linters + run: golangci-lint run -v unit-test: name: Unit test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version-file: go.mod - - run: make ci-test + + - name: Run Unit tests + run: make ci-test + - uses: codecov/codecov-action@v4.5.0 with: token: ${{ secrets.CODECOV_UPLOAD_TOKEN }} @@ -35,26 +43,29 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version-file: go.mod - - name: Execute tests + + - name: Execute Helm tests env: HELM_VERSION: v3.6.3 - run: | - # Get dependencies. - echo "Getting dependencies..." - curl -L https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar -xz && mv ./linux-amd64/helm /usr/local/bin && chmod +x /usr/local/bin/helm - make ci-helm-test + run: + - echo "Getting dependencies..." + - curl -L https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar -xz && mv ./linux-amd64/helm /usr/local/bin && chmod +x /usr/local/bin/helm + - make ci-helm-test integration-test-cli: name: Integration test CLI runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version-file: go.mod + - name: Execute tests run: | # Build binary. @@ -74,13 +85,21 @@ jobs: name: Tagged release binaries runs-on: ubuntu-latest steps: - - run: echo "VERSION=${GITHUB_REF#refs/*/}" >> ${GITHUB_ENV} # Sets VERSION env var. - uses: actions/checkout@v4 + + - name: Extract tag + shell: bash + run: echo "tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/tags/}}" >> $GITHUB_OUTPUT + id: extract_tag + - name: Build binaries - run: | - mkdir -p ./bin - chmod -R 0777 ./bin - make build-all + env: + VERSION: "${{ steps.extract_tag.outputs.tag }}" + run: + - mkdir -p ./bin + - chmod -R 0777 ./bin + - make build-all + - name: Upload binaries uses: xresloader/upload-to-github-release@v1.6.0 env: @@ -93,17 +112,25 @@ jobs: rolling-release-images: env: PROD_IMAGE_NAME: ghcr.io/${GITHUB_REPOSITORY} - VERSION: dev # needs: [check, unit-test, integration-test-cli, integration-test-k8s, helm-chart-test] needs: [check, unit-test, integration-test-cli, helm-chart-test] name: Release images runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + - name: Docker login run: docker login ghcr.io -u ${{ github.actor }} -p "${{ secrets.GITHUB_TOKEN }}" + - name: Build and publish docker images run: make build-publish-image-all + env: + VERSION: "branch-${{ steps.extract_branch.outputs.branch }}" tagged-release-images: # Only on tags. @@ -116,11 +143,19 @@ jobs: name: Tagged release images runs-on: ubuntu-latest steps: - - run: echo "VERSION=${GITHUB_REF#refs/*/}" >> ${GITHUB_ENV} # Sets VERSION env var. - uses: actions/checkout@v4 + + - name: Extract tag + shell: bash + run: echo "tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/tags/}}" >> $GITHUB_OUTPUT + id: extract_tag + - name: Docker login run: docker login ghcr.io -u ${{ github.actor }} -p "${{ secrets.GITHUB_TOKEN }}" + - name: Build and publish docker images + env: + VERSION: "${{ steps.extract_tag.outputs.tag }}" run: make build-publish-image-all # integration-test-k8s: