|
| 1 | +name: Deploy to playground.wordpress.net |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + # Deploy the website every day at 9am and 6pm UTC |
| 6 | + # TODO: Uncomment when ready for regular deployment |
| 7 | + # schedule: |
| 8 | + # - cron: '0 9,18 * * *' |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: website-deployment |
| 12 | + # TODO: Enable cancel-in-progress once we are deploying per commit? |
| 13 | + #cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + build_and_deploy: |
| 17 | + # Only run this workflow from the trunk branch and when it's triggered by another workflow OR a Playground maintainer |
| 18 | + # TODO: Uncomment guards before merge |
| 19 | + # if: > |
| 20 | + # github.ref == 'refs/heads/trunk' && ( |
| 21 | + # github.event_name == 'workflow_run' || |
| 22 | + # github.event_name == 'workflow_dispatch' || |
| 23 | + # github.actor == 'adamziel' || |
| 24 | + # github.actor == 'dmsnell' || |
| 25 | + # github.actor == 'bgrgicak' || |
| 26 | + # github.actor == 'brandonpayton' || |
| 27 | + # github.actor == 'zaerl' |
| 28 | + # ) |
| 29 | + |
| 30 | + # Specify runner + deployment step |
| 31 | + runs-on: ubuntu-latest |
| 32 | + environment: |
| 33 | + name: playground-wordpress-net-wp-cloud |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + submodules: true |
| 38 | + - uses: ./.github/actions/prepare-playground |
| 39 | + - run: npm run build |
| 40 | + - run: tar -czf wasm-wordpress-net.tar.gz dist/packages/playground/wasm-wordpress-net |
| 41 | + # Store dist/packages/artifacts/wasm-wordpress-net as a build artifact |
| 42 | + - uses: actions/upload-artifact@v4 |
| 43 | + with: |
| 44 | + name: playground-website |
| 45 | + path: wasm-wordpress-net.tar.gz |
| 46 | + # The artifact only becomes available after this workflow wraps up, so let's wrap. |
| 47 | + # This artifact enables the download of a pre-built package and hosting of one's own playground instance. |
| 48 | + |
| 49 | + - name: Deploy to playground.wordpress.net |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + mkdir -p ~/.ssh |
| 53 | + echo "${{ secrets.DEPLOY_WEBSITE_TARGET_HOST_KEY }}" >> ~/.ssh/known_hosts |
| 54 | + echo "${{ secrets.DEPLOY_WEBSITE_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 |
| 55 | + chmod 0600 ~/.ssh/* |
| 56 | +
|
| 57 | + # Website files |
| 58 | + rsync -avz -e "ssh -i ~/.ssh/id_ed25519" --delete \ |
| 59 | + dist/packages/playground/wasm-wordpress-net/ \ |
| 60 | + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/updated-playground-files' |
| 61 | +
|
| 62 | + # Host-specific deployment scripts and server config |
| 63 | + rsync -avz -e "ssh -i ~/.ssh/id_ed25519" --delete \ |
| 64 | + packages/playground/website-deployment/ \ |
| 65 | + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment' |
| 66 | +
|
| 67 | + # Copy MIME types for use with PHP-served files |
| 68 | + rsync -avz -e "ssh -i ~/.ssh/id_ed25519" \ |
| 69 | + packages/php-wasm/universal/src/lib/mime-types.json \ |
| 70 | + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment/' |
| 71 | +
|
| 72 | + # Require A8C proxy for private web app |
| 73 | + ssh -i ~/.ssh/id_ed25519 \ |
| 74 | + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }} \ |
| 75 | + -tt -C 'echo "if ( \"cli\" !== php_sapi_name() && empty( \$_SERVER[\"A8C_PROXIED_REQUEST\"] ) ) { http_response_code( 401 ); echo \"Unauthorized. Please proxy.\"; die(); }" >> ~/website-deployment/custom-redirects.php' |
| 76 | +
|
| 77 | + # Apply update |
| 78 | + ssh -i ~/.ssh/id_ed25519 \ |
| 79 | + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }} \ |
| 80 | + -tt -C '~/website-deployment/apply-update.sh' |
0 commit comments