From 679d652fbda0b31ecdb144203c4c680ee50317da Mon Sep 17 00:00:00 2001 From: Youjung Kim <126618609+ykim-1@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:11:16 -0700 Subject: [PATCH] CI: replace test execution handler with conditional (#504) * replace test execution handler and separate test report uploading * gha test 1 * gha test 2 * Clean up syntax format * gh test for removing build essentials step --- .github/workflows/integration-tests.yml | 83 ++++++++++++++++--------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 40d0c51e..aa37cf5d 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -16,58 +16,91 @@ jobs: run: working-directory: .ansible/collections/ansible_collections/linode/cloud steps: - - name: checkout repo + - name: Checkout repo uses: actions/checkout@v3 with: path: .ansible/collections/ansible_collections/linode/cloud fetch-depth: 0 submodules: 'recursive' - - name: update packages + - name: Update packages run: sudo apt-get update -y - - name: install make - run: sudo apt-get install -y build-essential - - - name: setup python 3 - uses: actions/setup-python@v4 + - name: Setup Python 3 + uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.x' - - name: install dependencies + - name: Install dependencies run: make deps - - name: install ansible dependencies + - name: Install ansible dependencies run: ansible-galaxy collection install amazon.aws:==6.0.1 - - name: install collection + - name: Install Collection run: make install - - name: replace existing keys + - name: Replace Existing Keys run: rm -rf ~/.ansible/test && mkdir -p ~/.ansible/test && ssh-keygen -m PEM -q -t rsa -N '' -f ~/.ansible/test/id_rsa - - name: run tests + - name: Run Integration Tests run: | - if ! make testall > test_output.txt; then - echo "EXIT_STATUS=1" >> $GITHUB_ENV - fi - cat test_output.txt + make testall env: LINODE_API_TOKEN: ${{ secrets.DX_LINODE_TOKEN }} ANSIBLE_CALLBACKS_ENABLED: "junit" - - name: Set release version env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Upload Test Report as Artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: xml-test-reports + if-no-files-found: ignore + path: '.ansible/collections/ansible_collections/linode/cloud/tests/output/junit' + retention-days: 1 + + + process-upload-report: + runs-on: ubuntu-latest + needs: [run-tests] + if: always() # Run even if previous job fails + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: 'recursive' + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install Python dependencies + run: pip3 install requests wheel boto3 + + # Create directory if it doesn't exist + - name: Create output directory + run: mkdir -p tests/output/junit + + - name: Download test report + uses: actions/download-artifact@v4 + with: + name: xml-test-reports # Specify the artifact name from the 'run-tests' job + path: tests/output/junit + continue-on-error: true # Continue even if artifact download fails - name: Merge all test xmls in output directory run: | + ls -R tests/output/junit python tod_scripts/merge_ansible_results.py - name: Add additional information to XML report run: | filename=$(ls | grep -E '^[0-9]{12}_ansible_merged\.xml$') python tod_scripts/add_to_xml_test_report.py \ - --branch_name "${{ env.RELEASE_VERSION }}" \ + --branch_name "${GITHUB_REF#refs/*/}" \ --gha_run_id "$GITHUB_RUN_ID" \ --gha_run_number "$GITHUB_RUN_NUMBER" \ --xmlfile "${filename}" @@ -79,13 +112,3 @@ jobs: env: LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }} LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }} - - - name: Test Execution Status Handler - run: | - if [[ "$EXIT_STATUS" != 0 ]]; then - echo "Test execution contains failure(s), check Run Integration tests step above" - exit $EXIT_STATUS - else - echo "Tests passed!" - fi -