Skip to content

Commit

Permalink
CLOUDP-194416: Isolate CI unit tests to always run (#1095)
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Vazquez <[email protected]>
  • Loading branch information
josvazg authored Aug 17, 2023
1 parent e2a0bcc commit c408731
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 112 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/cloud-tests-forked.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CloudTestsForked

on:
workflow_call:
inputs:
forked:
type: boolean
required: false
default: false

concurrency:
group: cloud-tests-forked
cancel-in-progress: true

jobs:
allowed-forked:
name: Allowed action
runs-on: ubuntu-latest
if: |
${{ github.actor == 'dependabot[bot]' }} ||
contains(github.event.pull_request.labels.*.name, 'safe-to-test')
steps:
- name: allowed message
run: echo "Allowed to run"

int-tests:
needs: allowed-forked
uses: ./.github/workflows/integration-test.yml
secrets: inherit
with:
forked: true

e2e-tests-forked:
needs: allowed-forked
uses: ./.github/workflows/test-e2e.yml
secrets: inherit
with:
forked: true

openshift-upgrade-test:
needs: allowed-forked
uses: ./.github/workflows/openshift-upgrade-test.yaml
secrets: inherit
with:
forked: true
67 changes: 67 additions & 0 deletions .github/workflows/cloud-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CloudTests

on:
workflow_call:
inputs:
forked:
type: boolean
required: false
default: false

concurrency:
group: cloud-tests
cancel-in-progress: true

jobs:
allowed:
name: Allowed
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
github.ref == 'refs/heads/main' ||
(github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
steps:
- name: allowed message
run: echo "Allowed to run"
- name: check Github action bot comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v2
id: find-bot-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: 'https://app.codecov.io/github/mongodb/mongodb-atlas-kubernetes/commit'
- name: edit comment if exists
if: github.event_name == 'pull_request' && steps.find-bot-comment.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v3
with:
edit-mode: replace
comment-id: ${{ steps.find-bot-comment.outputs.comment-id }}
body: https://app.codecov.io/github/mongodb/mongodb-atlas-kubernetes/commit/${{ github.event.pull_request.head.sha }}
- name: comment PR
if: github.event_name == 'pull_request' && steps.find-bot-comment.outputs.comment-id == ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }} -R mongodb/mongodb-atlas-kubernetes -b "https://app.codecov.io/github/mongodb/mongodb-atlas-kubernetes/commit/${{ github.event.pull_request.head.sha }}"
int-tests:
needs: allowed
uses: ./.github/workflows/integration-test.yml
secrets: inherit
with:
forked: false

e2e-tests:
needs: allowed
uses: ./.github/workflows/test-e2e.yml
secrets: inherit
with:
forked: false

openshift-upgrade-test:
needs: allowed
uses: ./.github/workflows/openshift-upgrade-test.yaml
secrets: inherit
with:
forked: false
28 changes: 0 additions & 28 deletions .github/workflows/integration-test-forked.yml

This file was deleted.

17 changes: 6 additions & 11 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
name: Integration tests non-forked

on:
push:
branches:
- 'main'
paths-ignore:
- 'docs/**'
pull_request:
branches:
- '**'
paths-ignore:
- 'docs/**'
workflow_dispatch:
workflow_call:
inputs:
forked:
type: boolean
required: false
default: false

concurrency:
group: int-test-${{ github.head_ref || github.ref_name }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
name: Lint

on:
pull_request:
branches:
- '**'
paths-ignore:
- 'docs/**'
workflow_dispatch:
workflow_call:
inputs:
forked:
type: boolean
required: false
default: false

jobs:
lint:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/openshift-upgrade-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
default: false
type: boolean
required: false
workflow_dispatch:

concurrency:
group: test-openshift-operator-upgrade
Expand Down Expand Up @@ -79,6 +80,9 @@ jobs:
opm version
oc version
operator-sdk version
- name: Install Go dependencies
run: go install golang.org/x/tools/cmd/goimports@latest

- name: Login to registry
run: docker login -u="${{ secrets.OPENSHIFT_UPGRADE_BOT_USERNAME }}" -p="${{ secrets.OPENSHIFT_UPGRADE_BOT_PASSWORD }}" quay.io
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/paths-filter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Unit Tests

on:
workflow_call:
outputs:
production-code-changed:
description: "Was production code changed?"
value: ${{ jobs.paths-filter.outputs.production-code-changed }}

jobs:
paths-filter:
runs-on: ubuntu-latest
outputs:
production-code-changed: ${{ steps.filter.outputs.production-code-changed }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
production-code-changed:
- 'cmd/**/!(*_test.go)'
- 'pkg/**/!(*_test.go)'
# run only if 'production-code' files were changed
- name: production code changed
if: steps.filter.outputs.production-code-changed == 'true'
run: echo "Production code was changed"

# run only if not 'production-code' files were changed
- name: production code not changed
if: steps.filter.outputs.production-code-changed != 'true'
run: echo "Production code was not changed"
39 changes: 18 additions & 21 deletions .github/workflows/test-forked.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test Forked

on:
pull_request_target:
types: [labeled]
types: [labeled, opened, synchronize, reopened, ready_for_review, converted_to_draft]
paths-ignore:
- 'docs/**'

Expand All @@ -11,31 +11,28 @@ concurrency:
cancel-in-progress: true

jobs:
allowed-forked:
name: Allowed action
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }} || contains(github.event.pull_request.labels.*.name, 'safe-to-test')
steps:
- name: allowed message
run: echo "Allowed to run"

