Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new workflow to GitHub Actions for deleting the test build of Custom GitHub actions #93

Merged
merged 2 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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