forked from ramp4-pcar4/ramp4-pcar4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable builds and demo pages for forked repos
- Loading branch information
1 parent
51f76ec
commit 25c9caa
Showing
11 changed files
with
288 additions
and
293 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
name: Build demo site and deploy to GitHub 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 | ||
with: | ||
path: ramp | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
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 demp-page branch (orphan) if it doesn't exist | ||
run: | | ||
# ramp is already checked out in the previous step, use git there to check if demo-pages exists on origin | ||
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..." | ||
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://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository_owner }}/ramp4-pcar4 | ||
git push -u origin demo-page | ||
echo "Orphan branch 'demo-page' has been created and pushed to origin." | ||
cd ../ | ||
# For simplicity we'll delete the demo-page folder now since it'll be checked out in the next step in all cases | ||
rm -rf demo-page | ||
fi | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: demo-page | ||
path: demo-page | ||
fetch-depth: 0 | ||
|
||
- name: Remove the old demo if it exists and make docs folder | ||
run: | | ||
rm -rf demo-page/${{ github.ref_name }} | ||
# this is the deepest folder we need to create | ||
mkdir -p demo-page/${{ github.ref_name }}/docs/api-tech-docs | ||
# Before building the docs we need to find and replace the version and repo owner references in the raw docs (next two steps). | ||
- 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 repo owner references before docs are built so that the links point to the correct repo | ||
uses: jacobtomlinson/gha-find-replace@v3 | ||
with: | ||
find: '{{repo-owner}}' | ||
replace: ${{ github.repository_owner }} | ||
include: 'ramp/docs/**' | ||
regex: false | ||
|
||
- name: Build the project and generate docs | ||
run: | | ||
cd ramp | ||
npm ci | ||
npm run build | ||
npm run ts-docs:generate | ||
npm run vite-docs:generate | ||
- name: Publish to NPM for tag releases on main repo only | ||
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: Move the built project and docs into the demo-page folder for deployment | ||
run: | | ||
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 | ||
- name: Commit and squash to the demo-page branch | ||
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 origin HEAD --force | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: demo-page | ||
retention-days: 1 | ||
|
||
- name: Setup Pages | ||
uses: actions/configure-pages@v5 | ||
|
||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
name: Clean up demo folders when they no longer exist | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # Runs every day at midnight | ||
workflow_dispatch: # Allows manual trigger from the GitHub website | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: write | ||
pages: write | ||
id-token: write | ||
|
||
jobs: | ||
clean_folders: | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
|
||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: demo-page | ||
|
||
- name: Set up Git | ||
run: | | ||
git config --global user.name "GitHub Action" | ||
git config --global user.email "[email protected]" | ||
- name: Fetch remote branches and tags from origin | ||
run: git fetch origin --prune | ||
|
||
- name: Run cleanup script | ||
run: | | ||
# Get all remote branch names from origin | ||
remote_branches=$(git branch -r | grep -v '\->' | grep "origin/" | sed "s# *origin/##g") | ||
# Get all remote tag names from origin | ||
remote_tags=$(git ls-remote --tags origin | awk -F/ '{print $NF}' | sed 's/\^{}//') | ||
# Combine branches and tags into a single list | ||
remote_refs=$(echo -e "$remote_branches\n$remote_tags") | ||
# Get all folder names in the current directory | ||
local_folders=$(ls -d */ | sed 's#/##') | ||
# Loop through each folder in the current directory | ||
for folder in $local_folders; do | ||
# Check if the folder name exists in the list of remote refs | ||
if ! echo "$remote_refs" | grep -qw "$folder"; then | ||
# If the folder name doesn't exist in the remote refs, delete the folder | ||
echo "Deleting folder: $folder" | ||
rm -rf "$folder" | ||
fi | ||
done | ||
- name: Commit and push changes | ||
id: commit-changes | ||
run: | | ||
git add . | ||
if ! git diff --cached --exit-code > /dev/null; then | ||
git commit -m "Automated folder cleanup" | ||
# Squash the commit history into a single commit | ||
git reset --soft $(git rev-list --max-parents=0 HEAD) | ||
git commit -m "Automated folder cleanup" | ||
git push -f origin demo-page | ||
# Let the next steps know that changes were made and deployment is needed | ||
echo "changes=true" >> $GITHUB_ENV | ||
else | ||
echo "No changes to commit" | ||
# Let the next steps know that no changes were made and deployment will be skipped | ||
echo "changes=false" >> $GITHUB_ENV | ||
fi | ||
- name: Upload artifact | ||
if: env.changes == 'true' | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: '.' | ||
retention-days: 1 | ||
|
||
- name: Setup Pages | ||
if: env.changes == 'true' | ||
uses: actions/configure-pages@v5 | ||
|
||
- name: Deploy to GitHub Pages | ||
if: env.changes == 'true' | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: PR Commenter | ||
|
||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
jobs: | ||
comment-on-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Comment on the PR | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
Your demo site is ready! 🚀 | ||
Enhanced Testing: | ||
Samples: https://${{github.event.pull_request.user.login}}.github.io/ramp4-pcar4/${{github.head_ref}}/demos/enhanced-samples.html | ||
Catalogue: https://${{github.event.pull_request.user.login}}.github.io/ramp4-pcar4/${{github.head_ref}}/demos/enhanced-all.html | ||
Legacy Testing: | ||
Main: https://${{github.event.pull_request.user.login}}.github.io/ramp4-pcar4/${{github.head_ref}}/ | ||
Catalogue: https://${{github.event.pull_request.user.login}}.github.io/ramp4-pcar4/${{github.head_ref}}/demos/index-all.html | ||
Samples: https://${{github.event.pull_request.user.login}}.github.io/ramp4-pcar4/${{github.head_ref}}/demos/index-samples.html |
Oops, something went wrong.