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.
- Loading branch information
1 parent
55e8770
commit 7e6cdfa
Showing
4 changed files
with
193 additions
and
155 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,101 @@ | ||
# 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: 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 config --global user.email "miles.petrov@ec.gc.ca" | ||
git config --global user.name "Miles Petrov" | ||
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 demo-folder | ||
git --work-tree=demo-folder checkout demo-page -- . | ||
# Modify and commit changes | ||
npm ci | ||
npm run build | ||
mv dist demo-folder/$BRANCH_OR_TAG_NAME | ||
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/* . | ||
rmdir demo-folder | ||
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 | ||
- 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 |
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,92 @@ | ||
name: Clean Folders and Deploy | ||
|
||
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 # Checkout the `demo-page` branch | ||
|
||
- name: Set up Git | ||
run: | | ||
git config --global user.name "GitHub Action" | ||
git config --global user.email "action@github.com" | ||
- 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 | ||
echo "changes=true" >> $GITHUB_ENV | ||
else | ||
echo "No changes to commit" | ||
echo "changes=false" >> $GITHUB_ENV | ||
fi | ||
# Deploy to GitHub Pages if changes were made | ||
- 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 was deleted.
Oops, something went wrong.