Skip to content

package-test-runner

package-test-runner #2

---
name: package-test-pipeline
on:
workflow_dispatch:
inputs:
package_testing_branch:
description: "Target branch for package-testing repository"
type: string
default: "master"
required: true
pmm_server_image:
description: "pmm-server docker image(auto detected if empty)"
required: false
type: string
default: "perconalab/pmm-server:dev-latest"
pmm_client_tarball:
description: "PMM Client tarball link or FB-code"
type: string
# package_repo: experimental | testing | main | pmm2-client-main
expected_version:
description: "expected version"
required: false
type: string
# TODO: investigate switch to actual repo name
repository:
description: "Select Repo to install PMM Client:"
required: true
default: "dev-latest"
type: choice
options:
- release
- release candidate
- dev-latest
metrics_mode:
description: "Select the Metrics Mode for PMM Client:"
required: true
default: "auto"
type: choice
options:
- auto
- push
- pull
playbook:
description: "Playbook file to run(without extension)"
type: string
default: "pmm2-client_integration"
required: true
test_name:
description: "Optional pretty test name"
type: string
required: false
os:
description: "Select OS to run test in:"
required: true
default: "jammy-x64"
type: choice
options:
- bionic-x64
- bullseye-x64
- buster-x64
- focal-x64
- jammy-x64
- centos-7-x64
- ol-8-x64
- ol-9-x64
workflow_call:
inputs:
package_testing_branch:
type: string
default: "master"
required: true
pmm_server_image:
required: false
type: string
pmm_client_tarball:
required: false
type: string
expected_version:
required: false
type: string
repository:
required: true
default: "dev-latest"
type: string
metrics_mode:
required: true
default: "auto"
type: string
playbook:
type: string
default: "pmm2-client_integration"
required: true
test_name:
type: string
required: false
os:
description: "Select OS to run test in:"
required: true
default: "jammy-x64"
type: string
jobs:
test:
name: ${{ inputs.test_name || inputs.playbook}}
runs-on: ubuntu-latest
timeout-minutes: 90
env:
SHA: ${{ inputs.sha || 'null' }}
PACKAGE_TESTING_BRANCH: ${{ inputs.package_testing_branch || 'master' }}
PMM_SERVER_IMAGE: ${{ inputs.pmm_server_image }}
TARBALL: ${{ inputs.pmm_server_image || 'null' }}
EXPECTED_VERSION: ${{ inputs.expected_version }}
REPO: ${{ inputs.repository || 'dev-latest' }}
METRICS_MODE: ${{ inputs.metrics_mode || 'auto' }}
PLAYBOOK: ${{ inputs.playbook }}
steps:
- name: "Create status check"
if: ${{ env.SHA != 'null' }}
uses: percona/gh-action-github-status-action@v1
continue-on-error: true
with:
authToken: ${{ secrets.GITHUB_TOKEN }}
context: "${{ inputs.test_name }} Package test"
description: "Test execution ${{ job.status }}"
state: "pending"
repository: ${{ github.repository }}
target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
sha: ${{ env.SHA }}
- name: 'Checkout package-testing: "${{ inputs.package_testing_branch }}"'
uses: actions/checkout@v3
with:
ref: ${{ inputs.package_testing_branch }}
- name: 'Convert choices'
run: |
### pmm-server docker image ###
if [[ -z "${{ env.PMM_SERVER_IMAGE }}" ]]; then
if [[ "${{ inputs.repository }}" = "dev-latest" ]]; then
echo "PMM_SERVER_IMAGE=perconalab/pmm-server:dev-latest" >> $GITHUB_ENV
fi
if [[ "${{ inputs.repository }}" =~ "candidate" ]]; then
rc_latest=$(wget -q "https://registry.hub.docker.com/v2/repositories/perconalab/pmm-client/tags?page_size=25&name=rc" -O - | jq -r .results[].name | grep 2.*.*-rc$ | sort -V | tail -n1)
echo "PMM_SERVER_IMAGE=perconalab/pmm-server:$rc_latest" >> $GITHUB_ENV
fi
if [[ "${{ inputs.repository }}" = "release" ]]; then
r_latest=$(wget -q https://registry.hub.docker.com/v2/repositories/percona/pmm-client/tags -O - | jq -r .results[].name | grep -v latest | sort -V | tail -n1)
echo "PMM_SERVER_IMAGE=percona/pmm-server:$r_latest" >> $GITHUB_ENV
fi
fi
echo "${{ env.PMM_SERVER_IMAGE }}"
### pmm2-client repository ###
if [[ "${{ inputs.repository }}" = "dev-latest" ]]; then
echo "REPO=experimental" >> $GITHUB_ENV
fi
if [[ "${{ inputs.repository }}" =~ "candidate" ]]; then
echo "REPO=testing" >> $GITHUB_ENV
fi
if [[ "${{ inputs.repository }}" = "release" ]]; then
echo "REPO=release" >> $GITHUB_ENV
fi
echo "${{ env.REPO }}"
### vagrant vm ###
if [[ "${{ inputs.os }}" =~ "buster" ]]; then
echo "VM_BOX=generic/debian10" >> $GITHUB_ENV
fi
if [[ "${{ inputs.os }}" =~ "bullseye" ]]; then
echo "VM_BOX=generic/debian11" >> $GITHUB_ENV
fi
if [[ "${{ inputs.os }}" =~ "bionic" ]]; then
echo "VM_BOX=generic/ubuntu1804" >> $GITHUB_ENV
fi
if [[ "${{ inputs.os }}" =~ "focal" ]]; then
echo "VM_BOX=ubuntu/focal64" >> $GITHUB_ENV
fi
if [[ "${{ inputs.os }}" =~ "jammy" ]]; then
echo "VM_BOX=generic/ubuntu2204" >> $GITHUB_ENV
fi
if [[ "${{ inputs.os }}" =~ "centos-7" ]]; then
echo "VM_BOX=generic/centos7" >> $GITHUB_ENV
fi
if [[ "${{ inputs.os }}" =~ "ol-8" ]]; then
echo "VM_BOX=generic/oracle8" >> $GITHUB_ENV
fi
if [[ "${{ inputs.os }}" =~ "ol-9" ]]; then
echo "VM_BOX=generic/oracle9" >> $GITHUB_ENV
fi
echo "${{ env.VM_BOX }}"
### test name -> playbook map ###
# basic -> pmm2-client.yml
# basic upgrade -> pmm2-client_upgrade.yml
# basic tarball -> pmm2-client_custom_path.yml
# config password -> pmm2-client_integration_auth_config.yml
# register password -> pmm2-client_integration_auth_register.yml
# tarball setup password -> pmm2-client_integration_auth_setup.yml
# tarball path -> pmm2-client_integration_custom_path.yml
# tarball port -> pmm2-client_integration_custom_port.yml
# integration upgrade port -> pmm2-client_integration_upgrade_custom_port.yml
######### Matrix tests
# integration -> pmm2-client_integration.yml
# integration upgrade -> pmm2-client_integration_upgrade.yml
# tarball upgrade path -> pmm2-client_integration_upgrade_custom_path.yml
- name: 'Setup "${{ env.PMM_SERVER_IMAGE }}"'
run: |
docker create -v /srv --name pmm-server-data ${{ env.PMM_SERVER_IMAGE }}
docker run -d -p 80:80 -p 443:443 -p 9000:9000 \
--volumes-from pmm-server-data --name pmm-server --restart always ${{ env.PMM_SERVER_IMAGE }}
- name: "Setup tools"
run: |
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates ansible virtualbox vagrant
if [[ "${{ inputs.os }}" =~ "buster" ]]; then
vagrant plugin install vagrant-vbguest
fi
- name: "Wait for PMM Server to be healthy"
run: |
timeout 240 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://127.0.0.1/v1/readyz)" != "200" ]]; do sleep 2; done' || false
- name: "Create vagrantfile"
working-directory: ./
run: |
pwd
# mkdir -p ~/test-vm/
# cat > ~/test-vm/Vagrantfile <<EOF
cat > Vagrantfile <<EOF
Vagrant.require_version ">= 1.7.0"
Vagrant.configure(2) do |config|
config.vm.box = "${{ env.VM_BOX }}"
${{ contains(env.VM_BOX, 'debian10') && 'config.vbguest.auto_update = true' }}
config.ssh.insert_key = false
config.vm.define :CLIENT_TEST do |t|
end
config.vm.synced_folder "/home/runner/work/package-testing/package-testing/", "/pmm/package-testing/"
config.vm.provision "shell", privileged: true, inline: <<-SHELL
## Set environment variables...
export PMM_SERVER_IP=10.0.2.2:443
export METRICS_MODE=${{ env.METRICS_MODE }}
export PMM_VERSION="${{ env.EXPECTED_VERSION }}"
export install_repo=${{ env.REPO }}
export tarball_link=${{ env.TARBALL }}
if [[ "${{ env.VM_BOX }}" =~ "centos7" ]]; then
sudo yum install -y epel-release
sudo yum -y update
sudo yum install -y ansible git wget
fi
if [[ "${{ env.VM_BOX }}" =~ "oracle" ]]; then
sudo yum install -y epel-release
sudo yum -y update
sudo yum install -y ansible-core git wget
fi
if [[ "${{ env.VM_BOX }}" =~ "debian" ]]; then
sudo apt-get install -y dirmngr gnupg2
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list > /dev/null
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
sudo apt update -y
sudo apt-get install -y ansible git wget
fi
if [[ "${{ env.VM_BOX }}" =~ "ubuntu" ]]; then
sudo apt update -y
sudo apt install -y software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt-get install -y ansible git wget
fi
cd /pmm/package-testing/playbooks
ansible-playbook -vv --connection=local --inventory 127.0.0.1, --limit 127.0.0.1 ${{ env.PLAYBOOK }}.yml
SHELL
end
EOF
- name: "Run ${{ inputs.test_name }} test on ${{ inputs.os }}"
working-directory: ./
run: vagrant up
- name: "Create status check"
uses: percona/gh-action-github-status-action@v1
if: ${{ env.SHA != 'null' && always() }}
continue-on-error: true
with:
authToken: ${{ secrets.GITHUB_TOKEN }}
context: "${{ inputs.test_name }} Package test"
description: "Test execution ${{ job.status }}"
state: ${{ job.status }}
repository: ${{ github.repository }}
target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
sha: ${{ env.SHA }}