From ea400da73bd24cd8134ebe96b34619ba6b7389e1 Mon Sep 17 00:00:00 2001 From: Ales Raszka Date: Thu, 12 Sep 2024 10:54:32 +0200 Subject: [PATCH] Run integration tests on PR A tests will be executed automatically on each PR after a PR gets approved. To reduce amount of test run we don't run a test on PR push event and instead trigger it by label. JIRA: ISV-4199 Signed-off-by: Ales Raszka --- ...tegration-tests.yml => build-and-test.yml} | 81 +++++++++++++++++-- .github/workflows/build-image.yml | 44 ---------- .github/workflows/validation.yml | 41 ---------- 3 files changed, 74 insertions(+), 92 deletions(-) rename .github/workflows/{integration-tests.yml => build-and-test.yml} (51%) delete mode 100644 .github/workflows/build-image.yml delete mode 100644 .github/workflows/validation.yml diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/build-and-test.yml similarity index 51% rename from .github/workflows/integration-tests.yml rename to .github/workflows/build-and-test.yml index e3f3a1cd9..ab628ba07 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/build-and-test.yml @@ -1,19 +1,87 @@ --- -name: Integration Tests +name: Build and test on: # yamllint disable-line rule:truthy - workflow_run: - workflows: - - Build + push: branches: - main - types: - - completed + pull_request: + types: [opened, synchronize, reopened, labeled] workflow_dispatch: jobs: + tox: + name: Run unit tests and linters + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up PDM + uses: pdm-project/setup-pdm@v4 + with: + python-version: "3.11" + + - name: Install non-python dependencies + run: | + sudo apt-get update && sudo apt-get install -y libkrb5-dev + + - name: Install Hadolint via Brew + run: | + NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + /home/linuxbrew/.linuxbrew/bin/brew install hadolint + sudo ln -s /home/linuxbrew/.linuxbrew/bin/hadolint /usr/bin/ + + - name: Install Python dependencies + run: | + pdm sync -dG tox + python3 -m pip install ansible-lint + + - name: Run Tests + run: | + pdm run -v tox + + build: + name: Build and push image + runs-on: ubuntu-latest + + steps: + - name: Set variables + id: set-vars + run: | + if [[ $GITHUB_REF_NAME == 'main' ]]; then + echo "tags=latest ${{ github.sha }}" >> $GITHUB_OUTPUT + else + echo "tags=${{ github.sha }}">> $GITHUB_OUTPUT + fi + - uses: actions/checkout@v4 + + - name: Build Image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: operator-pipelines-images + tags: ${{ steps.set-vars.outputs.tags }} + dockerfiles: | + ./operator-pipeline-images/Dockerfile + + - name: Push To quay.io + id: push-to-quay + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: quay.io/redhat-isv + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Print image url + run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" + integration-tests: + needs: [build] + if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event.label.name == 'ready-for-testing' strategy: matrix: test_type: @@ -74,7 +142,6 @@ jobs: options: | -e "test_type=${{ matrix.test_type }}" -e "oc_namespace=int-tests-${{ matrix.test_type }}-${{ github.run_number }}-${{ github.run_attempt }}" - -e "integration_tests_operator_bundle_version=0.1.${{ github.run_number }}-${{ github.run_attempt }}" -e "operator_pipeline_image_tag=${{ github.sha }}" -e "suffix=${{ steps.prepare.outputs.suffix }}" --skip-tags=signing-pipeline diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml deleted file mode 100644 index c514bead3..000000000 --- a/.github/workflows/build-image.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -name: Build - -on: # yamllint disable-line rule:truthy - workflow_run: - workflows: - - validation - branches: - - main - types: - - completed - workflow_dispatch: - -jobs: - build: - name: Build and push image - runs-on: ubuntu-latest - - if: ${{ github.event.workflow_run.conclusion == 'success' }} - - steps: - - uses: actions/checkout@v4 - - - name: Build Image - id: build-image - uses: redhat-actions/buildah-build@v2 - with: - image: operator-pipelines-images - tags: latest ${{ github.sha }} - dockerfiles: | - ./operator-pipeline-images/Dockerfile - - - name: Push To quay.io - id: push-to-quay - uses: redhat-actions/push-to-registry@v2 - with: - image: ${{ steps.build-image.outputs.image }} - tags: ${{ steps.build-image.outputs.tags }} - registry: quay.io/redhat-isv - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: Print image url - run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml deleted file mode 100644 index 157db2dae..000000000 --- a/.github/workflows/validation.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -name: validation - -on: # yamllint disable-line rule:truthy - pull_request: - push: - branches: - - main - workflow_dispatch: - -jobs: - tox: - name: Run unit tests and linters - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up PDM - uses: pdm-project/setup-pdm@v4 - with: - python-version: "3.11" - - - name: Install non-python dependencies - run: | - sudo apt-get update && sudo apt-get install -y libkrb5-dev - - - name: Install Hadolint via Brew - run: | - NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - /home/linuxbrew/.linuxbrew/bin/brew install hadolint - sudo ln -s /home/linuxbrew/.linuxbrew/bin/hadolint /usr/bin/ - - - name: Install Python dependencies - run: | - pdm sync -dG tox - python3 -m pip install ansible-lint - - - name: Run Tests - run: | - pdm run -v tox