diff --git a/.github/workflows/build-website.yml b/.github/workflows/build-website.yml index a643389c7d..62aea15f10 100644 --- a/.github/workflows/build-website.yml +++ b/.github/workflows/build-website.yml @@ -6,6 +6,11 @@ on: schedule: - cron: '0 9,18 * * *' +concurrency: + group: website-deployment + # TODO: Enable cancel-in-progress once we are deploying per commit? + #cancel-in-progress: true + jobs: build_and_deploy: # Only run this workflow from the trunk branch and when it's triggered by another workflow OR dmsnell OR adamziel @@ -22,16 +27,36 @@ jobs: # Specify runner + deployment step runs-on: ubuntu-latest environment: - name: playground-wordpress-net + name: playground-wordpress-net-wp-cloud steps: - uses: actions/checkout@v3 - uses: ./.github/actions/prepare-playground - run: npm run build - - run: tar -czf wasm-wordpress-net.tar.gz dist/packages/playground/wasm-wordpress-net - # Store dist/packages/artifacts/wasm-wordpress-net as a build artifact - - uses: actions/upload-artifact@v2 - with: - name: playground-website - path: wasm-wordpress-net.tar.gz - # The artifact only becomes available after this workflow wraps up, so let's wrap. - # The deploy-website.yml workflow will pick up the artifact and deploy it. + + - name: Deploy to playground.wordpress.net + shell: bash + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_WEBSITE_TARGET_HOST_KEY }}" >> ~/.ssh/known_hosts + echo "${{ secrets.DEPLOY_WEBSITE_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 + chmod 0600 ~/.ssh/* + + # Website files + rsync -avz -e "ssh -i ~/.ssh/id_ed25519" --delete \ + dist/packages/playground/wasm-wordpress-net/ \ + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/updated-playground-files' + + # Host-specific deployment scripts and server config + rsync -avz -e "ssh -i ~/.ssh/id_ed25519" --delete \ + packages/playground/website-deployment/ \ + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment' + + # Copy MIME types for use with PHP-served files + scp -i ~/.ssh/id_ed25519 \ + packages/php-wasm/universal/src/lib/mime-types.json \ + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment/' + + # Apply update + ssh -i ~/.ssh/id_ed25519 \ + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }} \ + -tt -C '~/website-deployment/apply-update.sh' diff --git a/.github/workflows/deploy-website-next.yml b/.github/workflows/deploy-website-next.yml deleted file mode 100644 index a93f5bdbef..0000000000 --- a/.github/workflows/deploy-website-next.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Finish deploying to playground.wordpress.net (don't use manually) -# Sorry, the previous job just built it and uploaded it to GitHub - -on: - workflow_run: - workflows: [Deploy to playground.wordpress.net] - types: - - completed -jobs: - deploy_to_wp_cloud: - # Only run this workflow from the trunk branch and when it's triggered by another workflow OR certain maintainers - if: > - github.ref == 'refs/heads/trunk' && ( - github.event.workflow_run.conclusion == 'success' || - github.actor == 'adamziel' || - github.actor == 'dmsnell' || - github.actor == 'bgrgicak' || - github.actor == 'brandonpayton' - ) - - # Specify runner + deployment step - runs-on: ubuntu-latest - environment: - name: playground-wordpress-net-wp-cloud - steps: - # TODO: Remove this unnecessary checkout when we merge this into the website build workflow - - uses: actions/checkout@v4 - with: - sparse-checkout: | - packages/php-wasm/universal/src/lib/mime-types.json - packages/playground/website-deployment - - name: Wait for latest build artifact - shell: bash - # Sleep to give the GitHub API time to register the artifact, - # otherwise the artifact will not be available when the webhook is called - run: | - while true; do - API_HASH=$(curl 'https://api.github.com/repos/wordpress/wordpress-playground/actions/artifacts?name=playground-website&per_page=2' \ - | jq -r '.artifacts[0].workflow_run.head_sha') - if [ "$API_HASH" = "$GITHUB_SHA" ]; then - break; - fi; - echo "$API_HASH was not $GITHUB_SHA, waiting 10 seconds..."; - sleep 10; - done; - - name: Deploy to playground.wordpress.net - shell: bash - run: | - ZIP_URL=$( - curl -L -s -S \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/wordpress/wordpress-playground/actions/artifacts\?name\=playground-website\&per_page\=1 \ - | jq -r '.artifacts[0].archive_download_url' - ) - - curl -L -s -S \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -o playground-website.zip \ - "$ZIP_URL" - - unzip playground-website.zip - tar -xzf wasm-wordpress-net.tar.gz - mv dist/packages/playground/wasm-wordpress-net/ playground-website/ - - mkdir -p ~/.ssh - echo "${{ secrets.DEPLOY_WEBSITE_TARGET_HOST_KEY }}" >> ~/.ssh/known_hosts - echo "${{ secrets.DEPLOY_WEBSITE_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 - chmod 0600 ~/.ssh/* - - # Website files - rsync -avz -e "ssh -i ~/.ssh/id_ed25519" --delete \ - playground-website/ \ - ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/updated-playground-files' - - # Host-specific deployment scripts and server config - rsync -avz -e "ssh -i ~/.ssh/id_ed25519" --delete \ - packages/playground/website-deployment/ \ - ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment' - - # Copy MIME types for use with PHP-served files - scp -i ~/.ssh/id_ed25519 \ - packages/php-wasm/universal/src/lib/mime-types.json \ - ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment/' - - # Apply update - ssh -i ~/.ssh/id_ed25519 \ - ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }} \ - -tt -C '~/website-deployment/apply-update.sh'