[chore] Fix packaging and salt tests #1955
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: salt-test | |
# Only run tests if there are relevant changes | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/salt-test.yml' | |
- 'deployments/salt/**' | |
- 'packaging/tests/deployments/salt/**' | |
- 'packaging/tests/helpers/**' | |
- 'packaging/tests/requirements.txt' | |
- '!**.md' | |
pull_request: | |
paths: | |
- '.github/workflows/salt-test.yml' | |
- 'deployments/salt/**' | |
- 'packaging/tests/deployments/salt/**' | |
- 'packaging/tests/helpers/**' | |
- 'packaging/tests/requirements.txt' | |
- '!**.md' | |
concurrency: | |
group: salt-test-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
env: | |
PYTHON_VERSION: '3.13' | |
REQUIREMENTS_PATH: "packaging/tests/requirements.txt" | |
jobs: | |
salt-lint-test: | |
name: salt-lint-test | |
# Use 20.04.5 until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/16450 is resolved | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
- name: Lint | |
run: | | |
make -C deployments/salt lint | |
salt-test-matrix: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Get matrix | |
id: get-matrix | |
run: | | |
# create test matrix for distro | |
deb_distro=$(yq e -r '.deb | keys | .[]' packaging/tests/deployments/salt/images/distro_docker_opts.yaml) | |
rpm_distro=$(yq e -r '.deb | keys | .[]' packaging/tests/deployments/salt/images/distro_docker_opts.yaml) | |
dockerfiles=$(echo -e "$deb_distro\n$rpm_distro" | sort -u) | |
if [ -z "$dockerfiles" ]; then | |
echo "Failed to get distros from packaging/tests/deployments/salt/images!" >&2 | |
exit 1 | |
fi | |
distro=$(for d in $dockerfiles; do echo -n "\"$d\","; done) | |
config="\"default\", \"custom\"" | |
matrix="{\"DISTRO\": [${distro%,}], \"CONFIG\": [${config}]}" | |
echo "$matrix" | jq | |
echo "matrix=${matrix}" >> $GITHUB_OUTPUT | |
outputs: | |
matrix: ${{ steps.get-matrix.outputs.matrix }} | |
salt-test: | |
name: salt-test | |
# Use 20.04.5 until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/16450 is resolved | |
runs-on: ${{ fromJSON('["ubuntu-20.04", "ubuntu-22.04"]')[matrix.DISTRO == 'amazonlinux-2023'] }} | |
timeout-minutes: 60 | |
needs: [salt-lint-test, salt-test-matrix] | |
strategy: | |
matrix: ${{ fromJSON(needs.salt-test-matrix.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
- name: Setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: pip | |
cache-dependency-path: ${{ env.REQUIREMENTS_PATH }} | |
- name: Install pytest | |
run: pip install -r "${{ env.REQUIREMENTS_PATH }}" | |
- name: Test salt deployment | |
id: pytest | |
continue-on-error: true | |
run: | | |
distro="${{ matrix.DISTRO }}" | |
if [[ "$distro" = "amazonlinux-2" ]]; then | |
# workaround for pytest substring matching | |
distro="amazonlinux-2 and not amazonlinux-2023" | |
fi | |
python3 -u -m pytest -s --verbose -k "$distro and ${{ matrix.CONFIG }}" \ | |
packaging/tests/deployments/salt/salt_test.py | |
# qemu, networking, running systemd in containers, etc., can be flaky | |
- name: Re-run failed tests | |
if: ${{ steps.pytest.outcome == 'failure' }} | |
run: | | |
distro="${{ matrix.DISTRO }}" | |
if [[ "$distro" = "amazonlinux-2" ]]; then | |
# workaround for pytest substring matching | |
distro="amazonlinux-2 and not amazonlinux-2023" | |
fi | |
python3 -u -m pytest -s --verbose -k "$distro and ${{ matrix.CONFIG }}" \ | |
--last-failed \ | |
packaging/tests/deployments/salt/salt_test.py |