From d3e544d785e3f25997774971e9eeacc144afb909 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Thu, 30 Nov 2023 18:24:11 +0800 Subject: [PATCH 1/2] Add a new workflow to GitHub Actions for deleting the test build of Custom GitHub actions. --- .../github-actions-delete-test-build.yml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/github-actions-delete-test-build.yml diff --git a/.github/workflows/github-actions-delete-test-build.yml b/.github/workflows/github-actions-delete-test-build.yml new file mode 100644 index 00000000..44af5dfd --- /dev/null +++ b/.github/workflows/github-actions-delete-test-build.yml @@ -0,0 +1,33 @@ +name: GitHub Actions - Delete Test Build + +on: + delete: + +jobs: + DeleteTestBuild: + name: Delete Test Build + runs-on: ubuntu-latest + if: github.event.ref_type == 'branch' + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: trunk + + - name: Delete test build branch + run: | + BRANCH_NAME="${{ github.event.ref }}-test-build" + REMOTE_BRANCH_NAME="origin/${BRANCH_NAME}" + + git fetch --prune --no-tags --depth=1 origin + + # Check if the test build branch exists. + if [ -n "$(git branch --list --remote "$REMOTE_BRANCH_NAME")" ]; then + AUTHOR_INFO=$(git show --no-patch --pretty=format:"%an %ae" "${REMOTE_BRANCH_NAME}") + + # Check if the author of the last commit is the github-actions bot account. + # https://api.github.com/users/github-actions%5Bbot%5D + if [[ "$AUTHOR_INFO" == 'github-actions[bot] 41898282+github-actions[bot]@users.noreply.github.com' ]]; then + git push -d origin "$BRANCH_NAME" + fi + fi From 525805b90e109db0a693f609670e9f2e9cdcf649 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Thu, 30 Nov 2023 18:25:47 +0800 Subject: [PATCH 2/2] Update README for the test build. --- packages/github-actions/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/github-actions/README.md b/packages/github-actions/README.md index b24887d2..dae3d7f2 100644 --- a/packages/github-actions/README.md +++ b/packages/github-actions/README.md @@ -76,8 +76,9 @@ Create a test build on the given branch and commit it to a separate branch with 1. Manually run the workflow with the target branch. 1. Wait for the triggered workflow run to complete. 1. View the summary of the workflow run to use the test build. -1. Take the branch name `add/my-action` and action path `greet-visitor` as an example. After a test build is created, it should be able to test the custom action by `woocommerce/grow/greet-visitor@add/my-action-test-build` -1. Delete the test branch once it is no longer needed. +1. Take the branch name `add/my-action` and action path `greet-visitor` as an example: + - After a test build is created, it should be able to test the custom action by `woocommerce/grow/greet-visitor@add/my-action-test-build`. + - After the `add/my-action` branch is deleted, the Workflow [GitHub Actions - Delete Test Build](https://github.com/woocommerce/grow/actions/workflows/github-actions-delete-test-build.yml) will delete the `my-action-test-build` branch. ### Directory structure of release build