-
Notifications
You must be signed in to change notification settings - Fork 8
49 lines (42 loc) · 1.47 KB
/
feature-branch-cleanup.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
47
48
49
# Based on https://evilmartians.com/chronicles/super-github-pages-budget-frontend-staging-with-storybook-and-more
name: Feature branch cleanup
on:
pull_request:
types: [closed]
branches-ignore: [main]
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
remove_stale_pages:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- name: Create branch name without text before first forward slash
run: |
RAW_BRANCH_NAME=${{ github.head_ref || github.ref_name }}
BRANCH_NAME=$(echo $RAW_BRANCH_NAME | sed 's/[^/]*\///')
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Check out branch to access .nvmrc
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Check out gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Delete folder
run: |
git config --global user.name GitHub Action
git config --global user.email [email protected]
git rm demo-${{ env.BRANCH_NAME }} -r
git add .
git commit -m "Remove feature branch folder"
git push
- name: Deactivate deployment
uses: bobheadxi/deployments@v1
if: always()
with:
step: deactivate-env
token: ${{ secrets.GITHUB_TOKEN }}
env: demo-${{ env.BRANCH_NAME }}