From f2bdad2a590d07c905d4c1ba8644340a39b7c954 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:22:12 +0800 Subject: [PATCH 01/11] Create build-zip.yml Introduce CI/CD workflow for on-demand ZIP build using 10up/action-wordpress-plugin-build-zip. This update implements a GitHub Action to automate the creation of a ZIP file for our WordPress plugin when it was run manually on GitHub, GitHub CLI, or the REST API. The ZIP is available for download immediately, facilitating rapid testing and deployment. To optimize storage, the ZIP file is retained for only 24 hours after creation. This ensures our CI/CD pipeline remains efficient and aligned with our development practices. --- .github/workflows/build-zip.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/build-zip.yml diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml new file mode 100644 index 00000000..7f4383c4 --- /dev/null +++ b/.github/workflows/build-zip.yml @@ -0,0 +1,23 @@ +name: Build release zip + +on: + workflow_dispatch + +jobs: + build: + name: Build release zip + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Build plugin # Remove or modify this step as needed + run: | + composer install --no-dev + npm install + npm run build + + - name: Generate zip + uses: 10up/action-wordpress-plugin-build-zip@v1.0.1 + with: + retention-days: 5 # Optional; defaults to 5 From b4eb6f487bb103b595b8bf22c3bbd2818c65c6e6 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:33:45 +0800 Subject: [PATCH 02/11] Fix(ci): build-zip.yml Correct the version tag for 10up/action-wordpress-plugin-build-zip --- .github/workflows/build-zip.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index 7f4383c4..5853b51d 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -18,6 +18,6 @@ jobs: npm run build - name: Generate zip - uses: 10up/action-wordpress-plugin-build-zip@v1.0.1 + uses: 10up/action-wordpress-plugin-build-zip@stable with: retention-days: 5 # Optional; defaults to 5 From e05599044ad17b8a053c38d2a1465442892eec9c Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:43:17 +0800 Subject: [PATCH 03/11] fix(ci): update GitHub Actions to Node.js 20 in build-zip.yml This commit updates the GitHub Actions workflow to use Node.js 20, following the deprecation of Node.js 16. The 'actions/checkout' action has been upgraded to version 3 to ensure compatibility with the new runtime environment. For more details on this transition, please refer to the GitHub Changelog: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/ --- .github/workflows/build-zip.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index 5853b51d..6cf2d21d 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -7,9 +7,10 @@ jobs: build: name: Build release zip runs-on: ubuntu-latest + steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build plugin # Remove or modify this step as needed run: | From 85581d7f12057d7d5bbba3a250269b0a6551d4d2 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:50:57 +0800 Subject: [PATCH 04/11] fix(ci): remove npm commands from build-zip.yml - Eliminated the `npm install` and `npm build` commands from the 'Build plugin' step to streamline the workflow. --- .github/workflows/build-zip.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index 6cf2d21d..fa326737 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -12,11 +12,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Build plugin # Remove or modify this step as needed + - name: Build plugin # modify this step as needed run: | composer install --no-dev - npm install - npm run build - name: Generate zip uses: 10up/action-wordpress-plugin-build-zip@stable From 6bcf19823387d534a07017606e4911bb489bd7c7 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 12:03:58 +0800 Subject: [PATCH 05/11] fix(ci): replace action for upload the archive - Substituted the `10up/action-wordpress-plugin-build-zip` with the `actions/upload-artifact@v4`. --- .github/workflows/build-zip.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index fa326737..3b90bfe8 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -15,8 +15,13 @@ jobs: - name: Build plugin # modify this step as needed run: | composer install --no-dev + composer build wp2static.zip - - name: Generate zip - uses: 10up/action-wordpress-plugin-build-zip@stable + - name: Upload the archive as an artifact + id: upload-plugin-artifact + uses: actions/upload-artifact@v4 with: - retention-days: 5 # Optional; defaults to 5 + name: ${{ github.event.repository.name }} + path: wp2static.zip + + From c8dd888fccc1cb60705e772cb4c3d663582ca1c7 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 12:07:10 +0800 Subject: [PATCH 06/11] fix(ci): change path for upload-artifact in build-zip.yml --- .github/workflows/build-zip.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index 3b90bfe8..cb4b7158 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -22,6 +22,6 @@ jobs: uses: actions/upload-artifact@v4 with: name: ${{ github.event.repository.name }} - path: wp2static.zip + path: wp2static From 07936d385f81b36d8c417c921e90fcf6b4b6ac00 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 12:10:00 +0800 Subject: [PATCH 07/11] fix(ci): change path for upload-archive action in build-zip.yml --- .github/workflows/build-zip.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index cb4b7158..ac3bac4b 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -22,6 +22,6 @@ jobs: uses: actions/upload-artifact@v4 with: name: ${{ github.event.repository.name }} - path: wp2static + path: $HOME/Downloads From 7712e935743b4ac8717e84863b0a587c3081cff6 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 13:33:33 +0800 Subject: [PATCH 08/11] Update build-zip.yml Copy bash commands from `tools/build_release.sh` --- .github/workflows/build-zip.yml | 35 ++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index ac3bac4b..48e97282 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -14,14 +14,43 @@ jobs: - name: Build plugin # modify this step as needed run: | - composer install --no-dev - composer build wp2static.zip + # run script from project root + EXEC_DIR=$(pwd) + + TMP_DIR="$EXEC_DIR/plugintmp" + rm -Rf "$TMP_DIR" + mkdir -p "$TMP_DIR" + + rm -Rf "$TMP_DIR/wp2static" + mkdir "$TMP_DIR/wp2static" + + # clear dev dependencies + rm -Rf "$EXEC_DIR/vendor/*" + # load prod deps and optimize loader + composer install --quiet --no-dev --optimize-autoloader + + # cp all required sources to build dir + cp -r "$EXEC_DIR"/src "$TMP_DIR"/wp2static/ + cp -r "$EXEC_DIR"/vendor "$TMP_DIR"/wp2static/ + cp -r "$EXEC_DIR"/views "$TMP_DIR"/wp2static/ + cp -r "$EXEC_DIR"/css "$TMP_DIR"/wp2static/ + cp -r "$EXEC_DIR"/js "$TMP_DIR"/wp2static/ + cp -r "$EXEC_DIR"/*.php "$TMP_DIR"/wp2static/ + + cd "$TMP_DIR" || exit + + # tidy permissions + find . -type d -exec chmod 755 {} \; + find . -type f -exec chmod 644 {} \; + + zip --quiet -r -9 "./$1.zip" ./wp2static + shell: bash - name: Upload the archive as an artifact id: upload-plugin-artifact uses: actions/upload-artifact@v4 with: name: ${{ github.event.repository.name }} - path: $HOME/Downloads + path: $$TMP_DIR From 3bfc17c9a4ee3e207756d2ac4f6808dfd47e1ecb Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 13:36:28 +0800 Subject: [PATCH 09/11] fix path for upload archive --- .github/workflows/build-zip.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index 48e97282..e15a7f09 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -51,6 +51,6 @@ jobs: uses: actions/upload-artifact@v4 with: name: ${{ github.event.repository.name }} - path: $$TMP_DIR + path: plugintmp From 51f316c1aa79f96a32f2e9a48f3abbcd669b7140 Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 13:39:22 +0800 Subject: [PATCH 10/11] Fix archive file name --- .github/workflows/build-zip.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index e15a7f09..92a75783 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -43,7 +43,7 @@ jobs: find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; - zip --quiet -r -9 "./$1.zip" ./wp2static + zip --quiet -r -9 "./wp2static.zip" ./wp2static shell: bash - name: Upload the archive as an artifact @@ -51,6 +51,6 @@ jobs: uses: actions/upload-artifact@v4 with: name: ${{ github.event.repository.name }} - path: plugintmp + path: plugintmp/wp2static.zip From ce257c4dd5f9000a1b43c4103f1d2bacb753545b Mon Sep 17 00:00:00 2001 From: "Chris K.Y. FUNG" <8746768+chriskyfung@users.noreply.github.com> Date: Sun, 28 Apr 2024 13:41:57 +0800 Subject: [PATCH 11/11] Drop the duplicated zip operation --- .github/workflows/build-zip.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-zip.yml b/.github/workflows/build-zip.yml index 92a75783..2c0c0a91 100644 --- a/.github/workflows/build-zip.yml +++ b/.github/workflows/build-zip.yml @@ -42,8 +42,6 @@ jobs: # tidy permissions find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; - - zip --quiet -r -9 "./wp2static.zip" ./wp2static shell: bash - name: Upload the archive as an artifact @@ -51,6 +49,6 @@ jobs: uses: actions/upload-artifact@v4 with: name: ${{ github.event.repository.name }} - path: plugintmp/wp2static.zip + path: plugintmp/wp2static