Skip to content

feat(ci): tests against shell workflow debug #109

feat(ci): tests against shell workflow debug

feat(ci): tests against shell workflow debug #109

name: Test plugins against Cockpit
on:
pull_request:
schedule:
- cron: '15 4 * * 1-5'
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 }}
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: 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 out already tested versions
if: ${{ github.event_name == 'pull_request' }}
id: filter-versions
run: |
mkdir -p ./cache-files
versions=$(jq -r '.[] | @base64' <<< '${{ steps.collect-shell-versions.outputs.shell_versions }}')
filtered_versions="[]"
for version in $versions; do
_jq() {
echo ${version} | base64 --decode | jq -r ${1}
}
tag=$(_jq '.tag')
ver=$(_jq '.version')
file="./cache-files/${tag}-${{ steps.extract-plugins-version.outputs.plugins_version }}.json"
if [[ -f "$file" ]]; then
echo "Cache file exists: $file"
alreadyTestedShellVersion=$(jq -r '.shellVersion' $file)
alreadyTestedPluginsVersion=$(jq -r '.pluginsVersion' $file)
if [[ "$alreadyTestedShellVersion" == "$ver" && "$alreadyTestedPluginsVersion" == "${{ steps.extract-plugins-version.outputs.plugins_version }}" ]]; then
echo "Shell version $alreadyTestedShellVersion with plugins of version $alreadyTestedPluginsVersion already tested. Skipping..."
continue
fi
else
echo "No cache file found for $tag with plugins version ${{ steps.extract-plugins-version.outputs.plugins_version }}"
fi
filtered_versions=$(jq --argjson ver "$(echo $version | base64 --decode)" '. + [$ver]' <<< $filtered_versions)
done
echo "Filtered shell versions: $filtered_versions"
echo "::set-output name=shell_versions::$filtered_versions"
- name: Verify shell versions output
run: echo "Collected shell versions ${{ steps.collect-shell-versions.outputs.shell_versions }} and plugins version ${{ steps.extract-plugins-version.outputs.plugins_version }}"
build-plugins:
if: needs.collect-shell-versions.outputs.shell_versions != '[]'
needs: collect-shell-versions
timeout-minutes: 30
runs-on: ubuntu-22.04
outputs:
plugins_version: ${{ needs.collect-shell-versions.outputs.plugins_version }}
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:
if: needs.collect-shell-versions.outputs.shell_versions != '[]'
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 }}
TAG: ${{ matrix.version_data.tag }}
PLUGINS_VERSION: ${{ needs.build-plugins.outputs.plugins_version }}
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: Download build artifact
uses: actions/download-artifact@v4
with:
name: build
path: dist/apps/sag-pkg-community-plugins/
- name: Get shell app of particular version
uses: SoftwareAG/plugins-e2e-setup/get-shell-app@main
with:
shell-name: cockpit
shell-version: ${{ env.VERSION }}
shell-path: dist/apps
- name: Cypress run
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,C8Y_CTRL_PROVIDER_VERSION=${{ env.VERSION }}
- name: Upload cypress screenshots
if: failure()
uses: actions/upload-artifact@v4
with:
retention-days: 5
name: cypress-screenshots
path: cypress/screenshots
- name: Upload cypress videos
if: always()
uses: actions/upload-artifact@v4
with:
retention-days: 5
name: cypress-videos
path: cypress/videos
- name: Create or update JSON file
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")
jq -n --arg shellVersion "${{ env.VERSION }}" --arg pluginsVersion "${{ env.PLUGINS_VERSION }}" --arg lastSuccess "$now" '{shellVersion: $shellVersion, pluginsVersion: $pluginsVersion, lastSuccess: $lastSuccess}' > $file
cat $file
- name: Upload updated JSON file to cache
if: ${{ github.event_name == 'pull_request' }}
uses: actions/cache@v4
with:
path: ./cache-files
key: test-plugins-against-shell-e2e-results