Add debug #26
This file contains 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
# Workflow for building and deploying a demo site to GitHub Pages | |
name: Deploy static demo files to Pages | |
on: push | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these deployments to complete. | |
concurrency: | |
group: 'pages' | |
cancel-in-progress: false | |
jobs: | |
build: | |
name: Build the project | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '22.5.1' | |
cache: 'npm' | |
- name: Set up Git | |
run: | | |
git config --global user.name "GitHub Action" | |
git config --global user.email "action@github.com" | |
- name: Build or delete the demo | |
run: | | |
set -e # Exit immediately if a command exits with a non-zero status | |
trap 'echo "::error::Command failed with exit code $? at line $LINENO"' ERR | |
BRANCH_OR_TAG_NAME=${GITHUB_REF#refs/heads/} | |
BRANCH_OR_TAG_NAME=${BRANCH_OR_TAG_NAME#refs/tags/} | |
git fetch --all | |
# Check if demo-page branch exists and create it if necessary | |
if git ls-remote --heads origin demo-page | grep -q "refs/heads/demo-page"; then | |
echo "demo-page exists." | |
git checkout demo-page | |
else | |
echo "demo-page does not exist. Creating an orphan branch." | |
git checkout --orphan demo-page | |
git rm -rf . || true | |
rm -r * || true | |
git commit --allow-empty -m "Initial commit on orphan demo-page" | |
fi | |
# Checkout to current branch or tag and create a temporary branch | |
git checkout $BRANCH_OR_TAG_NAME | |
git checkout -b temp-$BRANCH_OR_TAG_NAME | |
# Create a subfolder and checkout demo-page's content | |
mkdir -p demo-folder/$BRANCH_OR_TAG_NAME/docs | |
git --work-tree=demo-folder checkout demo-page -- . || true | |
# Modify and commit changes | |
npm ci | |
npm run build | |
- name: Publish to NPM | |
if: github.repository == 'ramp4-pcar4/ramp4-pcar4' && startsWith(github.ref, 'refs/tags/v') | |
run: | | |
TAG_VERSION=${GITHUB_REF#refs/tags/v} | |
PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then | |
npm version --allow-same-version --no-git-tag-version $TAG_VERSION | |
fi | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Update docsite version references | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: '{{ramp-version}}' | |
replace: ${{ github.ref_name }} | |
include: 'docs/**' | |
regex: false | |
- name: Build or delete the demo | |
run: | | |
set -e # Exit immediately if a command exits with a non-zero status | |
trap 'echo "::error::Command failed with exit code $? at line $LINENO"' ERR | |
BRANCH_OR_TAG_NAME=${GITHUB_REF#refs/heads/} | |
BRANCH_OR_TAG_NAME=${BRANCH_OR_TAG_NAME#refs/tags/} | |
echo "::debug::Branch or Tag Name: $BRANCH_OR_TAG_NAME" | |
# Remove the existing demo if it exists | |
echo "::debug::Removing existing demo-folder/$BRANCH_OR_TAG_NAME if it exists" | |
rm -rf demo-folder/$BRANCH_OR_TAG_NAME || true | |
echo "::debug::Generating TypeScript docs" | |
npm run ts-docs:generate | |
echo "::debug::Generating Vite docs" | |
npm run vite-docs:generate | |
# Move the built files and docs into the demo-folder | |
echo "::debug::Moving built files and docs into demo-folder/$BRANCH_OR_TAG_NAME" | |
mv dist demo-folder/$BRANCH_OR_TAG_NAME | |
mv vite-docs demo-folder/$BRANCH_OR_TAG_NAME/docs | |
mv ts-docs demo-folder/$BRANCH_OR_TAG_NAME/docs/api-tech-docs | |
rm -rf node_modules | |
echo "::debug::Adding changes to git" | |
git add demo-folder | |
git commit -m "Modified contents of demo-page within demo-folder" | |
# Apply the changes to demo-page | |
echo "::debug::Checking out demo-page branch" | |
git checkout demo-page | |
echo "::debug::Checking out temp-$BRANCH_OR_TAG_NAME -- demo-folder" | |
git checkout temp-$BRANCH_OR_TAG_NAME -- demo-folder | |
echo "::debug::Moving demo-folder contents to root" | |
mv demo-folder/* . | |
rm -rf demo-folder | |
- name: Consolidate docsite files | |
run: | | |
echo "::debug::Starting consolidate docsite files step" | |
echo "::debug::Adding all changes to git" | |
git add . | |
echo "::debug::Committing changes" | |
git commit -m "Applied changes from demo-folder to demo-page" | |
# Squash the commit history into a single commit | |
echo "::debug::Squashing commit history" | |
git reset --soft $(git rev-list --max-parents=0 HEAD) | |
git commit -m "Applied changes from demo-folder to demo-page" | |
git push -f origin demo-page | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: '.' | |
retention-days: 1 | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |