From 2f021d03439dc4edebc9ef4d6b509586e9d295ef Mon Sep 17 00:00:00 2001 From: Miles Petrov Date: Wed, 4 Sep 2024 12:07:27 -0400 Subject: [PATCH] Cleanup flow --- .github/workflows/demo-build.yml | 122 ++++++++++++------------------- 1 file changed, 46 insertions(+), 76 deletions(-) diff --git a/.github/workflows/demo-build.yml b/.github/workflows/demo-build.yml index a90a99d6b1b..6c8cb4f8e33 100644 --- a/.github/workflows/demo-build.yml +++ b/.github/workflows/demo-build.yml @@ -24,53 +24,58 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} steps: - uses: actions/checkout@v4 + with: + path: ramp - uses: actions/setup-node@v4 with: - node-version: '22.5.1' - cache: 'npm' + node-version: '22.5.1' + cache: 'npm' + cache-dependency-path: ramp/package-lock.json - name: Set up Git run: | git config --global user.name "GitHub Action" git config --global user.email "action@github.com" + - uses: actions/checkout@v4 + with: + ref: demo-page + path: demo-page + continue-on-error: true + + - name: Create orphan branch if checkout fails (demo-page doesn't exist) + if: failure() + run: | + echo "Checkout failed, creating orphan branch..." + mkdir -p demo-page + cd demo-page + git init + git checkout --orphan demo-page + git commit --allow-empty -m "Create orphan branch" + git remote add origin ${{ github.repositoryUrl }} + git push -u origin demo-page + + - name: Remove the old demo if it exists and make docs folder + run: | + rm -rf demo-page/${{ github.ref_name }} + mkdir -p demo-page/${{ github.ref_name }}/docs/api-tech-docs + + - name: Update docsite version references before docs are built + uses: jacobtomlinson/gha-find-replace@v3 + with: + find: '{{ramp-version}}' + replace: ${{ github.ref_name }} + include: 'ramp/docs/**' + regex: false + - name: Build or delete the demo run: | - 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 origin/demo-page - ls -a - 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 origin/$BRANCH_OR_TAG_NAME - git checkout -b temp-$BRANCH_OR_TAG_NAME - - echo "Current branch or tag: temp-$BRANCH_OR_TAG_NAME" - ls -a - - mkdir demo-folder - git --work-tree=demo-folder checkout origin/demo-page -- . - - echo "Demo folder added" - ls -a - - # Modify and commit changes + cd ramp npm ci npm run build + npm run ts-docs:generate + npm run vite-docs:generate - name: Publish to NPM if: github.repository == 'ramp4-pcar4/ramp4-pcar4' && startsWith(github.ref, 'refs/tags/v') @@ -85,51 +90,16 @@ jobs: 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 + - name: Move the built files and docs into the demo-page run: | - BRANCH_OR_TAG_NAME=${GITHUB_REF#refs/heads/} - BRANCH_OR_TAG_NAME=${BRANCH_OR_TAG_NAME#refs/tags/} - - # Remove the existing demo if it exists - rm -rf demo-folder/$BRANCH_OR_TAG_NAME - - # Create a subfolder and checkout demo-page's content - mkdir -p demo-folder/$BRANCH_OR_TAG_NAME/docs/api-tech-docs - - npm run ts-docs:generate - npm run vite-docs:generate - - # Move the built files and docs into the demo-folder - 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 - - ls -a - - # rm -rf node_modules + mv ramp/dist/* demo-page/${{ github.ref_name }} + mv ramp/vite-docs/* demo-page/${{ github.ref_name }}/docs + mv ramp/ts-docs/* demo-page/${{ github.ref_name }}/docs/api-tech-docs - git add demo-folder - git commit -m "Modified contents of demo-page within demo-folder" - - # Apply the changes to demo-page - git checkout demo-page - - git checkout temp-$BRANCH_OR_TAG_NAME -- demo-folder - mv demo-folder/* . - rm -rf demo-folder - - - name: Consolidate docsite files + - name: Squash and push changes to demo-page run: | + cd ../demo-page git add . - git commit -m "Applied changes from demo-folder to demo-page" # Squash the commit history into a single commit @@ -140,7 +110,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: '.' + path: demo-page retention-days: 1 - name: Setup Pages