Skip to content

Publish to GitHub Pages #10

Publish to GitHub Pages

Publish to GitHub Pages #10

Workflow file for this run

name: Publish to GitHub Pages
on:
release:
types:
- published
permissions:
id-token: write
pages: write
jobs:
publish:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Dump vars
if: vars.DUMP_VARS == 'true'
run: |
cat << EOF
${{ toJSON(vars) }}
EOF
- name: Dump GitHub context
if: vars.DUMP_GITHUB_CONTEXT == 'true'
run: |
cat << EOF
${{ toJSON(github) }}
EOF
- name: Checkout default repository (doc)
uses: actions/checkout@v6
with:
path: doc
- name: Reference branch
id: ref-branch
uses: aidc-toolkit/.github/actions/ref-branch@main
with:
path: doc
- name: Parse tag
id: parse-tag
run: |
# Tag includes label if this is a non-production release.
label=`echo ${{ github.ref_name }} | cut -d "-" -f 2 -s`
if [[ "$label" = "" ]]
then
base="/"
else
base="/$label/${{ steps.ref-branch.outputs.branch_name }}/"
fi
# Create repository state file.
mkdir -p doc/site/public
cat > doc/site/public/repository.txt << EOF
Date/time: `date`
Branch name: ${{ steps.ref-branch.outputs.branch_name }}
Label: $label
Publication base: $base
EOF
cat doc/site/public/repository.txt
echo "label=$label" >> $GITHUB_OUTPUT
echo "base=$base" >> $GITHUB_OUTPUT
- name: Setup node
uses: actions/setup-node@v6
with:
node-version: ${{ vars.NODE_VERSION }}
registry-url: https://registry.npmjs.org/
- name: Move .github
run: |
# Move .github to root to make actions accessible.
mv doc/.github .
- name: Start terminal session (pre build)
if: vars.TERMINAL_PRE_BUILD == 'true'
uses: mxschmitt/action-tmate@v3
- name: Build dev
uses: ./.github/actions/build-project-doc
with:
project: dev
branch: ${{ steps.ref-branch.outputs.branch }}
token: ${{ secrets.ORGANIZATION_READ_ONLY }}
- name: Build core
uses: ./.github/actions/build-project-doc
with:
project: core
branch: ${{ steps.ref-branch.outputs.branch }}
token: ${{ secrets.ORGANIZATION_READ_ONLY }}
- name: Build utility
uses: ./.github/actions/build-project-doc
with:
project: utility
branch: ${{ steps.ref-branch.outputs.branch }}
token: ${{ secrets.ORGANIZATION_READ_ONLY }}
- name: Build gs1
uses: ./.github/actions/build-project-doc
with:
project: gs1
branch: ${{ steps.ref-branch.outputs.branch }}
token: ${{ secrets.ORGANIZATION_READ_ONLY }}
- name: Build demo
uses: ./.github/actions/build-project-doc
with:
project: demo
branch: ${{ steps.ref-branch.outputs.branch }}
token: ${{ secrets.ORGANIZATION_READ_ONLY }}
- name: Build app-extension
uses: ./.github/actions/build-project-doc
with:
project: app-extension
branch: ${{ steps.ref-branch.outputs.branch }}
token: ${{ secrets.ORGANIZATION_READ_ONLY }}
- name: Build microsoft-add-in
uses: ./.github/actions/build-project-doc
with:
project: microsoft-add-in
branch: ${{ steps.ref-branch.outputs.branch }}
token: ${{ secrets.ORGANIZATION_READ_ONLY }}
- name: Build doc
uses: ./.github/actions/build-project-doc
with:
project: doc
branch: ${{ steps.ref-branch.outputs.branch }}
build_parameters: --base ${{ steps.parse-tag.outputs.base }}
- name: Start terminal session (post build)
if: vars.TERMINAL_POST_BUILD == 'true'
uses: mxschmitt/action-tmate@v3
- name: Restore production pages
if: steps.parse-tag.outputs.label != ''
working-directory: doc/.vitepress
run: |
# Move content to base directory.
mv dist _dist
mkdir -p dist${{ steps.parse-tag.outputs.base }}
mv _dist/* dist${{ steps.parse-tag.outputs.base }}
rmdir _dist
cd dist
escaped_base=`echo ${{ steps.parse-tag.outputs.base }} | sed -e 's/\/$//' | sed 's/\//\\\\\//g'`
relative_base=`echo ${{ steps.parse-tag.outputs.base }} | sed -e 's/^\///'`
# Patch generated HTML to refer to base directory.
find .${{ steps.parse-tag.outputs.base }} -name "*.html" -print0 | xargs -0 sed -i -e "s/https:\\/\\/aidc-toolkit.com/https:\\/\\/aidc-toolkit.com$escaped_base/g"
set +e
# Get consolidated pages.
curl -f -s https://aidc-toolkit.com/pages.zip -o pages.zip
if [[ $? -eq 0 ]]
then
# Unzip, excluding base directory if it exists.
unzip -qq pages.zip -x "$relative_base*"
# Remove pages.zip; will be recreated to include latest version of base directory.
rm pages.zip
fi
- name: Remove hostname
working-directory: doc/.vitepress/dist
run: |
# Replace absolute URLs on aidc-toolkit.com with relative URLs.
find . -name "*.html" -print0 | xargs -0 sed -i -e 's/https:\/\/aidc-toolkit.com\//\//g'
- name: Save pages
working-directory: doc/.vitepress/dist
run: |
# Create pages.zip.
zip -q -r pages .
- name: Start terminal session (post zip)
if: vars.TERMINAL_POST_ZIP == 'true'
uses: mxschmitt/action-tmate@v3
- name: Configure GitHub Pages
uses: actions/configure-pages@v5
- name: Upload pages directory
uses: actions/upload-pages-artifact@v3
with:
path: doc/.vitepress/dist
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Start terminal session (post deploy)
if: vars.TERMINAL_POST_DEPLOY == 'true'
uses: mxschmitt/action-tmate@v3