-
Notifications
You must be signed in to change notification settings - Fork 8
46 lines (43 loc) · 1.72 KB
/
branch-test-teardown.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: Manual branch test teardown
on:
pull_request_target:
types: [closed]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
teardown:
name: Seek & Destroy
runs-on: ubuntu-latest
# TODO: if pr contains label "has-test-bin"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
- name: Seek
id: seek
run: |
TAG_VERSION="$(echo '${{ github.head_ref }}' | iconv -t ascii//TRANSLIT | sed -r "s/[^a-zA-Z0-9]+/-/g" | sed -r "s/^-+\|-+$//g" | tr A-Z a-z)"
TAG_VERSION="v$(awk '/version/{gsub(/("|",)/,"",$2);print $2}' package.json)-$TAG_VERSION.0"
echo ::set-output name=tag-version::$TAG_VERSION
- name: Destroy local
id: destroy-local
run: |
git fetch --tags -p
set -e
TAG_NOT_FOUND=0
git tag -d '${{ steps.seek.outputs.tag-version }}' || TAG_NOT_FOUND=1
echo ::set-output name=tag-not-found::$TAG_NOT_FOUND
- name: Destroy remote
if: ${{ steps.destroy-local.outputs.tag-not-found == 0 }}
run: |
(
gh release delete "$TAG_VERSION" --yes --repo $REPO &&
git push --delete origin "$TAG_VERSION" &&
gh pr comment $PR_NUMBER --body "$TAG_VERSION successfully destroyed! ($RUN_URL)" --repo $REPO
) || gh pr comment $PR_NUMBER --body "$TAG_VERSION deletion failed ($RUN_URL)" --repo $REPO
env:
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.number }}
TAG_VERSION: ${{ steps.seek.outputs.tag-version }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/runs/${{ github.run_id }}