Skip to content

Commit

Permalink
Cleanup flow
Browse files Browse the repository at this point in the history
  • Loading branch information
milespetrov committed Sep 4, 2024
1 parent 0297b10 commit c519b33
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 79 deletions.
134 changes: 57 additions & 77 deletions .github/workflows/demo-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,68 @@ 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 "[email protected]"
- name: Create orphan branch if demo-page doesn't exist
run: |
cd ramp
git fetch origin
if git show-ref --quiet refs/remotes/origin/demo-page; then
echo "Branch 'demo-page' exists on origin."
else
echo "Branch 'demo-page' does not exist on origin. Creating an orphan branch... https://github.com/${{ github.repository_owner }}/ramp4-pcar4.git"
cd ../
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 https://github.com/${{ github.repository_owner }}/ramp4-pcar4.git
git push -u origin demo-page
echo "Orphan branch 'demo-page' has been created and pushed to origin."
fi
- 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: Update docsite version references before docs are built
uses: jacobtomlinson/gha-find-replace@v3
with:
find: '{{repo-owner}}'
replace: ${{ github.repository_owner }}
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')
Expand All @@ -85,62 +100,27 @@ 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
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
# 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
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
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
git push origin HEAD --force
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '.'
path: demo-page
retention-days: 1

- name: Setup Pages
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
},
{
text: 'API Reference',
link: 'https://ramp4-pcar4.github.io/ramp4-pcar4/{{ramp-version}}/docs/api-tech-docs/index.html'
link: 'https://{{repo-owner}}.github.io/ramp4-pcar4/{{ramp-version}}/docs/api-tech-docs/index.html'
},
{
text: 'Releases',
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ hero:
link: overview
- theme: alt
text: API Reference
link: https://ramp4-pcar4.github.io/ramp4-pcar4/{{ramp-version}}/docs/api-tech-docs/index.html
link: https://{{repo-owner}}.github.io/ramp4-pcar4/{{ramp-version}}/docs/api-tech-docs/index.html
- theme: alt
text: GitHub
link: https://github.com/ramp4-pcar4/ramp4-pcar4
Expand Down
14 changes: 14 additions & 0 deletions docs/introduction/setup.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Demo Setup

When you push changes to your forked repo a demo preview is automatically generated. The preview is updated every time you push changes to your forked repo. Demos are deleted daily whenever the source branch or tag is deleted from your forked repo.

To see a preview of a branch or tag push you can visit `https://{{github-username}}.github.io/ramp4-pcar4/{{branch-or-tag-name}}`.
You can also see the contents of all your demos by visiting `https://github.com/{{github-username}}/ramp4-pcar4/tree/demo-page`.

For demos to be enabled on your forked repo you'll need to update a few repo settings:

1. Settings -> Pages -> Build and deployment source -> Select GitHub Actions
2. Settings -> Environments -> github-pages -> Deployment branches and tags -> Select No restriction
3. Settings -> Actions -> General -> Actions permissions -> Allow all actions and reusable workflows
4. Settings -> Actions -> General -> Workflow permissions -> Read and write permissions

# Local development

## Project Setup
Expand Down

0 comments on commit c519b33

Please sign in to comment.