|
1 | 1 | name: Build and Deploy to Static Repo |
2 | 2 | on: |
| 3 | + # Trigger only on pushes to these specific branches. |
| 4 | + # Do NOT add 'pull_request' here. |
3 | 5 | push: |
4 | 6 | branches: |
5 | 7 | - main |
| 8 | + - stoppeds-fun-stuff |
| 9 | + |
6 | 10 | jobs: |
7 | | - # This job builds the client files and uploads them as an artifact |
8 | 11 | build: |
9 | 12 | runs-on: ubuntu-latest |
10 | 13 | steps: |
@@ -37,84 +40,91 @@ jobs: |
37 | 40 | name: eaglercraft-clients |
38 | 41 | path: out/ |
39 | 42 |
|
40 | | - # This job downloads the artifacts and deploys them to the external repository |
41 | 43 | deploy: |
42 | | - # This job runs only after the 'build' job has successfully completed |
43 | 44 | 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') |
46 | 48 | runs-on: ubuntu-latest |
47 | 49 | steps: |
48 | 50 | - name: Download Artifacts |
49 | 51 | uses: actions/download-artifact@v4 |
50 | 52 | with: |
51 | 53 | name: eaglercraft-clients |
52 | 54 | path: out/ |
| 55 | + |
53 | 56 | - name: Install Butler |
54 | 57 | run: | |
55 | | - # -L follows redirects |
56 | | - # -O specifies output name |
57 | 58 | curl -L -o butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default |
58 | 59 | unzip butler.zip |
59 | | - # GNU unzip tends to not set the executable bit even though it's set in the .zip |
60 | 60 | chmod +x butler |
61 | | - # just a sanity check run (and also helpful in case you're sharing CI logs) |
62 | 61 | ./butler -V |
63 | | - echo $PAT # just a test |
64 | 62 | env: |
65 | | - # This makes the PAT available within the script. |
66 | 63 | PAT: ${{ secrets.PAT }} |
67 | 64 |
|
68 | 65 | - name: Deploy Manually using Git and LFS |
69 | 66 | run: | |
70 | 67 | # 1. Configure Git LFS |
71 | | - # This command initializes the Git LFS client in the runner environment. |
72 | 68 | git lfs install |
73 | 69 |
|
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 |
76 | 71 | echo "Cloning destination repository..." |
77 | 72 | git clone "https://x-access-token:${{ secrets.PAT }}@github.com/StoppedwummPython/eageag.git" deploy_repo |
78 | 73 |
|
79 | 74 | # 3. Navigate into the cloned repository |
80 | 75 | 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 |
97 | 78 | git config user.name "github-actions[bot]" |
98 | 79 | git config user.email "github-actions[bot]@users.noreply.github.com" |
99 | 80 |
|
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 |
101 | 116 | echo "Preparing to commit..." |
102 | 117 | |
103 | | - # Add all new files to the staging area, including the new .nojekyll file. |
104 | 118 | git add . |
105 | 119 |
|
106 | | - # Check if there are any changes to commit. |
107 | 120 | if git diff --staged --quiet; then |
108 | 121 | echo "No changes detected. Nothing to commit." |
109 | 122 | else |
110 | 123 | 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 }}" |
112 | 125 |
|
113 | 126 | 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 |
116 | 128 | fi |
117 | 129 | env: |
118 | | - # This makes the PAT available within the script. |
119 | 130 | PAT: ${{ secrets.PAT }} |
120 | | - |
|
0 commit comments