Skip to content
Merged

Sync #11

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 48 additions & 38 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Build and Deploy to Static Repo
on:
# Trigger only on pushes to these specific branches.
# Do NOT add 'pull_request' here.
push:
branches:
- main
- stoppeds-fun-stuff

jobs:
# This job builds the client files and uploads them as an artifact
build:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -37,84 +40,91 @@ jobs:
name: eaglercraft-clients
path: out/

# This job downloads the artifacts and deploys them to the external repository
deploy:
# This job runs only after the 'build' job has successfully completed
needs: build
# This job should only run on a push to the main branch, not on pull requests
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# STICT CHECK: Only run if it is a PUSH event AND (is main OR is stoppeds-fun-stuff)
# This prevents PRs from ever running this job.
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/stoppeds-fun-stuff')
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: eaglercraft-clients
path: out/

- name: Install Butler
run: |
# -L follows redirects
# -O specifies output name
curl -L -o butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default
unzip butler.zip
# GNU unzip tends to not set the executable bit even though it's set in the .zip
chmod +x butler
# just a sanity check run (and also helpful in case you're sharing CI logs)
./butler -V
echo $PAT # just a test
env:
# This makes the PAT available within the script.
PAT: ${{ secrets.PAT }}

- name: Deploy Manually using Git and LFS
run: |
# 1. Configure Git LFS
# This command initializes the Git LFS client in the runner environment.
git lfs install

# 2. Clone the destination repository using a Personal Access Token (PAT)
# We clone it into a new directory named 'deploy_repo'.
# 2. Clone the destination repository
echo "Cloning destination repository..."
git clone "https://x-access-token:${{ secrets.PAT }}@github.com/StoppedwummPython/eageag.git" deploy_repo

# 3. Navigate into the cloned repository
cd deploy_repo

# 4. Clean the working directory
# This command removes all existing files and folders from the repository.
echo "Cleaning out old files..."
git rm -rf eaglercraft_js_client eaglercraft_wasm_client || true

# 5. Copy the new files from the build artifact
echo "Copying new website files..."
cp -r ../out/* .

# 6. Create .nojekyll file to disable Jekyll processing
# This tells GitHub Pages to treat the repository as a pure static site.
echo "Creating .nojekyll file..."
touch .nojekyll

# 7. Configure Git user for the commit

# 4. Configure Git user
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# 8. Add, commit, and push the changes
# 5. Logic to determine where to deploy based on the branch name
CURRENT_BRANCH="${{ github.ref_name }}"

if [ "$CURRENT_BRANCH" == "main" ]; then
echo "--- DEPLOYING MAIN TO ROOT ---"

# PRESERVE snapshit and PRESERVE index.html (unless overwritten)
echo "Cleaning specific client folders only..."
rm -rf eaglercraft_js_client eaglercraft_wasm_client

echo "Copying new files to root..."
cp -r ../out/* .

touch .nojekyll

elif [ "$CURRENT_BRANCH" == "stoppeds-fun-stuff" ]; then
echo "--- DEPLOYING TO SNAPSHIT DIRECTORY ---"

# Ensure directory exists
mkdir -p snapshit

# Clean INSIDE snapshit only
rm -rf snapshit/*

# Copy new files into the subdirectory
echo "Copying files to snapshit/..."
cp -r ../out/* snapshit/

else
# Safety catch: If we somehow got here on a different branch, fail.
echo "Error: Branch $CURRENT_BRANCH is not authorized for deployment."
exit 1
fi

# 6. Add, commit, and push
echo "Preparing to commit..."

# Add all new files to the staging area, including the new .nojekyll file.
git add .

# Check if there are any changes to commit.
if git diff --staged --quiet; then
echo "No changes detected. Nothing to commit."
else
echo "Committing changes..."
git commit -m "Automated deployment of static files | Source: ${{ github.sha }}"
git commit -m "Deploy from branch $CURRENT_BRANCH | Source: ${{ github.sha }}"

echo "Pushing to remote..."
# The push command will upload LFS files and commit the changes.
git push -u origin main
git push origin main
fi
env:
# This makes the PAT available within the script.
PAT: ${{ secrets.PAT }}