|
4 | 4 | pull_request: |
5 | 5 |
|
6 | 6 | jobs: |
7 | | - test: |
| 7 | + playground: |
8 | 8 | runs-on: ubuntu-latest |
9 | 9 | permissions: |
| 10 | + contents: read |
10 | 11 | pull-requests: write |
| 12 | + actions: read |
| 13 | + |
11 | 14 | steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + # Prepare a folder named exactly like the repo as the plugin root. |
| 18 | + # If the repo already has such a folder (common for WP plugins), use it. |
| 19 | + # Otherwise, stage one and copy root files into it (excluding CI junk). |
| 20 | + - name: Prepare plugin folder |
| 21 | + id: prep |
| 22 | + run: | |
| 23 | + set -euxo pipefail |
| 24 | + REPO="${{ github.event.repository.name }}" |
| 25 | + if [ -d "$REPO" ]; then |
| 26 | + # Plugin already lives in a subfolder named like the repo |
| 27 | + echo "PKG_DIR=$REPO" >> "$GITHUB_OUTPUT" |
| 28 | + else |
| 29 | + # Create a clean staging dir to avoid copying into itself |
| 30 | + STAGE="${REPO}-pkg" |
| 31 | + mkdir -p "$STAGE/$REPO" |
| 32 | + rsync -a \ |
| 33 | + --exclude='.git' \ |
| 34 | + --exclude='.github' \ |
| 35 | + --exclude='node_modules' \ |
| 36 | + --exclude="${STAGE}" \ |
| 37 | + ./ "$STAGE/$REPO/" |
| 38 | + echo "PKG_DIR=$STAGE/$REPO" >> "$GITHUB_OUTPUT" |
| 39 | +
|
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Update plugin version with PR number |
| 43 | + run: | |
| 44 | + set -euxo pipefail |
| 45 | + PLUGIN_FILE="${{ steps.prep.outputs.PKG_DIR }}/${{ github.event.repository.name }}.php" |
| 46 | + PR_NUMBER="${{ github.event.number }}" |
| 47 | +
|
| 48 | + # Extract current version and add PR number |
| 49 | + CURRENT_VERSION=$(grep -o "Version:[[:space:]]*[0-9.]*" "$PLUGIN_FILE" | sed 's/Version:[[:space:]]*//') |
| 50 | + NEW_VERSION="${CURRENT_VERSION} - PR ${PR_NUMBER}" |
| 51 | +
|
| 52 | + # Replace the version line |
| 53 | + sed -i "s/Version:[[:space:]]*[0-9.]*/Version: ${NEW_VERSION}/" "$PLUGIN_FILE" |
| 54 | +
|
| 55 | + - name: Prepare blueprint with artifact link |
| 56 | + id: blueprint |
| 57 | + run: | |
| 58 | + set -euxo pipefail |
| 59 | + ARTIFACT_URL="https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip" |
| 60 | +
|
| 61 | + # Use Node.js to parse, modify, and stringify the JSON |
| 62 | + BLUEPRINT=$(node -e " |
| 63 | + const fs = require('fs'); |
| 64 | + const blueprint = JSON.parse(fs.readFileSync('.wordpress-org/blueprints/playground.json', 'utf8')); |
| 65 | + blueprint.plugins = blueprint.plugins.map(plugin => |
| 66 | + plugin === '${{ github.event.repository.name }}' ? '$ARTIFACT_URL' : plugin |
| 67 | + ); |
| 68 | + console.log(JSON.stringify(blueprint)); |
| 69 | + ") |
| 70 | +
|
| 71 | + # Base64 encode the blueprint |
| 72 | + ENCODED_BLUEPRINT=$(echo -n "$BLUEPRINT" | base64 -w 0) |
| 73 | +
|
| 74 | + echo "blueprint=$ENCODED_BLUEPRINT" >> "$GITHUB_OUTPUT" |
| 75 | +
|
| 76 | + # Upload the FOLDER (not a .zip). The artifact service zips it for us, |
| 77 | + # keeping the top-level folder name inside the archive. |
| 78 | + - name: Upload plugin artifact |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: ${{ github.event.repository.name }} |
| 82 | + path: ${{ steps.prep.outputs.PKG_DIR }} |
| 83 | + # Optional: faster uploads for already-compressed assets |
| 84 | + compression-level: 0 |
| 85 | + |
| 86 | + # Comment with a Playground link that installs from the artifact ZIP |
12 | 87 | - uses: mshick/add-pr-comment@v2 |
13 | 88 | with: |
14 | 89 | message: | |
15 | 90 | **Test on Playground** |
16 | | - [Test this pull request on the Playground](https://playground.wordpress.net/?blueprint-url=https%3A%2F%2Fprogressplanner.com%2Fresearch%2Fblueprint-pp.php%3Frepo%3D${{ github.repository }}%26branch%3D${{ github.head_ref }}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/${{ github.sha }}.zip). |
| 91 | + [Test this pull request on the Playground](https://playground.wordpress.net/#${{ steps.blueprint.outputs.blueprint }}) |
| 92 | + or [download the zip](https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/${{ github.event.repository.name }}.zip) |
0 commit comments