Skip to content

Merge branch 'ci-setup' of https://github.com/TechnologyEnhancedLearn… #35

Merge branch 'ci-setup' of https://github.com/TechnologyEnhancedLearn…

Merge branch 'ci-setup' of https://github.com/TechnologyEnhancedLearn… #35

Workflow file for this run

name: Dev Check Test Package TELBlazor.Components Trigger TELBlazor-DevShowCase Deployment
on:
push:
branches-ignore:
- 'main'
- 'master'
permissions:
contents: write
actions: write
env:
# Permission
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Try other token so semver has the ability to add comments
GITHUB_TOKEN: ${{ secrets.NUGETKEY }}
PACKAGES_TOKEN: ${{ secrets.NUGETKEY }}
GITHUB_USERNAME: "Phil-NHS"
# Nuget Set Up
TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH: ${{ 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: false
jobs:
call-reusable-ci-checks-workflow:
name: run ci checks
uses: ./.github/workflows/reuseable-ci-checks.yml
with:
runall: true
# Now we've done due diligence
# The checks have been allowed to run if the workflow fails so if there a multiple fails we know.
# We do not proceed from the point if there is a fail.
# Hence explicit "if" and "needs"
generate-dev-semantic-version:
if: success()
needs: [call-reusable-ci-checks-workflow]
runs-on: ubuntu-latest
outputs:
dev-package-version: ${{ steps.set-dev-semantic-version.outputs.dev-semantic-version }}
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
- name: Run Semantic Version (None Blocking)
run: |
# If no version is required we can get an error so here we handle it
set +e
SEMVER_OUTPUT_RAW=$(npx semantic-release)
echo "Raw SEMVER_OUTPUT_RAW=$SEMVER_OUTPUT_RAW"
SEMVER_OUTPUT=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Published release \K[^\s]+')
# In development, we always package and update the website—even if there’s no version change.
# This ensures the CI process runs consistently and the latest code is deployed.
# It's especially useful when squashing commits, as it guarantees the package is still rebuilt and published.
echo "Packaging and updating the website in development, even without version changes, to ensure consistent CI behavior and updated packages after squashed commits."
STATUS=$?
if [ -z "$SEMVER_OUTPUT" ]; then
SEMVER_OUTPUT=$(echo "$SEMVER_OUTPUT_RAW" | grep -oP 'Found git tag v\K[^\s]+')
# Note: If Semver falls back to using a Git tag, it will pick the most recent one.
# This tag may not belong to the current branch, so the result isn't guaranteed to reflect the latest changes on this branch.
echo "Semver fallback: using latest Git tag, which may not be from the current branch."
fi
if [ -z "$SEMVER_OUTPUT" ]; then
SEMVER_OUTPUT="0.0.0"
echo "No semantic version or tag, defaulting to 0.0.0 $SEMVER_OUTPUT"
fi
# Export the result to the environment
echo "SEMVER_OUTPUT=$SEMVER_OUTPUT" >> $GITHUB_ENV
set -e
- name: Rename Semver Version With Date Time Dev
id: set-dev-semantic-version
run: |
echo "Semantic Release Output $SEMVER_OUTPUT"
# In development, we always package and update the website—even if there’s no version change.
# This ensures the CI process runs consistently and the latest code is deployed.
# It's especially useful when squashing commits, as it guarantees the package is still rebuilt and published.
timestamp=$(date +"%y%m%d-%H%M")
echo "Timestamp $timestamp"
full_version="${SEMVER_OUTPUT}-${timestamp}"
echo "extracted version $full_version"
echo "dev-semantic-version=$full_version" >> $GITHUB_OUTPUT
build-telblazor-dev-package-and-publish:
if: success()
needs: [generate-dev-semantic-version, call-reusable-ci-checks-workflow]
runs-on: ubuntu-latest
env:
DEV_TELBLAZOR_PACKAGE_VERSION: ${{ needs.generate-dev-semantic-version.outputs.dev-package-version }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Debug Version Output DEV_TELBLAZOR_PACKAGE_VERSION var
run: echo "Extracted Version $DEV_TELBLAZOR_PACKAGE_VERSION "
- 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
#CI is an install that adheres to package-lock
- name: Build TELBlazor.Components (it publishes on build)
env:
DISABLE_PACKAGE_GENERATION: false
run: |
dotnet build TELBlazor.Components -c Release \
/p:TELBlazorPackageVersion=$DEV_TELBLAZOR_PACKAGE_VERSION \
/p:NupkgOutputPath=$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH \
/p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \
/p:DisablePackageGeneration=$DISABLE_PACKAGE_GENERATION
- name: Publish to TechnologyEnhancedLearning as a Dev Package
run: |
dotnet nuget push "$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH/TELBlazor.Components.*.nupkg" \
--source "$TELBLAZOR_PACKAGE_SOURCE" \
--api-key $PACKAGES_TOKEN \
--skip-duplicate
Make-WasmStaticClient-DevShowCase-Artifact-Trigger-GH-Pages-In-TELBlazor-DevShowCase-Repo:
if: success() #not needed but being explicit
needs: [build-telblazor-dev-package-and-publish, generate-dev-semantic-version, call-reusable-ci-checks-workflow]
runs-on: ubuntu-latest
env:
DEV_TELBLAZOR_PACKAGE_VERSION: ${{ needs.generate-dev-semantic-version.outputs.dev-package-version }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Clean Solution
run: |
echo "Cleaning the solution..."
dotnet clean TELBlazor.sln
- name: Replace local environment variable in nuget config because cant provide it as a parameter
run: |
sed -i "s|%TELBlazorPackageSource%|$TELBLAZOR_PACKAGE_SOURCE|g" nuget.config
sed -i "s|%GITHUB_USERNAME%|$GITHUB_USERNAME|g" nuget.config
sed -i "s|%GITHUB_PACKAGES_TOKEN%|$PACKAGES_TOKEN|g" nuget.config
- name: debug DEV_TELBLAZOR_PACKAGE_VERSION
run: |
echo "DEV_TELBLAZOR_PACKAGE_VERSION $DEV_TELBLAZOR_PACKAGE_VERSION"
- name: Clean lock files because the newly generated package file will superseed 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
#qqqq with recent changes can we just build the solution now if this works then check
# - name: Build TELBlazor.Components.ShowCase.Shared
# run: |
# dotnet build TELBlazor.Components.ShowCase.Shared -c Release \
# /p:TELBlazorPackageVersion=$DEV_TELBLAZOR_PACKAGE_VERSION \
# /p:NupkgOutputPath=$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH \
# /p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \
# /p:TELBlazorPackageSource=$TELBLAZOR_PACKAGE_SOURCE
- name: Publish WasmStaticClient
run: |
dotnet publish ./TELBlazor.Components.ShowCase.WasmStaticClient/TELBlazor.Components.ShowCase.WasmStaticClient.csproj --configuration Release \
/p:TELBlazorPackageVersion=$DEV_TELBLAZOR_PACKAGE_VERSION \
/p:NupkgOutputPath=$TELBLAZOR_PACKAGE_LOCAL_OUTPUT_PATH \
/p:UseTELBlazorComponentsProjectReference=$USE_TEL_BLAZOR_COMPONENTS_PROJECT_REFERENCE \
/p:TELBlazorPackageSource=$TELBLAZOR_PACKAGE_SOURCE
#include hidden so we get jekyll
- name: Creating artifact of publish folder for test gh page workflow
uses: actions/upload-artifact@v4
with:
name: published-telblazor-components-showcase-wasmstaticclient-using-dev-package-${{env.DEV_TELBLAZOR_PACKAGE_VERSION}}
include-hidden-files: true
path: |
./docs
./docs/.nojekyll # explicitly include the .nojekyll file
retention-days: 90
- name: Get artifact location
run: |
# Get the artifact list for the current workflow run
ARTIFACT_LIST=$(gh api "repos/TechnologyEnhancedLearning/TELBlazor/actions/runs/${GITHUB_RUN_ID}/artifacts")
# Echo the entire artifact list for debugging purposes
echo "Artifact List: $ARTIFACT_LIST"
# Extract the download URL from the artifact list (first artifact in the list)
#ARTIFACT_URL=$(echo "$ARTIFACT_LIST" | jq -r '.artifacts[0].archive_download_url')
ARTIFACT_URL=$(echo "$ARTIFACT_LIST" | jq -r '.artifacts[0].url')
# Echo the artifact URL to confirm
echo "Artifact URL: $ARTIFACT_URL"
echo "artifact_url=$ARTIFACT_URL" >> $GITHUB_ENV
- name: Trigger Workflow in TELBlazor-DevShowCase Repository
run: |
repo_owner="TechnologyEnhancedLearning"
repo_name="TELBlazor-DevShowCase"
event_type="artifact_ready"
# Trigger the workflow
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $PACKAGES_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repo_owner/$repo_name/dispatches \
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"artifact_url\": \"$artifact_url\"}}"