Skip to content

Commit

Permalink
Merge pull request #93 from woocommerce/dev/actions-delete-test-build
Browse files Browse the repository at this point in the history
Add a new workflow to GitHub Actions for deleting the test build of Custom GitHub actions
  • Loading branch information
eason9487 authored Dec 26, 2023
2 parents 09022c7 + 525805b commit d9b9b89
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/github-actions-delete-test-build.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions packages/github-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d9b9b89

Please sign in to comment.