CI: run_tests3.sh requires env parameter PYTHON_BINARY (#82) #156
This file contains hidden or 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
| # This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
| name: CI | |
| on: | |
| push: | |
| branches: [ "master" ] | |
| paths-ignore: | |
| - "*.md" | |
| pull_request: | |
| branches: [ "master" ] | |
| paths-ignore: | |
| - "*.md" | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install flake8 flake8-pyproject ruff | |
| - name: Lint with flake8 | |
| run: | | |
| flake8 . | |
| - name: Lint with ruff | |
| run: | | |
| ruff check . | |
| build-check: | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Set up Python 3.12 | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| cache: 'pip' | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install build twine | |
| - name: Build package | |
| run: | | |
| python -m build | |
| - name: Check package metadata | |
| run: | | |
| twine check dist/* | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: build-check | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: "alpine" | |
| python: "3.7" | |
| - platform: "alpine" | |
| python: "3.8" | |
| - platform: "alpine" | |
| python: "3.9" | |
| - platform: "alpine" | |
| python: "3.10" | |
| - platform: "alpine" | |
| python: "3.11" | |
| - platform: "alpine" | |
| python: "3.12" | |
| - platform: "alpine" | |
| python: "3.13" | |
| - platform: "alpine" | |
| python: "3.14" | |
| - platform: "ubuntu_24_04" | |
| python: "3" | |
| - platform: "altlinux_10" | |
| python: "3" | |
| - platform: "altlinux_11" | |
| python: "3" | |
| - platform: "astralinux_1_7" | |
| python: "3" | |
| env: | |
| BASE_SIGN: "${{ matrix.platform }}-py${{ matrix.python }}" | |
| steps: | |
| - name: Prepare variables | |
| run: | | |
| echo "RUN_CFG__NOW=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV | |
| echo "RUN_CFG__LOGS_DIR=logs-${{ env.BASE_SIGN }}" >> $GITHUB_ENV | |
| echo "RUN_CFG__DOCKER_IMAGE_NAME=tests-${{ env.BASE_SIGN }}" >> $GITHUB_ENV | |
| echo "RUN_CFG__NETWORK_NAME=network-${{ env.BASE_SIGN }}" >> $GITHUB_ENV | |
| echo "RUN_CFG__MACHINE1_NAME=machine1-${{ env.BASE_SIGN }}" >> $GITHUB_ENV | |
| echo "RUN_CFG__MACHINE2_NAME=machine2-${{ env.BASE_SIGN }}" >> $GITHUB_ENV | |
| echo "RUN_CFG__SSH_KEY_NAME=id_ed25519-${{ env.BASE_SIGN }}" >> $GITHUB_ENV | |
| echo "---------- [$GITHUB_ENV]" | |
| cat $GITHUB_ENV | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Prepare logs folder on the host | |
| run: mkdir -p "${{ env.RUN_CFG__LOGS_DIR }}" | |
| - name: Adjust logs folder permission | |
| run: chmod -R 777 "${{ env.RUN_CFG__LOGS_DIR }}" | |
| - name: Build local image ${{ matrix.alpine }} | |
| run: docker build --build-arg PYTHON_VERSION="${{ matrix.python }}" -t "${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" -f Dockerfile--${{ matrix.platform }}.tmpl . | |
| - name: Generate temporary SSH Key pair for CI | |
| run: | | |
| # Generate a key without a password directly on the GitHub Actions host | |
| ssh-keygen -q -t ed25519 -N "" -f ${{ github.workspace }}/${{ env.RUN_CFG__SSH_KEY_NAME }} | |
| - name: Setup network | |
| run: | | |
| docker network create ${{ env.RUN_CFG__NETWORK_NAME }} | |
| - name: Run machine2 (for remote operations) | |
| run: | | |
| # | |
| # "- sleep infinity" is a right command. Docker ignores "-" and runs "sleep infinity". | |
| # | |
| docker run -d -t \ | |
| --network ${{ env.RUN_CFG__NETWORK_NAME }} \ | |
| --name ${{ env.RUN_CFG__MACHINE2_NAME }} \ | |
| "${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" \ | |
| sleep infinity | |
| echo "Waiting for container ${{ env.RUN_CFG__MACHINE2_NAME }} to start ..." | |
| # Set the timeout using the attempt counter | |
| MAX_ATTEMPTS=50 | |
| ATTEMPT=0 | |
| until [ "$(docker container inspect --format '{{.State.Running}}' "${{ env.RUN_CFG__MACHINE2_NAME }}")" = "true" ]; do | |
| ATTEMPT=$((ATTEMPT + 1)) | |
| if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then | |
| echo "Error: Container did not start within the allotted time (timeout)!" | |
| exit 1 | |
| fi | |
| sleep 0.2 | |
| done | |
| echo "Container successfully launched in $((ATTEMPT * 2 / 10)) second(s)!" | |
| # | |
| # Setup authorized_keys | |
| # | |
| cat ${{ github.workspace }}/${{ env.RUN_CFG__SSH_KEY_NAME }}.pub | \ | |
| docker exec -i -u test ${{ env.RUN_CFG__MACHINE2_NAME }} sh -c " \ | |
| cat >> /home/test/.ssh/authorized_keys && \ | |
| chmod 600 /home/test/.ssh/authorized_keys \ | |
| " | |
| # | |
| # Log status | |
| # | |
| docker exec -u root ${{ env.RUN_CFG__MACHINE2_NAME }} sh -c " | |
| echo '--- INSIDE CONTAINER OS ---' && \ | |
| cat /etc/os-release && \ | |
| echo '--- INSIDE CONTAINER .SSH ---' && \ | |
| ls -la /home/test/.ssh/ \ | |
| " | |
| - name: Run machine1 (main test container) | |
| run: | | |
| # Launch the main container, passing the private key to the .ssh folder of the test user. | |
| # Pass environment variables so Python tests know where to start. | |
| # Added the --rm flag so that the container is automatically deleted after the tests are completed | |
| docker run --rm -t \ | |
| --network ${{ env.RUN_CFG__NETWORK_NAME }} \ | |
| --name ${{ env.RUN_CFG__MACHINE1_NAME }} \ | |
| -v ${{ github.workspace }}/${{ env.RUN_CFG__LOGS_DIR }}:/home/test/testgres/logs \ | |
| -v ${{ github.workspace }}/${{ env.RUN_CFG__SSH_KEY_NAME }}:/home/test/testgres/id_ed25519_test:ro \ | |
| -e TEST_CFG__REMOTE_HOST="${{ env.RUN_CFG__MACHINE2_NAME }}" \ | |
| -e TEST_CFG__REMOTE_PORT="22" \ | |
| -e TEST_CFG__REMOTE_USERNAME="test" \ | |
| -e TEST_CFG__REMOTE_SSH_KEY="/home/test/testgres/id_ed25519_test" \ | |
| "${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" | |
| - name: Upload Logs | |
| uses: actions/upload-artifact@v7 | |
| if: always() # IT IS IMPORTANT! | |
| with: | |
| name: testgres.os_ops--test_logs--${{ env.RUN_CFG__NOW }}-${{ env.BASE_SIGN }}-id${{ github.run_id }} | |
| path: "${{ env.RUN_CFG__LOGS_DIR }}/" | |
| - name: Cleanup Docker resources | |
| if: always() # Ensures that the step is executed regardless of the result of the task | |
| run: | | |
| echo "=== Garbage Collection ===" | |
| # Force kill the background machine (the -f flag will stop it if it is running) | |
| docker rm -f "${{ env.RUN_CFG__MACHINE2_NAME }}" || true | |
| # Delete the network (it will be deleted successfully, since all containers in it have already been destroyed) | |
| docker network rm "${{ env.RUN_CFG__NETWORK_NAME }}" || true |