Merge pull request #300 from TechnologyEnhancedLearning/feat-version-… #97
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: release | |
| on: | |
| push: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| actions: write | |
| env: | |
| # Permission | |
| # Using key with more permissions | |
| GITHUB_TOKEN: ${{ secrets.NUGETKEY }} | |
| TEL_GIT_PACKAGES_TOKEN: ${{ secrets.NUGETKEY }} | |
| GITHUB_USERNAME: "Phil-NHS" | |
| # Nuget Set Up | |
| NUGET_PACKAGES_OUTPUT_PATH: ${{ github.workspace }}/CICDPackageLocation | |
| LOCAL_PACKAGES_PATH: ${{ github.workspace }}/CICDPackageLocation | |
| TEL_GIT_PACKAGE_SOURCE : "https://nuget.pkg.github.com/TechnologyEnhancedLearning/index.json" | |
| # Build Set Up | |
| USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE: false | |
| jobs: | |
| generate-semantic-version: | |
| name: Generate semantic version for package and repo | |
| runs-on: ubuntu-latest | |
| outputs: | |
| semantic-release-version: ${{ steps.set_semantic_version.outputs.semantic-release-version }} | |
| semantic-version-change-required: ${{ steps.set_semantic_version.outputs.semantic-version-change-required }} | |
| steps: | |
| - name: checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # required for semantic release to analyze commit history | |
| - name: Install semantic release packages | |
| run: | | |
| echo "Installing semantic-release packages..." | |
| npm install -D \ | |
| semantic-release \ | |
| @semantic-release/changelog \ | |
| @semantic-release/git \ | |
| @semantic-release/commit-analyzer \ | |
| @semantic-release/release-notes-generator \ | |
| @semantic-release/github | |
| echo "Semantic Release packages installed." | |
| npm ls --depth=0 # Debug: List installed packages | |
| #configured with .releaseserc | |
| - name: run semantic release | |
| id: set_semantic_version | |
| run: | | |
| echo "error catch run of semver first to get any error detail on config issues" | |
| set +e | |
| SEMVER_OUTPUT_RAW_ERROR_CHECK=$(npx semantic-release --dry-run 2> /tmp/semantic-release-errors.log) | |
| STATUS_ERROR_CHECK=$? | |
| echo $SEMVER_OUTPUT_RAW_ERROR_CHECK | |
| echo "STATUS_ERROR_CHECK = $STATUS_ERROR_CHECK " | |
| # Now you can check the status and log the error messages if an error occurred | |
| if [ $STATUS_ERROR_CHECK -ne 0 ]; then | |
| echo "❌ Semantic release failed with exit code $STATUS_ERROR_CHECK." | |
| echo "❌ Error output:" | |
| cat /tmp/semantic-release-errors.log | |
| else | |
| echo "✅ Semantic Ouput success : $SEMVER_OUTPUT_RAW_ERROR_CHECK " | |
| echo "✅ Error on success : $STATUS_ERROR_CHECK" | |
| fi | |
| set -e | |
| echo "running semantic-release" | |
| echo "⚠️ Semver-release will not be able to make the change if branch checks havent run if they are required ⚠️" | |
| SEMVER_OUTPUT_RAW=$(npx semantic-release) | |
| echo "semantic-release run" | |
| echo "$SEMVER_OUTPUT_RAW" | |
| # Check for no changes and set SEMVER_VERSION accordingly | |
| if echo "$SEMVER_OUTPUT_RAW" | grep -q 'There are no relevant changes'; then | |
| echo "No relevant changes found" | |
| SEMVER_CHANGED=false | |
| echo "Changes do not warrant a version change. gh_pages and packages won't be updated." | |
| echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT | |
| # Check if version bump expected | |
| elif echo "$SEMVER_OUTPUT_RAW" | grep -q 'Published release'; then | |
| # Extract the actual version, if it fails here we want to know | |
| SEMVER_VERSION=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Published release \K[\d.]+') | |
| echo "Version change detected - SEMVER_VERSION=$SEMVER_VERSION" | |
| echo "version change required true" | |
| SEMVER_CHANGED=true | |
| echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT | |
| echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT | |
| else | |
| echo "⚠️ Semver-release not successfully parsed ⚠️" | |
| echo "Output did not match expected patterns" | |
| echo "Raw output was: $SEMVER_OUTPUT_RAW" | |
| exit 1 | |
| fi | |
| build-telblazor-package-and-publish: | |
| needs: [generate-semantic-version] | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.generate-semantic-version.outputs.semantic-version-change-required == 'true' }} # Only run if there's a version | |
| env: | |
| TELBLAZOR_PACKAGE_VERSION: ${{ needs.generate-semantic-version.outputs.semantic-release-version }} | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: global.json | |
| # the restore cant be given env values to override values like it can in build so we need to remove this file so we use the env values | |
| - name: Remove local package settings (CI Only) | |
| run: rm -f PackageSettings.props.local | |
| - name: Replace nuget.config with CI template | |
| run: | | |
| rm -f nuget.config | |
| cp nuget.config.cicd nuget.config | |
| - name: Replace local environment variable in nuget config because cant provide it as a parameter | |
| run: | | |
| sed -i "s|%TEL_BLAZOR_PACKAGE_SOURCE%|$LOCAL_PACKAGES_PATH|g" nuget.config | |
| sed -i "s|%GITHUB_USERNAME%|$GITHUB_USERNAME|g" nuget.config | |
| sed -i "s|%TEL_GIT_PACKAGES_TOKEN%|$TEL_GIT_PACKAGES_TOKEN|g" nuget.config | |
| - name: Create appsettings development from secrets | |
| run: | | |
| declare -A paths | |
| paths["./TELBlazor.Components.UnitTests/appsettings.Development.json"]='${{ secrets.UNITTESTS_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.ShowCase.WasmStaticClient/wwwroot/appsettings.Development.json"]='${{ secrets.WASMSTATICCLIENT_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost.Client/wwwroot/appsettings.Development.json"]='${{ secrets.WASMSERVERHOSTCLIENT_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/appsettings.Development.json"]='${{ secrets.WASMSERVERHOST_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.UnitTests/appsettings.Production.json"]='${{ secrets.UNITTESTS_APPSETTINGS_PRODUCTION }}' | |
| paths["./TELBlazor.Components.ShowCase.WasmStaticClient/wwwroot/appsettings.Production.json"]='${{ secrets.WASMSTATICCLIENT_APPSETTINGS_PRODUCTION }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost.Client/wwwroot/appsettings.Production.json"]='${{ secrets.WASMSERVERHOSTCLIENT_APPSETTINGS_PRODUCTION }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/appsettings.Production.json"]='${{ secrets.WASMSERVERHOST_APPSETTINGS_PRODUCTION }}' | |
| for path in "${!paths[@]}"; do | |
| mkdir -p "$(dirname "$path")" | |
| printf '%s' "${paths[$path]}" > "$path" | |
| done | |
| - name: Clean lock files because the newly generated package file will supersede 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 | |
| run: npm ci | |
| #CI is an install that adheres to package-lock | |
| - name: Install wasm-tools workload (wasm-tools used for delinking so can test against optimised client wasm using TELBlazor package) | |
| run: dotnet workload install wasm-tools --skip-manifest-update --source https://api.nuget.org/v3/index.json | |
| - name: Build and pack TELBlazor.Components | |
| run: | | |
| dotnet build TELBlazor.Components -c Release \ | |
| /p:TELBlazorPackageVersion=$TELBLAZOR_PACKAGE_VERSION \ | |
| /p:NugetPackagesOutputPath=$NUGET_PACKAGES_OUTPUT_PATH \ | |
| /p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \ | |
| /p:DisablePackageGeneration=false | |
| - name: Publish to TELBlazor.Components Package | |
| run: | | |
| dotnet nuget push "$NUGET_PACKAGES_OUTPUT_PATH/TELBlazor.Components.*.nupkg" \ | |
| --source "$TEL_GIT_PACKAGE_SOURCE" \ | |
| --api-key $TEL_GIT_PACKAGES_TOKEN \ | |
| --skip-duplicate | |
| update-gh-pages-site: | |
| name: Update the production TELBlazor ShowCase page (on this repo) | |
| needs: [build-telblazor-package-and-publish, generate-semantic-version] | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.generate-semantic-version.outputs.semantic-version-change-required == 'true' }} # Only run if there's a version | |
| env: | |
| TELBLAZOR_PACKAGE_VERSION: ${{ needs.generate-semantic-version.outputs.semantic-release-version }} | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: global.json | |
| - name: Remove local packagesettings (CI Only) | |
| run: rm -f PackageSettings.props.local | |
| - name: Replace nuget.config with CI template | |
| run: | | |
| rm -f nuget.config | |
| cp nuget.config.cicd nuget.config | |
| - name: Replace local environment variable in nuget config because cant provide it as a parameter | |
| run: | | |
| sed -i "s|%TEL_BLAZOR_PACKAGE_SOURCE%|$TEL_GIT_PACKAGE_SOURCE|g" nuget.config | |
| sed -i "s|%GITHUB_USERNAME%|$GITHUB_USERNAME|g" nuget.config | |
| sed -i "s|%TEL_GIT_PACKAGES_TOKEN%|$TEL_GIT_PACKAGES_TOKEN|g" nuget.config | |
| - name: Create appsettings development from secrets | |
| run: | | |
| declare -A paths | |
| paths["./TELBlazor.Components.UnitTests/appsettings.Development.json"]='${{ secrets.UNITTESTS_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.ShowCase.WasmStaticClient/wwwroot/appsettings.Development.json"]='${{ secrets.WASMSTATICCLIENT_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost.Client/wwwroot/appsettings.Development.json"]='${{ secrets.WASMSERVERHOSTCLIENT_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/appsettings.Development.json"]='${{ secrets.WASMSERVERHOST_APPSETTINGS_DEVELOPMENT }}' | |
| paths["./TELBlazor.Components.UnitTests/appsettings.Production.json"]='${{ secrets.UNITTESTS_APPSETTINGS_PRODUCTION }}' | |
| paths["./TELBlazor.Components.ShowCase.WasmStaticClient/wwwroot/appsettings.Production.json"]='${{ secrets.WASMSTATICCLIENT_APPSETTINGS_PRODUCTION }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost.Client/wwwroot/appsettings.Production.json"]='${{ secrets.WASMSERVERHOSTCLIENT_APPSETTINGS_PRODUCTION }}' | |
| paths["./TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/appsettings.Production.json"]='${{ secrets.WASMSERVERHOST_APPSETTINGS_PRODUCTION }}' | |
| for path in "${!paths[@]}"; do | |
| mkdir -p "$(dirname "$path")" | |
| printf '%s' "${paths[$path]}" > "$path" | |
| done | |
| - name: Clean lock files because the newly generated package file will supersede the locks | |
| run: | | |
| echo "Listing packages.lock.json files:" | |
| find . -name "packages.lock.json" -type f -print | |
| echo "" | |
| echo "Deleting packages.lock.json files:" | |
| find . -name "packages.lock.json" -type f -exec rm -f {} \; | |
| echo "Listing packages.lock.json files:" | |
| find . -name "packages.lock.json" -type f -print | |
| - 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 | |
| run: npm ci | |
| - name: Install wasm-tools workload (wasm-tools used for delinking so can test against optimised client wasm using TELBlazor package) | |
| run: dotnet workload install wasm-tools --skip-manifest-update --source https://api.nuget.org/v3/index.json | |
| - name: Build solution without generating new package | |
| run: | | |
| dotnet build TELBlazor.sln -c Release \ | |
| /p:TELBlazorPackageVersion=$TELBLAZOR_PACKAGE_VERSION \ | |
| /p:NugetPackagesOutputPath=$NUGET_PACKAGES_OUTPUT_PATH \ | |
| /p:UseTELBlazorComponentsProjectReference=false \ | |
| /p:DisablePackageGeneration=true | |
| - name: Publish WasmStaticClient TELBlazor ShowCase | |
| run: | | |
| dotnet publish ./TELBlazor.Components.ShowCase.WasmStaticClient/TELBlazor.Components.ShowCase.WasmStaticClient.csproj --configuration Release \ | |
| /p:TELBlazorPackageVersion=$TELBLAZOR_PACKAGE_VERSION \ | |
| /p:NugetPackagesOutputPath=$NUGET_PACKAGES_OUTPUT_PATH \ | |
| /p:UseTELBlazorComponentsProjectReference=false \ | |
| /p:DisablePackageGeneration=true | |
| - name: Deploy to GitHub Pages | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| folder: docs # The folder the action should deploy | |
| branch: gh-pages # The branch the action should deploy to |