From 37ed0730d202ce257e9f18be3fec3bd7aa8d1d55 Mon Sep 17 00:00:00 2001 From: jdre Date: Mon, 22 Jul 2024 12:28:54 +0200 Subject: [PATCH] feat(ci): tests against shell workflow debug n/a --- .../test-plugins-against-cockpit.yml | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/.github/workflows/test-plugins-against-cockpit.yml b/.github/workflows/test-plugins-against-cockpit.yml index 569aed46..c272994d 100644 --- a/.github/workflows/test-plugins-against-cockpit.yml +++ b/.github/workflows/test-plugins-against-cockpit.yml @@ -2,7 +2,7 @@ name: Test plugins against Cockpit on: pull_request: - schedule: + pull_request: - cron: '15 4 * * 1-5' permissions: @@ -16,22 +16,68 @@ jobs: timeout-minutes: 30 runs-on: ubuntu-22.04 outputs: - shell_versions: ${{ steps.collect-shell-versions.outputs.shell_versions }} + shell_versions: ${{ steps.filter-shell-versions.outputs.filtered_shell_versions }} + plugins_version: ${{ steps.extract-plugins-version.outputs.plugins_version }} steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Collect Shell Versions id: collect-shell-versions uses: SoftwareAG/plugins-e2e-setup/collect-shell-versions@main - - name: Verify shell versions output - run: echo "Collected shell versions ${{ steps.collect-shell-versions.outputs.shell_versions }}" + - name: Extract Plugins Version + id: extract-plugins-version + run: | + plugins_version=$(jq -r '.version' package.json) + echo "plugins_version=${plugins_version}" >> $GITHUB_ENV + echo "::set-output name=plugins_version::${plugins_version}" + + - name: Retrieve cached JSON files + if: ${{ github.event_name == 'pull_request' }} + id: retrieve-cache + uses: actions/cache@v4 + with: + path: ./cache-files + key: test-plugins-against-shell-e2e-results + restore-keys: | + test-plugins-against-shell-e2e-results + + - name: Filter shell versions + id: filter-shell-versions + if: ${{ github.event_name == 'pull_request' }} + run: | + mkdir -p ./cache-files + versions=$(echo '${{ steps.collect-shell-versions.outputs.shell_versions }}' | jq -c '.[]') + filtered_versions=() + for version_data in $versions; do + tag=$(echo $version_data | jq -r '.tag') + version=$(echo $version_data | jq -r '.version') + file="./cache-files/${tag}-${{ env.plugins_version }}.json" + if [ -f "$file" ]; then + alreadyTestedShellVersion=$(jq -r '.shellVersion' $file) + alreadyTestedPluginsVersion=$(jq -r '.pluginsVersion' $file) + if [[ "$alreadyTestedShellVersion" == "$version" && "$alreadyTestedPluginsVersion" == "${{ env.plugins_version }}" ]]; then + continue + fi + fi + filtered_versions+=("$version_data") + done + filtered_versions_json=$(printf '%s\n' "${filtered_versions[@]}" | jq -s '.') + echo "filtered_shell_versions=$filtered_versions_json" >> $GITHUB_ENV + echo "::set-output name=filtered_shell_versions::$filtered_versions_json" + + - name: Verify filtered shell versions output + run: echo "Filtered shell versions ${{ steps.filter-shell-versions.outputs.filtered_shell_versions }}" build-plugins: needs: collect-shell-versions + if: ${{ needs.collect-shell-versions.outputs.shell_versions != '[]' }} timeout-minutes: 30 runs-on: ubuntu-22.04 - outputs: - plugins_version: ${{ steps.extract-plugins-version.outputs.plugins_version }} steps: - name: Checkout @@ -45,13 +91,6 @@ jobs: node-version: '20' cache: 'npm' - - name: Extract Plugins Version - id: extract-plugins-version - run: | - plugins_version=$(jq -r '.version' package.json) - echo "plugins_version=${plugins_version}" >> $GITHUB_ENV - echo "::set-output name=plugins_version::${plugins_version}" - - name: Install dependencies run: npm ci @@ -69,6 +108,7 @@ jobs: run-tests-against-shell: needs: [collect-shell-versions, build-plugins] + if: ${{ needs.collect-shell-versions.outputs.shell_versions != '[]' }} runs-on: ubuntu-22.04 strategy: fail-fast: false @@ -78,7 +118,7 @@ jobs: JSON: ${{ toJson(matrix.version_data) }} VERSION: ${{ matrix.version_data.version }} TAG: ${{ matrix.version_data.tag }} - PLUGINS_VERSION: ${{ needs.build-plugins.outputs.plugins_version }} + PLUGINS_VERSION: ${{ needs.collect-shell-versions.outputs.plugins_version }} steps: - name: Checkout @@ -86,58 +126,22 @@ jobs: with: fetch-depth: 0 - - name: Retrieve cached JSON files - if: ${{ github.event_name == 'schedule' }} - id: retrieve-cache - uses: actions/cache@v4 - with: - path: ./cache-files - key: cache-json-files-${{ runner.os }}-${{ env.TAG }}-${{ env.PLUGINS_VERSION }} - restore-keys: | - cache-json-files-${{ runner.os }}-${{ env.TAG }}-${{ env.PLUGINS_VERSION }} - - - name: Check if version is already tested - if: ${{ github.event_name == 'schedule' }} - id: check-version - run: | - mkdir -p ./cache-files - file="./cache-files/${{ env.TAG }}-${{ env.PLUGINS_VERSION }}.json" - if [ -f "$file" ]; then - echo "Cache file exists: $file" - alreadyTestedShellVersion=$(jq -r '.shellVersion' $file) - alreadyTestedPluginsVersion=$(jq -r '.pluginsVersion' $file) - if [[ "$alreadyTestedShellVersion" == "${{ env.VERSION }}" && "$alreadyTestedPluginsVersion" == "${{ env.PLUGINS_VERSION }}" ]]; then - echo "Shell version $alreadyTestedShellVersion with plugins of version $alreadyTestedPluginsVersion already tested." - echo "skip_job=true" >> $GITHUB_ENV - fi - else - echo "No cache file found for ${{ env.TAG }} with plugins version ${{ env.PLUGINS_VERSION }}" - fi - - - name: Skip if already tested - if: ${{ env.skip_job == 'true' }} - run: echo "Skipping job for shell version ${{ env.VERSION }} and plugins version ${{ env.PLUGINS_VERSION }}" - - name: Setup Node.js - if: ${{ env.skip_job != 'true' }} uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' - name: Install dependencies - if: ${{ env.skip_job != 'true' }} run: npm ci - name: Download build artifact - if: ${{ env.skip_job != 'true' }} uses: actions/download-artifact@v4 with: name: build path: dist/apps/sag-pkg-community-plugins/ - name: Get shell app of particular version - if: ${{ env.skip_job != 'true' }} uses: SoftwareAG/plugins-e2e-setup/get-shell-app@main with: shell-name: cockpit @@ -145,7 +149,6 @@ jobs: shell-path: dist/apps - name: Cypress run - if: ${{ env.skip_job != 'true' }} uses: cypress-io/github-action@v5 with: start: npm run cypress:ctrl @@ -157,7 +160,7 @@ jobs: env: C8Y_CTRL_MODE=mocking,C8Y_CTRL_PROVIDER_VERSION=${{ env.VERSION }} - name: Upload cypress screenshots - if: failure() && env.skip_job != 'true' + if: failure() uses: actions/upload-artifact@v4 with: retention-days: 5 @@ -165,7 +168,7 @@ jobs: path: cypress/screenshots - name: Upload cypress videos - if: always() && env.skip_job != 'true' + if: always() uses: actions/upload-artifact@v4 with: retention-days: 5 @@ -173,7 +176,7 @@ jobs: path: cypress/videos - name: Create or update JSON file - if: ${{ env.skip_job != 'true' && github.event_name == 'schedule' }} + if: ${{ github.event_name == 'pull_request' }} run: | file="./cache-files/${{ env.TAG }}-${{ env.PLUGINS_VERSION }}.json" now=$(date --utc +"%Y-%m-%dT%H:%M:%SZ") @@ -181,8 +184,8 @@ jobs: cat $file - name: Upload updated JSON file to cache - if: ${{ env.skip_job != 'true' && github.event_name == 'schedule' }} + if: ${{ github.event_name == 'pull_request' }} uses: actions/cache@v4 with: path: ./cache-files - key: cache-json-files-${{ runner.os }}-${{ env.TAG }}-${{ env.PLUGINS_VERSION }} + key: test-plugins-against-shell-e2e-results