feat(button): test cicd #1
This file contains hidden or 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: Reusable CI Checks | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| runall: | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| env: | ||
| # Permission | ||
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # PACKAGES_TOKEN: ${{ secrets.NUGETKEY }} | ||
| # GITHUB_USERNAME: "Phil-NHS" | ||
| # Nuget Set Up | ||
| TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH: ${{ github.workspace }}/CICDPackageLocation | ||
| TELBLAZOR_PACKAGE_SOURCE: ${{ github.workspace }}/CICDPackageLocation | ||
| #TELBLAZOR_PACKAGE_SOURCE: "https://nuget.pkg.github.com/TechnologyEnhancedLearning/index.json" | ||
| # Build Set Up | ||
| USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE: false | ||
| DISABLE_PACKAGE_GENERATION: true | ||
| E2E_TRACING_ENABLED: false | ||
| # Check Dummy Data | ||
| TELBLAZOR_PACKAGE_VERSION: "0.0.0-ci-checks" | ||
| jobs: | ||
| # Build Package | ||
| # Build Solution useing package | ||
| reuseable-ci-checks-solution-build: | ||
| name: Check solution builds | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: ${{ inputs.runall }} | ||
| outputs: | ||
| status: ${{ job.status }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| global-json-file: global.json | ||
| - name: Replace local environment variable in nuget config because cant provide it as a parameter | ||
| run: sed -i "s|%TELBlazorPackageSource%|$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH|g" nuget.config | ||
| - name: Clean lock files because the newly generated package file will superseed the locks | ||
| run: | | ||
| find . -name "packages.lock.json" -type f -exec rm -f {} \; | ||
| - name: Set up Node.js so we have gulp for retrieving TEL Frontend Css | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| - name: Install npm packages so we have gulp for retrieving TEL Frontend Css | ||
| working-directory: ./TELBlazor.Components | ||
| run: npm ci | ||
| - name: Build and create package locally | ||
| env: | ||
| #Overwrite package generation | ||
| DISABLE_PACKAGE_GENERATION: false | ||
| run: | | ||
| dotnet build TELBlazor.Components -c Release \ | ||
| /p:TELBlazorPackageVersion=$TELBLAZOR_PACKAGE_VERSION \ | ||
| /p:NupkgOutputPath=$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH \ | ||
| /p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \ | ||
| /p:TELBlazorPackageSource=$TELBLAZOR_PACKAGE_SOURCE \ | ||
| /p:DisablePackageGeneration=$DISABLE_PACKAGE_GENERATION \ | ||
| /p:E2ETracingEnabled=$E2E_TRACING_ENABLED | ||
| - name: Build solution without generating new package | ||
| env: | ||
| #Overwrite package generation | ||
| DISABLE_PACKAGE_GENERATION: true | ||
| run: | | ||
| dotnet build TELBlazor.sln -c Release \ | ||
| /p:TELBlazorPackageVersion=$TELBLAZOR_PACKAGE_VERSION \ | ||
| /p:NupkgOutputPath=$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH \ | ||
| /p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \ | ||
| /p:TELBlazorPackageSource=$TELBLAZOR_PACKAGE_SOURCE \ | ||
| /p:DisablePackageGeneration=$DISABLE_PACKAGE_GENERATION \ | ||
| /p:E2ETracingEnabled=$E2E_TRACING_ENABLED | ||
| reuseable-ci-checks-branch-name-check: | ||
| name: Check branch names | ||
| if: success() || failure() | ||
| continue-on-error: ${{ inputs.runall }} | ||
| outputs: | ||
| status: ${{ job.status }} | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Validate Branch Name | ||
| run: | | ||
| #BRANCH_NAME="${GITHUB_HEAD_REF}" | ||
| BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" | ||
| echo "Validating branch name: $BRANCH_NAME" | ||
| if [[ "$BRANCH_NAME" =~ ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|sample|security|config|bugfix|hotfix)-[a-zA-Z0-9._/-]+$ ]] || [[ "$BRANCH_NAME" == "master" ]]; then | ||
| echo "✅ Branch name is valid" | ||
| else | ||
| echo "❌ Invalid branch name: $BRANCH_NAME" | ||
| echo "Branch names must follow one of the allowed prefixes:" | ||
| echo " build-*, feat-*, fix-*, bugfix-*, hotfix-*, build-*, chore-*, ci-*, docs-*, perf-*, refactor-*, revert-*, style-*, test-*, sample-*, security-*, config-*, bugfix-*, hotfix-*" | ||
| exit 1 | ||
| fi | ||
| reuseable-ci-checks-commitlint: | ||
| name: Check commit names | ||
| runs-on: ubuntu-latest | ||
| if: success() || failure() | ||
| continue-on-error: ${{ inputs.runall }} | ||
| outputs: | ||
| status: ${{ job.status }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - uses: wagoid/commitlint-github-action@v5 | ||
| with: | ||
| configFile: .commitlintrc.json | ||
| reuseable-ci-checks-unit-tests: | ||
| name: Unit test components | ||
| runs-on: ubuntu-latest | ||
| if: success() || failure() | ||
| continue-on-error: ${{ inputs.runall }} | ||
| outputs: | ||
| status: ${{ job.status }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| global-json-file: global.json | ||
| - name: Replace local environment variable in nuget config because cant provide it as a parameter | ||
| run: sed -i "s|%TELBlazorPackageSource%|$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH|g" nuget.config | ||
| - name: Clean lock files because the newly generated package file will superseed the locks | ||
| run: | | ||
| find . -name "packages.lock.json" -type f -exec rm -f {} \; | ||
| - name: Set up Node.js so we have gulp for retrieving TEL Frontend Css | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| - name: Install npm packages so we have gulp for retrieving TEL Frontend Css | ||
| working-directory: ./TELBlazor.Components | ||
| run: npm ci | ||
| - name: Build and create package locally | ||
| env: | ||
| #Overwrite package generation | ||
| DISABLE_PACKAGE_GENERATION: false | ||
| run: | | ||
| dotnet build TELBlazor.Components -c Release \ | ||
| /p:TELBlazorPackageVersion=$TELBLAZOR_PACKAGE_VERSION \ | ||
| /p:NupkgOutputPath=$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH \ | ||
| /p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \ | ||
| /p:TELBlazorPackageSource=$TELBLAZOR_PACKAGE_SOURCE \ | ||
| /p:DisablePackageGeneration=$DISABLE_PACKAGE_GENERATION \ | ||
| /p:E2ETracingEnabled=$E2E_TRACING_ENABLED | ||
| - name: Build solution without generating new package | ||
| env: | ||
| #Overwrite package generation | ||
| DISABLE_PACKAGE_GENERATION: true | ||
| run: | | ||
| dotnet build TELBlazor.sln -c Release \ | ||
| /p:TELBlazorPackageVersion=$TELBLAZOR_PACKAGE_VERSION \ | ||
| /p:NupkgOutputPath=$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH \ | ||
| /p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \ | ||
| /p:TELBlazorPackageSource=$TELBLAZOR_PACKAGE_SOURCE \ | ||
| /p:DisablePackageGeneration=$DISABLE_PACKAGE_GENERATION \ | ||
| /p:E2ETracingEnabled=$E2E_TRACING_ENABLED | ||
| - name: Run Unit tests | ||
| run: | | ||
| reuseable-ci-checks-e2e-tests: | ||
| name: Check with end to end testing including nojs | ||
| timeout-minutes: 60 | ||
| runs-on: ubuntu-latest | ||
| if: success() || failure() | ||
| continue-on-error: ${{ inputs.runall }} | ||
| outputs: | ||
| status: ${{ job.status }} | ||
| steps: | ||
| - name: See other project pipeline for Tests | ||
| run: echo " See other project pipeline for Tests this is a placeholder" | ||
| reuseable-ci-checks-code-coverage: | ||
| name: Check for code coverage | ||
| runs-on: ubuntu-latest | ||
| if: success() || failure() | ||
| continue-on-error: ${{ inputs.runall }} | ||
| outputs: | ||
| status: ${{ job.status }} | ||
| steps: | ||
| - name: See other project pipeline for Tests | ||
| run: echo " See other project pipeline for Tests this is a placeholder" | ||
| reuseable-ci-checks-check-for-failed-jobs: | ||
| name: Check for failures | ||
| if: ${{ inputs.runall }} | ||
| needs: | ||
| - reuseable-ci-checks-solution-build | ||
| - reuseable-ci-checks-branch-name-check | ||
| - reuseable-ci-checks-commitlint | ||
| - reuseable-ci-checks-unit-tests | ||
| - reuseable-ci-checks-e2e-tests | ||
| - reuseable-ci-checks-code-coverage | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check Job Results | ||
| run: | | ||
| echo "Solution Build: ${{ needs.reuseable-ci-checks-solution-build.outputs.status }}" | ||
| echo "Branch Name Check: ${{ needs.reuseable-ci-checks-branch-name-check.outputs.status }}" | ||
| echo "Commitlint: ${{ needs.reuseable-ci-checks-commitlint.outputs.status }}" | ||
| echo "Unit Tests: ${{ needs.reuseable-ci-checks-unit-tests.outputs.status }}" | ||
| echo "E2E Tests: ${{ needs.reuseable-ci-checks-e2e-tests.outputs.status }}" | ||
| echo "Code Coverage: ${{ needs.reuseable-ci-checks-code-coverage.outputs.status }}" | ||
| # Check if any job is not success (failure, cancelled, skipped) | ||
| if [[ "${{ needs.reuseable-ci-checks-solution-build.outputs.status }}" != "success" || \ | ||
| "${{ needs.reuseable-ci-checks-branch-name-check.outputs.status }}" != "success" || \ | ||
| "${{ needs.reuseable-ci-checks-commitlint.outputs.status }}" != "success" || \ | ||
| "${{ needs.reuseable-ci-checks-unit-tests.outputs.status }}" != "success" || \ | ||
| "${{ needs.reuseable-ci-checks-e2e-tests.outputs.status }}" != "success" || \ | ||
| "${{ needs.reuseable-ci-checks-code-coverage.outputs.status }}" != "success" ]]; then | ||
| echo "❌ One or more jobs failed." | ||
| exit 1 | ||
| fi | ||
| continue-on-error: false | ||