|
| 1 | +name: 'API' |
| 2 | + |
| 3 | +on: |
| 4 | + # NOTE: no action on `push` and `pull_request` since the API tests need to be run |
| 5 | + # against a container that has the latest changes from your code. Therefore, the |
| 6 | + # PMM_SERVER_IMAGE should either be the one from your feature build or the local |
| 7 | + # devcontainer. One more scenario is when we want to run the API tests on dev-latest |
| 8 | + # to see if the tests are in a good shape. |
| 9 | + # That said, this workflow is mostly a convenience if you prefer Github to Jenkins. |
| 10 | + # https://github.com/Percona-Lab/jenkins-pipelines/blob/master/pmm/pmm2-api-tests.groovy |
| 11 | + |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + MYSQL_IMAGE: |
| 15 | + description: "MYSQL image version" |
| 16 | + default: "percona:5.7" |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + POSTGRESQL_IMAGE: |
| 20 | + description: "POSTGRESQL image version" |
| 21 | + default: "postgres:12" |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + MONGODB_IMAGE: |
| 25 | + description: "MONGODB image version" |
| 26 | + default: "percona/percona-server-mongodb:4.4" |
| 27 | + required: true |
| 28 | + type: string |
| 29 | + PMM_SERVER_IMAGE: |
| 30 | + description: "PMM Server image version" |
| 31 | + default: "perconalab/pmm-server:dev-latest" |
| 32 | + required: true |
| 33 | + type: string |
| 34 | + |
| 35 | + workflow_call: |
| 36 | + inputs: |
| 37 | + BRANCH: |
| 38 | + description: "The branch to source API tests from" |
| 39 | + default: "main" |
| 40 | + required: true |
| 41 | + type: string |
| 42 | + MYSQL_IMAGE: |
| 43 | + description: "MYSQL image version" |
| 44 | + default: "percona:5.7" |
| 45 | + required: true |
| 46 | + type: string |
| 47 | + POSTGRESQL_IMAGE: |
| 48 | + description: "POSTGRESQL image version" |
| 49 | + default: "postgres:12" |
| 50 | + required: true |
| 51 | + type: string |
| 52 | + MONGODB_IMAGE: |
| 53 | + description: "MONGODB image version" |
| 54 | + default: "percona/percona-server-mongodb:4.4" |
| 55 | + required: true |
| 56 | + type: string |
| 57 | + PMM_SERVER_IMAGE: |
| 58 | + description: "PMM Server image version" |
| 59 | + default: "perconalab/pmm-server:dev-latest" |
| 60 | + required: true |
| 61 | + type: string |
| 62 | + |
| 63 | +jobs: |
| 64 | + test: |
| 65 | + name: Tests |
| 66 | + runs-on: ubuntu-22.04 |
| 67 | + env: |
| 68 | + PMM_URL: http://admin:admin@127.0.0.1 |
| 69 | + BRANCH: ${{ github.event.inputs.BRANCH || 'main' }} |
| 70 | + MYSQL_IMAGE: ${{ github.event.inputs.MYSQL_IMAGE || 'percona:5.7' }} |
| 71 | + POSTGRESQL_IMAGE: ${{ github.event.inputs.POSTGRESQL_IMAGE || 'postgres:12' }} |
| 72 | + MONGODB_IMAGE: ${{ github.event.inputs.MONGODB_IMAGE || 'percona/percona-server-mongodb:4.4' }} |
| 73 | + PMM_SERVER_IMAGE: ${{ github.event.inputs.PMM_SERVER_IMAGE || 'perconalab/pmm-server:dev-latest' }} |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Check out code |
| 77 | + uses: actions/checkout@v4 |
| 78 | + with: |
| 79 | + ref: ${{ env.BRANCH }} |
| 80 | + |
| 81 | + - name: Login to docker.io registry |
| 82 | + uses: docker/login-action@v3 |
| 83 | + with: |
| 84 | + registry: docker.io |
| 85 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 86 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 87 | + |
| 88 | + - name: Run PMM Server |
| 89 | + run: | |
| 90 | + cat <<-EOF > compose.pmm-server-test.yml |
| 91 | + services: |
| 92 | + pmm-server: |
| 93 | + image: ${{ env.PMM_SERVER_IMAGE }} |
| 94 | + container_name: pmm-agent_pmm-server |
| 95 | + environment: |
| 96 | + - PMM_DEBUG=1 |
| 97 | + - PERCONA_TEST_CHECKS_INTERVAL=10s |
| 98 | + - PERCONA_TEST_PLATFORM_ADDRESS=https://check-dev.percona.com |
| 99 | + - PERCONA_TEST_PLATFORM_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX |
| 100 | + ports: |
| 101 | + - 80:80 |
| 102 | + - 443:443 |
| 103 | + volumes: |
| 104 | + - ./managed/testdata/checks:/srv/checks |
| 105 | + EOF |
| 106 | +
|
| 107 | + # Run it and wait until it's healthy |
| 108 | + docker compose -f compose.pmm-server-test.yml up -d --wait --wait-timeout=100 |
| 109 | +
|
| 110 | + - name: Build the test image |
| 111 | + shell: bash |
| 112 | + run: | |
| 113 | + docker build -t percona/pmm-api-tests . |
| 114 | +
|
| 115 | + - name: Run DB containers |
| 116 | + shell: bash |
| 117 | + run: | |
| 118 | + pushd api-tests |
| 119 | + docker compose up test_db # no daemon mode |
| 120 | + # TODO: review the provisions below (copied from the Jenkins pipeline) |
| 121 | + # MYSQL_IMAGE=${{env.MYSQL_IMAGE}} docker compose up -d mysql |
| 122 | + # MONGO_IMAGE=${{env.MONGODB_IMAGE}} docker compose up -d mongo |
| 123 | + # POSTGRES_IMAGE=${{env.POSTGRESQL_IMAGE}} docker compose up -d postgres |
| 124 | + # docker compose up -d sysbench |
| 125 | + popd |
| 126 | +
|
| 127 | + - name: Check connectivity to PMM Server |
| 128 | + shell: bash |
| 129 | + run: curl -f ${{env.PMM_URL}}/ping |
| 130 | + |
| 131 | + - name: Run API tests |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | + docker run -e PMM_SERVER_URL=${{env.PMM_URL}} \ |
| 135 | + -e PMM_RUN_UPDATE_TEST=0 \ |
| 136 | + -e PMM_RUN_STT_TESTS=0 \ |
| 137 | + --name pmm-api-tests \ |
| 138 | + --network host \ |
| 139 | + percona/pmm-api-tests |
| 140 | +
|
| 141 | + - name: Get PMM logs |
| 142 | + if: ${{ failure() }} |
| 143 | + run: curl --insecure ${{env.PMM_URL}}/logs.zip --output ${{ github.workspace }}/logs.zip || true |
| 144 | + |
| 145 | + - name: Upload the logs on failure |
| 146 | + if: ${{ failure() }} |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: "logs.zip" |
| 150 | + path: ${{ github.workspace }}/logs.zip |
| 151 | + |
| 152 | + - name: Run debug commands on failure |
| 153 | + if: ${{ failure() }} |
| 154 | + run: | |
| 155 | + echo "----- ENVIRONMENT VARIABLES -----" |
| 156 | + env | sort |
0 commit comments