From 7e01486829aecd32762d84dc131f1383310100b4 Mon Sep 17 00:00:00 2001 From: Hans Morbach <6433480+hansmorb@users.noreply.github.com> Date: Thu, 30 Jan 2025 19:58:09 +0100 Subject: [PATCH] Add PR Zip (#1745) * added PR upload action * clean slate setting to fix uploading issues * automatically fill out version comment with branch and commit sha upon build * get branch info from github, not from git * added ability to test plugin in WP playground --------- Co-authored-by: Chris <105302830+datengraben@users.noreply.github.com> --- .github/actions/build-plugin/action.yml | 19 ++++++++- .github/workflows/zip-pr.yml | 52 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/zip-pr.yml diff --git a/.github/actions/build-plugin/action.yml b/.github/actions/build-plugin/action.yml index 4df6d5df0..96f35d6f9 100644 --- a/.github/actions/build-plugin/action.yml +++ b/.github/actions/build-plugin/action.yml @@ -1,6 +1,15 @@ name: 'Build Plugin' description: 'Builds plugin into ./build/commonsbooking' +inputs: + generate_zip: + description: 'Set to true, if a zip file should be generated in the root of the plugin folder' + required: false + default: 'false' + options: + - true + - false + runs: using: "composite" steps: @@ -30,6 +39,12 @@ runs: - run: npm ci --legacy-peer-deps --include=dev shell: bash - - name: Run build script + - name: Run build script (skip zip generation) + if: ${{ inputs.generate_zip == 'false' }} run: bin/build-zip.sh --skip-zip - shell: bash \ No newline at end of file + shell: bash + + - name: Run build script and generate zip file + if: ${{ inputs.generate_zip == 'true' }} + run: bin/build-zip.sh + shell: bash diff --git a/.github/workflows/zip-pr.yml b/.github/workflows/zip-pr.yml new file mode 100644 index 000000000..103ed6df5 --- /dev/null +++ b/.github/workflows/zip-pr.yml @@ -0,0 +1,52 @@ +name: Build zip from PR +on: + pull_request: + branches: + - 'master' + +jobs: + zip-pr: + runs-on: ubuntu-20.04 + steps: + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Important for getting full commit history + + - name: Update Version Comment + run: | + sed -i "s|define('COMMONSBOOKING_VERSION_COMMENT',.*|define('COMMONSBOOKING_VERSION_COMMENT', '${{ github.head_ref }} at ${{ github.event.pull_request.head.sha}}');|" commonsbooking.php + - uses: ./.github/actions/build-plugin + with: + generate_zip: 'true' + + - name: Upload zip + uses: SamKirkland/FTP-Deploy-Action@v4.3.5 + with: + exclude: | + ** + ! commonsbooking.zip + server: ${{ secrets.CBZIPUPLOAD_SERVER }} + username: ${{ secrets.CBZIPUPLOAD_USER }} + password: ${{ secrets.CBZIPUPLOAD_KEY }} + server-dir: ${{ github.event.number }}/ + dangerous-clean-slate: true + protocol: ftps + + - name: Find Comment + uses: peter-evans/find-comment@v3 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Download built plugin zip + + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + [Download built plugin zip](https://builds.commonsbooking.org/${{ github.event.number }}/commonsbooking.zip) + [Test Plugin in Wordpress Playground](https://playground.wordpress.net/#{%22steps%22:[{%22step%22:%22installPlugin%22,%22pluginData%22:{%22resource%22:%22url%22,%22url%22:%22https://builds.commonsbooking.org/${{ github.event.number }}/commonsbooking.zip%22}},{%22step%22:%22importWxr%22,%22file%22:{%22resource%22:%22url%22,%22url%22:%22https://raw.githubusercontent.com/wielebenwir/commonsbooking/refs/heads/master/tests/cypress/wordpress-files/content-example.xml%22}}],%22preferredVersions%22:{%22php%22:%227.4%22,%22wp%22:%22latest%22},%22login%22:true}) + edit-mode: replace