unit-tests-forked:
needs: allowed-forked
uses: ./.github/workflows/test-unit.yml
secrets: inherit
lint:
uses: ./.github/workflows/lint.yaml
with:
forked: true

e2e-tests-forked:
needs: allowed-forked
uses: ./.github/workflows/test-e2e.yml
secrets: inherit

unit-tests:
uses: ./.github/workflows/test-unit.yml
with:
forked: true

openshift-upgrade-test:
needs: allowed-forked
uses: ./.github/workflows/openshift-upgrade-test.yaml
paths-filter:
uses: ./.github/workflows/paths-filter.yml

cloud-tests-forked:
needs:
- lint
- unit-tests
- paths-filter
if: |
github.event.pull_request.draft == false &&
needs.paths-filter.outputs.production-code-changed == 'true'
uses: ./.github/workflows/cloud-tests-forked.yml
secrets: inherit
with:
forked: true
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Tests.
name: Unit Tests

on:
workflow_call:
Expand Down
62 changes: 18 additions & 44 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths-ignore:
- 'docs/**'
pull_request:
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]
branches:
- '**'
paths-ignore:
Expand All @@ -18,55 +19,28 @@ concurrency:
cancel-in-progress: true

jobs:
allowed:
name: Allowed
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
github.ref == 'refs/heads/main' ||
(github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
steps:
- name: allowed message
run: echo "Allowed to run"
- name: check Github action bot comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v2
id: find-bot-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: 'https://app.codecov.io/github/mongodb/mongodb-atlas-kubernetes/commit'
- name: edit comment if exists
if: github.event_name == 'pull_request' && steps.find-bot-comment.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v3
with:
edit-mode: replace
comment-id: ${{ steps.find-bot-comment.outputs.comment-id }}
body: https://app.codecov.io/github/mongodb/mongodb-atlas-kubernetes/commit/${{ github.event.pull_request.head.sha }}
- name: comment PR
if: github.event_name == 'pull_request' && steps.find-bot-comment.outputs.comment-id == ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }} -R mongodb/mongodb-atlas-kubernetes -b "https://app.codecov.io/github/mongodb/mongodb-atlas-kubernetes/commit/${{ github.event.pull_request.head.sha }}"
unit-tests:
needs: allowed
uses: ./.github/workflows/test-unit.yml
secrets: inherit
lint:
uses: ./.github/workflows/lint.yaml
with:
forked: false

e2e-tests:
needs: allowed
uses: ./.github/workflows/test-e2e.yml
secrets: inherit

unit-tests:
uses: ./.github/workflows/test-unit.yml
with:
forked: false

paths-filter:
uses: ./.github/workflows/paths-filter.yml

openshift-upgrade-test:
needs: allowed
uses: ./.github/workflows/openshift-upgrade-test.yaml
cloud-tests:
needs:
- lint
- unit-tests
- paths-filter
if: |
github.event.pull_request.draft == false &&
needs.paths-filter.outputs.production-code-changed == 'true'
uses: ./.github/workflows/cloud-tests.yml
secrets: inherit
with:
forked: false
3 changes: 2 additions & 1 deletion scripts/openshift-upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ set -eou pipefail
# * yq
#
# Test conf
TEST_NAMESPACE=${TEST_NAMESPACE:-"atlas-upgrade-test"}
RANDOM_NAMESPACE_SUFFIX=${RANDOM}
TEST_NAMESPACE=${TEST_NAMESPACE:-"atlas-upgrade-test-${RANDOM_NAMESPACE_SUFFIX}"}
LATEST_RELEASE_VERSION="${LATEST_RELEASE_VERSION:-1.0.0}"
LATEST_RELEASE_REGISTRY=${LATEST_RELEASE_REGISTRY:-"quay.io/mongodb"}
REGISTRY=${REGISTRY:-"quay.io/mongodb"}
Expand Down

0 comments on commit c408731

Please sign in to comment.