Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for workflows shipped with the creators package #13008

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/scripts/check-creators-workflows-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
set -eo pipefail

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
BASE_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
CREATOR_WORKFLOWS_DIR="$BASE_DIR/creators/extension/app/files/.github/workflows"
WORKFLOW_BRANCH="$1"

generate_proper_charts() {
cat <<EOF
name: Build and Release Extension Charts

on:
workflow_dispatch:
release:
types: [released]

defaults:
run:
shell: bash
working-directory: ./

jobs:
build-extension-charts:
uses: rancher/dashboard/.github/workflows/build-extension-charts.yml@$WORKFLOW_BRANCH
permissions:
actions: write
contents: write
deployments: write
pages: write
with:
target_branch: gh-pages
tagged_release: \${{ github.ref_name }}
EOF
}

generate_proper_catalog() {
cat <<EOF
name: Build and Release Extension Catalog

on:
workflow_dispatch:
release:
types: [released]

defaults:
run:
shell: bash
working-directory: ./

jobs:
build-extension-catalog:
uses: rancher/dashboard/.github/workflows/build-extension-catalog.yml@$WORKFLOW_BRANCH
permissions:
actions: write
contents: read
packages: write
with:
registry_target: ghcr.io
registry_user: \${{ github.actor }}
tagged_release: \${{ github.ref_name }}
secrets:
registry_token: \${{ secrets.GITHUB_TOKEN }}
EOF
}

compare_files() {
local expected="$1"
local actual_file="$2"
local description="$3"

if ! diff <(echo "$expected") "$actual_file" >/dev/null; then
echo "::error::$description validation failed for branch $WORKFLOW_BRANCH"
exit 1
fi
}

main() {
charts_expected=$(generate_proper_charts)
catalog_expected=$(generate_proper_catalog)

compare_files "$charts_expected" \
"$CREATOR_WORKFLOWS_DIR/build-extension-charts.yml" \
"build-extension-charts workflow"

compare_files "$catalog_expected" \
"$CREATOR_WORKFLOWS_DIR/build-extension-catalog.yml" \
"build-extension-catalog workflow"

echo "All workflows validated successfully for $WORKFLOW_BRANCH"
}

main
45 changes: 42 additions & 3 deletions .github/workflows/test-extension-workflows-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ jobs:
run: .github/workflows/scripts/test-extensions-creators-build.sh
id: test-extensions-and-creators
shell: bash

branch-checks:
if: ${{ github.repository_owner == 'rancher' }}
runs-on: ubuntu-latest
strategy:
matrix:
branch: [master, release-2.9, release-2.8]
outputs:
status-${{ matrix.branch }}: ${{ job.status }}
steps:
- name: Checkout ${{ matrix.branch }}
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}

- name: Validate workflows
run: .github/workflows/scripts/check-creators-workflows-code.sh "${{ matrix.branch }}"

matching-creators-workflows:
if: ${{ github.repository_owner == 'rancher' }}
runs-on: ubuntu-latest
needs: [branch-checks]
outputs:
matching-creators-workflows-job-status: ${{ steps.aggregate.outputs.result }}
steps:
- name: Aggregate results
id: aggregate
run: |
# Check all branch check outcomes
if [[ '${{ needs.branch-checks.result }}' == 'failure' ]]; then
echo "result=failure" >> $GITHUB_OUTPUT
else
echo "result=success" >> $GITHUB_OUTPUT
fi

retrieve-tags-master:
if: ${{ github.repository_owner == 'rancher' }}
runs-on: ubuntu-latest
Expand All @@ -43,6 +78,7 @@ jobs:
run: source ./.github/workflows/scripts/retrieve-versions.sh
id: retrieve-data
shell: bash

test-build-extension-charts-master:
needs: retrieve-tags-master
uses: rancher/dashboard/.github/workflows/build-extension-charts.yml@master
Expand All @@ -57,6 +93,7 @@ jobs:
is_test: 'true'
test_ext_repo: 'ui-plugin-examples'
test_ext_branch: 'main'

test-build-extension-catalog-master:
needs: retrieve-tags-master
uses: rancher/dashboard/.github/workflows/build-extension-catalog.yml@master
Expand All @@ -73,13 +110,15 @@ jobs:
test_ext_branch: 'main'
secrets:
registry_token: ${{ secrets.GITHUB_TOKEN }}

test-release-shell-pkg-master:
needs: retrieve-tags-master
uses: rancher/dashboard/.github/workflows/release-shell-pkg.yaml@master
with:
is_test: 'true'
test_branch: 'master'
tag: ${{ needs.retrieve-tags-master.outputs.SHELL_TAG }}

test-release-creators-pkg-master:
needs: retrieve-tags-master
uses: rancher/dashboard/.github/workflows/release-shell-pkg.yaml@master
Expand All @@ -91,16 +130,16 @@ jobs:
slack-message:
if: ${{ always() }}
runs-on: ubuntu-latest
needs: [test-extensions-creators-and-update-paths, retrieve-tags-master, test-build-extension-charts-master, test-build-extension-catalog-master, test-release-shell-pkg-master, test-release-creators-pkg-master]
needs: [matching-creators-workflows, test-extensions-creators-and-update-paths, retrieve-tags-master, test-build-extension-charts-master, test-build-extension-catalog-master, test-release-shell-pkg-master, test-release-creators-pkg-master]
steps:
- name: Slack message for workflow
if: always()
shell: bash
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_EXT_WFS }}
run: |
OUTPUT_ARRAY=("${{ needs.test-extensions-creators-and-update-paths.outputs.test-extensions-creators-and-update-paths-job-status }}" "${{ needs.retrieve-tags-master.outputs.tags-job-status }}" "${{ needs.test-build-extension-charts-master.outputs.build-job-status }}" "${{ needs.test-build-extension-catalog-master.outputs.build-extension-catalog-job-status }}" "${{ needs.test-release-shell-pkg-master.outputs.build-release-shell-creators-status }}" "${{ needs.test-release-creators-pkg-master.outputs.build-release-shell-creators-status }}")
JOB_NAME_ARRAY=("test-extensions-creators-and-update-paths" "retrieve-tags-master" "test-build-extension-charts-master" "test-build-extension-catalog-master" "test-release-shell-pkg-master" "test-release-creators-pkg-master")
OUTPUT_ARRAY=("${{ needs.matching-creators-workflows.outputs.matching-creators-workflows-job-status }}" "${{ needs.test-extensions-creators-and-update-paths.outputs.test-extensions-creators-and-update-paths-job-status }}" "${{ needs.retrieve-tags-master.outputs.tags-job-status }}" "${{ needs.test-build-extension-charts-master.outputs.build-job-status }}" "${{ needs.test-build-extension-catalog-master.outputs.build-extension-catalog-job-status }}" "${{ needs.test-release-shell-pkg-master.outputs.build-release-shell-creators-status }}" "${{ needs.test-release-creators-pkg-master.outputs.build-release-shell-creators-status }}")
JOB_NAME_ARRAY=("matching-creators-workflows" "test-extensions-creators-and-update-paths" "retrieve-tags-master" "test-build-extension-charts-master" "test-build-extension-catalog-master" "test-release-shell-pkg-master" "test-release-creators-pkg-master")

if [[ ${OUTPUT_ARRAY[@]} =~ "failure" ]]; then
MSG_PREFIX="\nWorkflows testing for extensions failed! ❌"
Expand Down