|
| 1 | +on: |
| 2 | + push: |
| 3 | + delete: |
| 4 | +name: 🚀 Deploy and cleanup emulator website |
| 5 | +jobs: |
| 6 | + web-deploy: |
| 7 | + name: 🎉 Deploy |
| 8 | + runs-on: ubuntu-latest |
| 9 | + if: github.event_name == 'push' |
| 10 | + steps: |
| 11 | + - name: 🚚 Get latest code |
| 12 | + uses: actions/checkout@v4 |
| 13 | + |
| 14 | + - name: 🔧 Set deployment path |
| 15 | + id: deploy-path |
| 16 | + run: | |
| 17 | + BRANCH_NAME="${{ github.ref_name }}" |
| 18 | + if [ "$BRANCH_NAME" = "main" ]; then |
| 19 | + echo "server_dir=./" >> $GITHUB_OUTPUT |
| 20 | + echo "Deploying main branch to root directory" |
| 21 | + else |
| 22 | + echo "server_dir=./--$BRANCH_NAME/" >> $GITHUB_OUTPUT |
| 23 | + echo "Deploying branch '$BRANCH_NAME' to subfolder '--$BRANCH_NAME/'" |
| 24 | + fi |
| 25 | +
|
| 26 | + - name: 📂 Sync files |
| 27 | + uses: SamKirkland/[email protected] |
| 28 | + with: |
| 29 | + server: ${{ secrets.ftp_server }} |
| 30 | + username: ${{ secrets.ftp_user }} |
| 31 | + password: ${{ secrets.ftp_password }} |
| 32 | + local-dir: ./micropatterns_emulator/ |
| 33 | + server-dir: ${{ steps.deploy-path.outputs.server_dir }} |
| 34 | + |
| 35 | + cleanup-deploy: |
| 36 | + name: 🗑️ Remove branch folder |
| 37 | + runs-on: ubuntu-latest |
| 38 | + if: github.event_name == 'delete' && github.event.ref_type == 'branch' |
| 39 | + steps: |
| 40 | + - name: 🔧 Set cleanup path |
| 41 | + id: cleanup-path |
| 42 | + run: | |
| 43 | + BRANCH_NAME="${{ github.event.ref }}" |
| 44 | + if [ "$BRANCH_NAME" != "main" ]; then |
| 45 | + echo "folder_path=--$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 46 | + echo "should_cleanup=true" >> $GITHUB_OUTPUT |
| 47 | + echo "Will cleanup folder: --$BRANCH_NAME" |
| 48 | + else |
| 49 | + echo "should_cleanup=false" >> $GITHUB_OUTPUT |
| 50 | + echo "Main branch deleted - no cleanup needed" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: 📁 Create temporary empty folder |
| 54 | + if: steps.cleanup-path.outputs.should_cleanup == 'true' |
| 55 | + run: mkdir -p empty-folder |
| 56 | + |
| 57 | + - name: 🗑️ Delete branch folder via FTP |
| 58 | + if: steps.cleanup-path.outputs.should_cleanup == 'true' |
| 59 | + uses: SamKirkland/[email protected] |
| 60 | + with: |
| 61 | + server: ${{ secrets.ftp_server }} |
| 62 | + username: ${{ secrets.ftp_user }} |
| 63 | + password: ${{ secrets.ftp_password }} |
| 64 | + local-dir: ./empty-folder/ |
| 65 | + server-dir: ./micropatterns_emulator/${{ steps.cleanup-path.outputs.folder_path }}/ |
| 66 | + delete: true |
| 67 | + exclude: | |
| 68 | + **/.git* |
| 69 | + **/.git*/** |
0 commit comments