Skip to content

Deploy to GitHub Pages #107

Deploy to GitHub Pages

Deploy to GitHub Pages #107

name: Deploy to GitHub Pages
on:
#push:
# branches: [ master ]
workflow_run:
workflows: ["Build BCL Package"] # Name of the workflow to trigger from.
types:
- completed
permissions:
contents: read
actions: write
# repository_dispatch: write
env:
BCL_Source: "https://nuget.pkg.github.com/phil-nhs/index.json"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
GITHUB_USERNAME: "Phil-NHS"
IS_LOCAL_DEV: false
USE_BCL_PROJECT_REFERENCE: false
jobs:
get-bcl-version:
runs-on: ubuntu-latest
outputs:
bcl-version: ${{ steps.get-bcl-version-from-git-packages.outputs.latest-bcl-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get BCL Version from Git Packages
id: get-bcl-version-from-git-packages
run: |
TOKEN="${{ secrets.GITHUB_TOKEN }}"
OWNER="Phil-NHS"
PACKAGE_NAME="TELBlazorComponentLibrary.GitPageBlazorWasm"
BCL_PACKAGE_PATH="https://api.github.com/users/$OWNER/packages/nuget/$PACKAGE_NAME/versions"
echo "API Path: $BCL_PACKAGE_PATH"
VERSION_JSON=$(curl -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github+json" $BCL_PACKAGE_PATH)
echo "$VERSION_JSON"
LATEST_VERSION=$(echo "$VERSION_JSON" | jq -r '.[0].name')
echo "latest-bcl-version=$LATEST_VERSION" >> $GITHUB_OUTPUT
update-gh-page:
needs: get-bcl-version
runs-on: ubuntu-latest
env:
BCL_VERSION: ${{ needs.get-bcl-version.outputs.bcl-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Replace local environment variable in nuget config because cant provide it as a parameter
run: |
sed -i "s|%LocalPackagePath%|$BCL_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 values
run: |
echo "BCL_VERSION $BCL_VERSION"
- name: Publish client using client release .csproj logic
run: |
dotnet publish ./TestHostPrerenderWASM/TestHostPrerenderWASM.Client/TestHostPrerenderWASM.Client.csproj --configuration Release \
/p:IsLocalDev=$IS_LOCAL_DEV \
/p:BCLVersion=$BCL_VERSION \
/p:UseBCLProjectReference=$USE_BCL_PROJECT_REFERENCE
# qqqq nice to have would be only running if version number increase
- name: Creating artifact of publish folder for test gh page workflow
uses: actions/upload-artifact@v4
with:
name: gh-blazor-components-wiki-site-using-package-${{env.BCL_VERSION}}
path: ./docs
retention-days: 90
- name: Debug artifact location
run: |
# Get the artifact list for the current workflow run
ARTIFACT_LIST=$(gh api "repos/TechnologyEnhancedLearning/GitPageBlazorWASM/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
# {
# "id": 2859123465,
# "node_id": "MDg6QXJ0aWZhY3QyODU5MTIzNDY1",
# "name": "gh-blazor-components-wiki-site-using-package-1.2.27-DEV-master-250401-12-36-20",
# "size_in_bytes": 8934640,
# "url": "https://api.github.com/repos/TechnologyEnhancedLearning/GitPageBlazorWASM/actions/artifacts/2859123465",
# "archive_download_url": "https://api.github.com/repos/TechnologyEnhancedLearning/GitPageBlazorWASM/actions/artifacts/2859123465/zip",
# "expired": false,
# "digest": "sha256:0f2f65b4ee432facd62b1558a2d3feaf59a9a58f2d5d8cfc066cb3a84194fd2c",
# "created_at": "2025-04-01T12:38:01Z",
# "updated_at": "2025-04-01T12:38:01Z",
# "expires_at": "2025-06-30T12:37:04Z",
# "workflow_run": {
# "id": 14195776281,
# "repository_id": 942679037,
# "head_repository_id": 942679037,
# "head_branch": "master",
# "head_sha": "aa71ffeaee45e4f5d9edbe84c0da15dee5397eb2"
# }
# }
# need gh or curl using gh for gh api actions
- name: Install GitHub CLI
run: |
sudo apt update
sudo apt install gh -y
# need gh or curl using gh for gh api actions - we have a token
# - name: Authenticate GitHub CLI
# run: |
# echo ${{ secrets.PACKAGES_TOKEN }} | gh auth login --with-token
# dont think token has what it needs -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
- name: Dispatch artifact ready event to test environment gh page
run: |
# Use the artifact URL that was passed from the previous step
echo "Artifact URL: $artifact_url"
# Dispatch the artifact URL to the other repository
gh api \
"repos/TechnologyEnhancedLearning/GitPageBlazorWASM-TestGHPage/dispatches" \
-H "Authorization: token $PACKAGES_TOKEN" \
-f event_type=artifact_ready \
-f client_payload='{"artifact_url": "'"$artifact_url"'"}'
- 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