Merge pull request #102 from TechnologyEnhancedLearning/refactor-logging #37
  
    
      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: | | |
| # Set pipefail so we can check if pipefail is semantic-release classifying no version bump required as an error | |
| set -o pipefail | |
| OUTPUT=$(npx semantic-release 2>&1) || STATUS=$? | |
| echo "$OUTPUT" | |
| # 0 not exclusively due to no version bump so check output | |
| if [ "${STATUS:-0}" -ne 0 ]; then | |
| if echo "$OUTPUT" | grep -q "No release published"; then | |
| # No new version, but we can find the current version | |
| echo "No new version required getting current version from git tags" | |
| SEMVER_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-version-placeholder") # last git tag | |
| echo "semantic-release-version=$SEMVER_VERSION" | |
| SEMVER_CHANGED=false | |
| echo "Changes do not warrant a version change. gh_pages and packages won't be updated." | |
| echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT | |
| echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT | |
| exit 0 # treat as success code didnt fail there just was no version increment required | |
| else | |
| exit $STATUS # real error → fail pipeline | |
| fi | |
| else | |
| SEMVER_VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[\d.]+') | |
| echo "semantic-release-version=$SEMVER_VERSION" | |
| # VERSION=$(echo "$OUTPUT" | grep "Published release" | awk '{print $NF}') - AI suggestion try if issues | |
| # awk is a text-processing tool that splits each line into fields using whitespace by default. | |
| # $NF is a special variable in awk that means “the last field” of the current line. | |
| # print $NF prints just that last field. | |
| SEMVER_CHANGED=true | |
| echo "semantic-version-change-required=$SEMVER_CHANGED" | |
| echo "version change required true" | |
| echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT | |
| echo "semantic-version-change-required=$SEMVER_CHANGED" >> $GITHUB_OUTPUT | |
| # Just because weve been handling errors | |
| exit 0 | |
| fi | |
| #configured with .releaseserc | |
| # - name: Run semantic release | |
| # id: set_semantic_version | |
| # run: | | |
| # set +e | |
| # RELEASE_OUTPUT=$(npx semantic-release 2>&1) | |
| # echo "$RELEASE_OUTPUT" | |
| # # Try to extract the version from the full output | |
| # SEMVER_VERSION=$(echo "$RELEASE_OUTPUT" | grep -oP 'Published release \K[\d.]+') | |
| # # Output it clearly for debugging | |
| # echo "Parsed semantic-release version: $SEMVER_VERSION" | |
| # # Set GitHub Action output | |
| # echo "semantic-release-version=$SEMVER_VERSION" >> $GITHUB_OUTPUT | |
| # # Check if SEMVER_VERSION is empty and echo the message if so | |
| # if [ -z "$SEMVER_VERSION" ]; then | |
| # echo "Changes do not warrant a version change. gh_pages and packages won't be updated." | |
| # fi | |
| # set -e | |
| 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: 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-release-version != '' }} # 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: 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 |