Skip to content

Commit 8aa2de5

Browse files
Merge pull request #11 from StoppedwummPython/main
Sync
2 parents 1089c90 + 01fab6d commit 8aa2de5

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

.github/workflows/Build.yml

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: Build and Deploy to Static Repo
22
on:
3+
# Trigger only on pushes to these specific branches.
4+
# Do NOT add 'pull_request' here.
35
push:
46
branches:
57
- main
8+
- stoppeds-fun-stuff
9+
610
jobs:
7-
# This job builds the client files and uploads them as an artifact
811
build:
912
runs-on: ubuntu-latest
1013
steps:
@@ -37,84 +40,91 @@ jobs:
3740
name: eaglercraft-clients
3841
path: out/
3942

40-
# This job downloads the artifacts and deploys them to the external repository
4143
deploy:
42-
# This job runs only after the 'build' job has successfully completed
4344
needs: build
44-
# This job should only run on a push to the main branch, not on pull requests
45-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
45+
# STICT CHECK: Only run if it is a PUSH event AND (is main OR is stoppeds-fun-stuff)
46+
# This prevents PRs from ever running this job.
47+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/stoppeds-fun-stuff')
4648
runs-on: ubuntu-latest
4749
steps:
4850
- name: Download Artifacts
4951
uses: actions/download-artifact@v4
5052
with:
5153
name: eaglercraft-clients
5254
path: out/
55+
5356
- name: Install Butler
5457
run: |
55-
# -L follows redirects
56-
# -O specifies output name
5758
curl -L -o butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default
5859
unzip butler.zip
59-
# GNU unzip tends to not set the executable bit even though it's set in the .zip
6060
chmod +x butler
61-
# just a sanity check run (and also helpful in case you're sharing CI logs)
6261
./butler -V
63-
echo $PAT # just a test
6462
env:
65-
# This makes the PAT available within the script.
6663
PAT: ${{ secrets.PAT }}
6764

6865
- name: Deploy Manually using Git and LFS
6966
run: |
7067
# 1. Configure Git LFS
71-
# This command initializes the Git LFS client in the runner environment.
7268
git lfs install
7369
74-
# 2. Clone the destination repository using a Personal Access Token (PAT)
75-
# We clone it into a new directory named 'deploy_repo'.
70+
# 2. Clone the destination repository
7671
echo "Cloning destination repository..."
7772
git clone "https://x-access-token:${{ secrets.PAT }}@github.com/StoppedwummPython/eageag.git" deploy_repo
7873
7974
# 3. Navigate into the cloned repository
8075
cd deploy_repo
81-
82-
# 4. Clean the working directory
83-
# This command removes all existing files and folders from the repository.
84-
echo "Cleaning out old files..."
85-
git rm -rf eaglercraft_js_client eaglercraft_wasm_client || true
86-
87-
# 5. Copy the new files from the build artifact
88-
echo "Copying new website files..."
89-
cp -r ../out/* .
90-
91-
# 6. Create .nojekyll file to disable Jekyll processing
92-
# This tells GitHub Pages to treat the repository as a pure static site.
93-
echo "Creating .nojekyll file..."
94-
touch .nojekyll
95-
96-
# 7. Configure Git user for the commit
76+
77+
# 4. Configure Git user
9778
git config user.name "github-actions[bot]"
9879
git config user.email "github-actions[bot]@users.noreply.github.com"
9980
100-
# 8. Add, commit, and push the changes
81+
# 5. Logic to determine where to deploy based on the branch name
82+
CURRENT_BRANCH="${{ github.ref_name }}"
83+
84+
if [ "$CURRENT_BRANCH" == "main" ]; then
85+
echo "--- DEPLOYING MAIN TO ROOT ---"
86+
87+
# PRESERVE snapshit and PRESERVE index.html (unless overwritten)
88+
echo "Cleaning specific client folders only..."
89+
rm -rf eaglercraft_js_client eaglercraft_wasm_client
90+
91+
echo "Copying new files to root..."
92+
cp -r ../out/* .
93+
94+
touch .nojekyll
95+
96+
elif [ "$CURRENT_BRANCH" == "stoppeds-fun-stuff" ]; then
97+
echo "--- DEPLOYING TO SNAPSHIT DIRECTORY ---"
98+
99+
# Ensure directory exists
100+
mkdir -p snapshit
101+
102+
# Clean INSIDE snapshit only
103+
rm -rf snapshit/*
104+
105+
# Copy new files into the subdirectory
106+
echo "Copying files to snapshit/..."
107+
cp -r ../out/* snapshit/
108+
109+
else
110+
# Safety catch: If we somehow got here on a different branch, fail.
111+
echo "Error: Branch $CURRENT_BRANCH is not authorized for deployment."
112+
exit 1
113+
fi
114+
115+
# 6. Add, commit, and push
101116
echo "Preparing to commit..."
102117
103-
# Add all new files to the staging area, including the new .nojekyll file.
104118
git add .
105119
106-
# Check if there are any changes to commit.
107120
if git diff --staged --quiet; then
108121
echo "No changes detected. Nothing to commit."
109122
else
110123
echo "Committing changes..."
111-
git commit -m "Automated deployment of static files | Source: ${{ github.sha }}"
124+
git commit -m "Deploy from branch $CURRENT_BRANCH | Source: ${{ github.sha }}"
112125
113126
echo "Pushing to remote..."
114-
# The push command will upload LFS files and commit the changes.
115-
git push -u origin main
127+
git push origin main
116128
fi
117129
env:
118-
# This makes the PAT available within the script.
119130
PAT: ${{ secrets.PAT }}
120-

0 commit comments

Comments
 (0)