From 86af854c42a98dab76d2fe5a545923283a066164 Mon Sep 17 00:00:00 2001 From: Raghavendra Talur Date: Wed, 9 Oct 2024 15:40:16 -0400 Subject: [PATCH] ci Signed-off-by: Raghavendra Talur --- .github/workflows/talurci.yaml | 210 +++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 .github/workflows/talurci.yaml diff --git a/.github/workflows/talurci.yaml b/.github/workflows/talurci.yaml new file mode 100644 index 000000000..78e816210 --- /dev/null +++ b/.github/workflows/talurci.yaml @@ -0,0 +1,210 @@ +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 + +--- +# yamllint disable rule:line-length + +name: TalurCI + +# This workflow will run when developer push a topic branch to their +# fork in github, minimizing noise for maintainers. This +# workflow also runs on nightly basis at 12:00 AM (00:00 UTC) + +on: # yamllint disable-line rule:truthy + push: + pull_request: + schedule: + - cron: '0 0 * * *' + +env: + # Values can be overriden by repository variables. + IMAGE_TAG_BASE: ${{ vars.IMAGE_TAG_BASE || 'quay.io/raghavendra_talur/ramen' }} + IMAGE_REPOSITORY: ${{ vars.IMAGE_REPOSITORY || 'raghavendra_talur' }} + IMAGE_NAME: ${{ vars.IMAGE_NAME || 'ramen' }} + OPERATOR_SUGGESTED_NAMESPACE: ${{ vars.OPERATOR_SUGGESTED_NAMESPACE || 'ramen-system' }} + # Constants + GO_VERSION: "1.22" + IMAGE_REGISTRY: "quay.io" + IMAGE_TAG: "workload" + DOCKERCMD: "podman" + DRIVER: "container" +defaults: + run: + shell: bash +jobs: + lint: + name: Linters + runs-on: ubuntu-20.04 + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install prereqs + run: | + echo 'APT::Acquire::Retries "5";' | sudo tee /etc/apt/apt.conf.d/80-retries + sudo apt-get update + sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip ruby + sudo gem install mdl + sudo pip3 install yamllint + + - name: Run linters + run: ./hack/pre-commit.sh + + - name: Check that generated files were not modified + run: | + make generate + make manifests + go mod tidy + git --no-pager diff + git diff-index --quiet HEAD + + golangci: + name: Golangci Lint + runs-on: ubuntu-20.04 + strategy: + matrix: + directory: [., api] + # golangci-lint has a limitation that it doesn't lint subdirectories if + # they are a different module. + # see https://github.com/golangci/golangci-lint/issues/828 + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Setup go + uses: actions/setup-go@v5 + with: + # when the files to be extracted are already present, + # tar extraction in Golangci Lint fails with the "File exists" + # errors. These files appear to be present because of + # cache in setup-go, on disabling the cache we are no more seeing + # such error. Cache is to be enabled once the fix is available for + # this issue. + go-version: ${{ env.GO_VERSION }} + cache: false + + - name: GolangCI Lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.55.2 + working-directory: ${{ matrix.directory }} + + unit-test: + name: Unit tests + runs-on: ubuntu-20.04 + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Run unit tests + run: make test + + build-image: + name: Build image + runs-on: ubuntu-20.04 + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: update image tag + run: | + echo "IMAGE_TAG=workload-$(date +'%Y%m%d')-${{ github.sha }}" >> $GITHUB_ENV + + - name: Build image + run: make docker-build + + - name: Export image + run: ${{env.DOCKERCMD}} save -o /tmp/ramen-operator.tar ${IMAGE_TAG_BASE}-operator:${IMAGE_TAG} + + - name: Save image artifact + uses: actions/upload-artifact@v4 + with: + name: ramen-operator + path: /tmp/ramen-operator.tar + retention-days: 1 + + publish-image: + name: Publish built image + needs: [lint, golangci, unit-test, build-image] + if: > + (vars.PUBLISH_IMAGES == 'true') && + (github.event_name == 'push') && + (github.ref == 'refs/heads/main' || + startsWith(github.ref, 'refs/heads/release-') || + startsWith(github.ref, 'refs/tags/v')) + runs-on: ubuntu-20.04 + steps: + - name: Download image artifact + uses: actions/download-artifact@v4 + with: + name: ramen-operator + path: /tmp + + - name: Load image artifact + run: | + ${{env.DOCKERCMD}} load -i /tmp/ramen-operator.tar + + - name: Login to Quay + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_ROBOT_TOKEN }} + + - name: Determine image tag + run: | + [[ "${{ github.ref }}" =~ ^refs\/(heads|tags)\/(release-)?(.*) ]] + echo "heads or tags? ${BASH_REMATCH[1]}" + echo "release? ${BASH_REMATCH[2]}" + echo "version? ${BASH_REMATCH[3]}" + TAG="" + if test "${BASH_REMATCH[1]}" = "heads"; then + if test "${BASH_REMATCH[2]}" = "" && test "${BASH_REMATCH[3]}" = "main"; then + TAG="canary" + elif test "${BASH_REMATCH[2]}" = "release-"; then + TAG="${BASH_REMATCH[3]}-canary" + fi + elif test "${BASH_REMATCH[1]}" == "tags" && test "${BASH_REMATCH[2]}" = ""; then + TAG="${BASH_REMATCH[3]}" + fi + test "${TAG}" = "" && exit 1 + echo "Publish image tag ${TAG}" + echo "publish_image_tag=${TAG}" >> $GITHUB_ENV + + - name: Push operator image to Quay + run: | + ${{env.DOCKERCMD}} tag "${IMAGE_TAG_BASE}-operator:${IMAGE_TAG}" "${IMAGE_TAG_BASE}-operator:${{ env.publish_image_tag }}" + ${{env.DOCKERCMD}} push "${IMAGE_TAG_BASE}-operator:${{ env.publish_image_tag }}" + + # TODO: We do not need to build bundles and catalogs each time, fix once we reach alpha + - name: Checkout source + uses: actions/checkout@v4 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Build and push bundle images to Quay + run: | + IMAGE_TAG="${{ env.publish_image_tag }}" make bundle-build bundle-push + + - name: Build and push catalog image to Quay + run: | + IMAGE_TAG="${{ env.publish_image_tag }}" make catalog-build catalog-push + # TODO: Test built bundles and catalog based install