From 7450fb8cf4b62f31119337b41abdc2d746ab7286 Mon Sep 17 00:00:00 2001 From: L0RD-ZER0 <68327382+L0RD-ZER0@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:38:52 +0530 Subject: [PATCH 1/2] Update CI Workflows --- .github/deploy/addon.sh | 30 +++++++++++++++ .github/workflows/deploy.yml | 40 ++++++++++++++++++++ .github/workflows/perform-lints.yml | 35 +++++++++++++---- .github/workflows/upload-schema-artifact.yml | 6 ++- 4 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 .github/deploy/addon.sh create mode 100644 .github/workflows/deploy.yml diff --git a/.github/deploy/addon.sh b/.github/deploy/addon.sh new file mode 100644 index 0000000..a5eb6cd --- /dev/null +++ b/.github/deploy/addon.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +function setup_wordpress_files() { + # Since it is a plugin deployment, iirc we skip this step + cd "$GITHUB_WORKSPACE" + build_root="$(pwd)" + export build_root +} + +function cleanup_node_modules() { + # Since it is a plugin deployment, iirc we skip this step + cd "$GITHUB_WORKSPACE" + # required to remove development dependencies used for building but not required for runtime + npm ci --omit dev +} + +function main() { + setup_hosts_file + check_branch_in_hosts_file + setup_ssh_access + maybe_install_submodules + maybe_install_node_dep + maybe_run_node_build + setup_wordpress_files + block_emails + cleanup_node_modules + deploy +} + +main diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7a06fe3 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,40 @@ +on: + push: + branches: + - main + - develop + workflow_dispatch: +name: Deploying Headless Server +env: + # Please keep in install-links to avoid npm install errors on the server + build-command: npm i --include-dev --install-links && npm run build:dist +jobs: + deploy: + name: Deploy + runs-on: [ self-hosted, headless ] + concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + steps: + - uses: actions/checkout@v4 + - name: Setup hosts file + run: | + cat < '${{ github.workspace }}/.github/hosts.yml' + ${{ secrets.HOSTS_FILE }} + EOF + - name: Get node version + id: node-version + run: | + cd '${{ github.workspace }}' + NODE_VERSION="$(cat .nvmrc)" + echo "node_version=${NODE_VERSION}" >> "$GITHUB_ENV" + - name: Deploy + uses: rtCamp/action-deploy-wordpress@master + env: + SSH_PRIVATE_KEY: ${{ secrets.ED_DEPLOYMENT_KEY }} + NODE_VERSION: "${{ env.node_version }}" + NODE_BUILD_COMMAND: ${{ env.build-command }} + SSH_USER: ${{ secrets.SSH_USER }} + SSH_HOST: ${{ secrets.SSH_HOST }} + - if: always() + uses: rtCamp/action-cleanup@master diff --git a/.github/workflows/perform-lints.yml b/.github/workflows/perform-lints.yml index 8efc9e6..f31306d 100644 --- a/.github/workflows/perform-lints.yml +++ b/.github/workflows/perform-lints.yml @@ -9,6 +9,7 @@ on: branches: - develop - main + workflow_dispatch: permissions: contents: read @@ -77,7 +78,7 @@ jobs: for file in "$PHP_CHANGED_FILES"; do echo "$file was changed" done - + - name: List all JS changed files if: steps.changed-files.outputs.js_any_changed == 'true' env: @@ -193,9 +194,9 @@ jobs: php: [ '8.2' ] #, '8.1' ] @todo reenable when repo is made public wordpress: [ '6.7' ] #, '6.6' ] include: - - php: '8.2' - wordpress: '6.7' - coverage: 1 + - php: '8.2' + wordpress: '6.7' + coverage: 1 fail-fast: false steps: - name: Checkout @@ -255,8 +256,24 @@ jobs: COVERAGE: ${{ matrix.coverage }} DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG || matrix.debug }} SUITES: "Integration" - # Todo: Add coveralls + codeclimate - + +# - name: Push coverage to Coveralls.io +# if: matrix.coverage == 1 +# uses: coverallsapp/github-action@v2 +# with: +# github-token: ${{ secrets.GITHUB_TOKEN }} +# path-to-lcov: tests/_output/coverage/lcov.info # todo: verify path +# +# - name: Push coverage to CodeClimate +# if: matrix.coverage == 1 +# uses: paambaati/codeclimate-action@v9 +# env: +# CC_TEST_REPORTER_ID: # todo: add code climate reporter id +# with: +# debug: true +# coverageLocations: | +# ${{github.workspace}}/tests/_output/*.xml:clover # todo: verify path + playwright: needs: pre-run if: needs.pre-run.outputs.changed-workflow == 'true' || needs.pre-run.outputs.changed-js == 'true' @@ -296,7 +313,11 @@ jobs: run: npx playwright install --with-deps - name: Start wp-env - run: npm run wp-env -- start + run: | + npm run wp-env -- start + sleep 10 + netstat -nltp + curl -iL http://localhost:8889 - name: Run E2E tests run: npm run test:e2e diff --git a/.github/workflows/upload-schema-artifact.yml b/.github/workflows/upload-schema-artifact.yml index eef20b5..08731bb 100644 --- a/.github/workflows/upload-schema-artifact.yml +++ b/.github/workflows/upload-schema-artifact.yml @@ -4,6 +4,10 @@ on: release: types: [ published ] +permissions: + contents: read + actions: write + jobs: run: runs-on: ubuntu-latest @@ -41,7 +45,7 @@ jobs: - name: Setup GraphQL Schema Linter run: npm install -g graphql-schema-linter@^3.0 graphql@^16 - + - name: Install Node.js dependencies run: npm ci env: From de38b00dd97d95ba6ccf96c1f878a449dc5200fd Mon Sep 17 00:00:00 2001 From: L0RD-ZER0 <68327382+L0RD-ZER0@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:51:24 +0530 Subject: [PATCH 2/2] Reformat addon.sh --- .github/deploy/addon.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/deploy/addon.sh b/.github/deploy/addon.sh index a5eb6cd..58bfe66 100644 --- a/.github/deploy/addon.sh +++ b/.github/deploy/addon.sh @@ -1,21 +1,21 @@ #!/usr/bin/env bash function setup_wordpress_files() { - # Since it is a plugin deployment, iirc we skip this step - cd "$GITHUB_WORKSPACE" - build_root="$(pwd)" - export build_root + # Since it is a plugin deployment, we skip this step + cd "$GITHUB_WORKSPACE" + build_root="$(pwd)" + export build_root } function cleanup_node_modules() { - # Since it is a plugin deployment, iirc we skip this step - cd "$GITHUB_WORKSPACE" - # required to remove development dependencies used for building but not required for runtime - npm ci --omit dev + # Since it is a plugin deployment, we skip this step + cd "$GITHUB_WORKSPACE" + # required to remove development dependencies used for building but not required for runtime + npm ci --omit dev } function main() { - setup_hosts_file + setup_hosts_file check_branch_in_hosts_file setup_ssh_access maybe_install_submodules