Skip to content

added: git config pull.ff only #8

added: git config pull.ff only

added: git config pull.ff only #8

name: Sync wwwroot to GitHubPages
on:
push:
branches:
- main # Trigger on changes to the main branch
env:
TARGET_BRANCH: GitHubPages # Branch to push to
SUBFOLDER_PATH: Client/wwwroot # Path of the subfolder to copy
GIT_USER_NAME: "github-actions[bot]" # GitHub Actions bot username
GIT_USER_EMAIL: "github-actions[bot]@users.noreply.github.com" # GitHub Actions bot email
BASE_COMMIT_MESSAGE: "Sync subfolder from main branch to GitHubPages" # Base commit message
jobs:
copy-subfolder:
runs-on: ubuntu-latest
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
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 temp_subfolder
cp -R $SUBFOLDER_PATH/* temp_subfolder/ # Use the variable for the subfolder path
# Step 3: Checkout the target branch
- name: Checkout target branch
run: |
git config pull.ff only
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 pull origin $TARGET_BRANCH # Pull the latest changes from the target branch
# Step 4: Copy the content to the root of the target branch
- name: Move Subfolder to Target Branch
run: |
cp -R temp_subfolder/* . # Copies the content of temp_subfolder to the root of the target branch
rm -rf temp_subfolder # 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
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