[MTM-59397] As a plugin developer I want to have a workflow that will collect shell versions and run cypress tests against them #6
Workflow file for this run
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: Test plugins against Cockpit | |
on: | |
pull_request: | |
# TODO: add cron to test nightly | |
permissions: | |
contents: read | |
env: | |
ACTIONS_STEP_DEBUG: true | |
jobs: | |
collect-shell-versions: | |
timeout-minutes: 30 | |
runs-on: ubuntu-22.04 | |
outputs: | |
shell_versions: ${{ steps.collect-shell-versions.outputs.shell_versions }} | |
steps: | |
- name: Collect Shell Versions | |
id: collect-shell-versions | |
uses: SoftwareAG/plugins-e2e-setup/collect-shell-versions@main | |
with: | |
include-latest: true # TODO: remove this line | |
- name: Verify shell versions output | |
run: echo "Collected shell versions ${{ steps.collect-shell-versions.outputs.shell_versions }}" | |
build-plugins: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build | |
if-no-files-found: error | |
retention-days: 5 | |
path: | | |
dist/sag-pkg-community-plugins/** | |
run-tests-against-shell: | |
needs: [collect-shell-versions, build-plugins] | |
runs-on: ubuntu-22.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
version_data: ${{ fromJson(needs.collect-shell-versions.outputs.shell_versions) }} | |
env: | |
JSON: ${{ toJson(matrix.version_data) }} | |
VERSION: ${{ matrix.version_data.version }} | |
MAJOR: ${{ matrix.version_data.major }} | |
TAG: ${{ matrix.version_data.tag }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Retrieve cached JSON files | |
id: retrieve-cache | |
uses: actions/cache@v4 | |
with: | |
path: ./cache-files | |
key: cache-json-files-${{ runner.os }}-${{ env.TAG }} | |
restore-keys: | | |
cache-json-files-${{ runner.os }}-${{ env.TAG }} | |
- name: Check if version is already tested | |
id: check-version | |
run: | | |
mkdir -p ./cache-files | |
file="./cache-files/${{ env.TAG }}.json" | |
if [ -f "$file" ]; then | |
echo "Cache file exists: $file" | |
alreadyTestedVersion=$(jq -r '.version' $file) | |
if [[ "$alreadyTestedVersion" == "${{ env.VERSION }}" ]]; then | |
echo "Version $alreadyTestedVersion already tested." | |
echo "skip_job=true" >> $GITHUB_ENV | |
fi | |
else | |
echo "No cache file found for ${{ env.TAG }}" | |
fi | |
- name: Skip if already tested | |
if: env.skip_job == 'true' | |
run: echo "Skipping job for ${{ env.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 | |
shell-version: ${{ env.VERSION }} | |
shell-path: dist/apps | |
- name: Cypress run | |
if: env.skip_job != 'true' | |
uses: cypress-io/github-action@v5 | |
with: | |
start: npm run cypress:ctrl | |
install: false | |
wait-on: 'http://localhost:4200/apps/cockpit/index.html?remotes=%7B"sag-pkg-community-plugins"%3A%5B"ExampleWidgetPluginModule"%2C"DatapointsGraphWidgetModule"%5D%7D#' | |
browser: chrome | |
record: false | |
config-file: cypress.config.ts | |
env: C8Y_CTRL_MODE=mocking,grepTags=@${{ env.MAJOR }} | |
- name: Upload cypress screenshots | |
if: failure() && env.skip_job != 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
retention-days: 5 | |
name: cypress-screenshots | |
path: cypress/screenshots | |
- name: Upload cypress videos | |
if: always() && env.skip_job != 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
retention-days: 5 | |
name: cypress-videos | |
path: cypress/videos | |
- name: Create or update JSON file | |
if: env.skip_job != 'true' | |
run: | | |
file="./cache-files/${{ env.TAG }}.json" | |
now=$(date --utc +"%Y-%m-%dT%H:%M:%SZ") | |
jq -n --arg version "${{ env.VERSION }}" --arg lastSuccess "$now" '{version: $version, lastSuccess: $lastSuccess}' > $file | |
cat $file | |
- name: Upload updated JSON file to cache | |
if: env.skip_job != 'true' | |
uses: actions/cache@v4 | |
with: | |
path: ./cache-files | |
key: cache-json-files-${{ runner.os }}-${{ env.TAG }} |