Skip to content

Commit

Permalink
Cleanup Github action to remove old contents of GitHubPages branch
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-tanner committed Nov 12, 2024
1 parent b0e8e6b commit 30f2521
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/sync-wwwroot-to-GitHubPages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main # Trigger on changes to the main branch
workflow_dispatch: # Allows manual trigger of the workflow

env:
TARGET_BRANCH: GitHubPages # Branch to push to
Expand All @@ -19,37 +20,38 @@ jobs:
steps:
# Step 1: Check out the code
- name: Checkout main branch
uses: actions/checkout@v4 # Update to the latest version to avoid Node.js deprecation warning
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history so we can switch branches later

# Step 2: Copy subfolder to a temporary directory
- name: Copy Subfolder
run: |
mkdir -p subfolder_copy
cp -R $SUBFOLDER_PATH/* subfolder_copy/ # Use the variable for the subfolder path
cp -R $SUBFOLDER_PATH/* subfolder_copy/ # Recursive copy of files and folders
# Step 3: Checkout the target branch
- name: Checkout target branch
# Step 3: Checkout and clear the target branch
- name: Checkout and clear target branch
run: |
git config user.name "$GIT_USER_NAME"
git config user.email "$GIT_USER_EMAIL"
git checkout -B $TARGET_BRANCH # Use the target branch variable
git checkout -B $TARGET_BRANCH # Checkout the target branch
rm -rf * # Remove all files and folders in the target branch
# Step 4: Copy the content to the root of the target branch
# Step 4: Move Subfolder contents to the target branch
- name: Move Subfolder to Target Branch
run: |
cp -R subfolder_copy/* . # Copies the content of subfolder_copy to the root of the target branch
cp -R subfolder_copy/* . # Copy all files and subfolders from the subfolder_copy directory
rm -rf subfolder_copy # Clean up the temporary directory
# Step 5: Generate Commit Message with Date-Time
- name: Generate Commit Message with Date-Time
id: commit_message # Set an ID to reference this step's outputs
id: commit_message
run: echo "COMMIT_MESSAGE=$BASE_COMMIT_MESSAGE $(date +"%Y-%m-%d %H:%M:%S")" >> $GITHUB_ENV

# Step 6: Commit and push changes
- name: Commit changes
run: |
git add .
git commit -m "$COMMIT_MESSAGE" # Use the dynamic commit message
git push origin $TARGET_BRANCH # Push to the target branch using the variable
git commit -m "$COMMIT_MESSAGE"
git push -f origin $TARGET_BRANCH # Push to the target branch, using -f to force overwrite

0 comments on commit 30f2521

Please sign in to comment.