-
Notifications
You must be signed in to change notification settings - Fork 16
102 lines (91 loc) · 3.26 KB
/
eas-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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: 🧹 EAS Update Branch Cleanup
on:
pull_request:
types: [closed]
jobs:
prepare:
runs-on: ubuntu-latest
permissions:
actions: read # Required to find the last successful workflow run
contents: read # Required for actions/checkout
steps:
- name: 🏗 Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # Checks out all branches and tags. Maybe we can make this better in the future?
# This line is needed for nx affected to work when CI is running on a PR
- name: 🔀 Track main if PR
if: github.ref != 'refs/heads/main'
run: git branch --track main origin/main
- name: 🔧 Configure NX SHAs
uses: nrwl/nx-set-shas@v4
- name: 🔧 Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.12.2
- run: |
corepack enable
- name: Setup Yarn in Node
uses: actions/setup-node@v4
with:
cache: 'yarn'
- name: 📦 Install dependencies
run: yarn install
- name: 🧩 Determine Affected Projects for eas-update
id: set-matrix
run: |
# Get the list of affected projects with eas-update target
affected_projects=$(yarn nx show projects --affected --exclude=shelter --withTarget eas-update)
# Convert the list to a JSON matrix
MATRIX_JSON=$(echo "$affected_projects" | jq -Rcs '
split("\n") |
map(select(. != "")) |
if length == 0 then
{}
else
{include: map({project: .})}
end'
)
IS_MATRIX_EMPTY=$(echo "$MATRIX_JSON" | jq 'if .include | length == 0 then true else false end')
echo "is_matrix_empty=$IS_MATRIX_EMPTY" >> $GITHUB_OUTPUT
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
is_matrix_empty: ${{ steps.set-matrix.outputs.is_matrix_empty }}
delete-eas-branch:
needs: prepare
runs-on: ubuntu-latest
if: needs.prepare.outputs.is_matrix_empty == 'false'
steps:
- name: 🏗 Check out repo
uses: actions/checkout@v4
- name: 🔧 Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.12.2
- run: |
corepack enable
- name: Setup Yarn in Node
uses: actions/setup-node@v4
with:
cache: 'yarn'
- name: 🔧 Setup EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: 📦 Install dependencies
run: yarn install
- name: 🗑️ Delete EAS Branch & Channel for Each Project
run: |
BRANCH_NAME=${{ github.head_ref || github.ref_name }}
MATRIX_JSON='${{ needs.prepare.outputs.matrix }}'
for project in $(echo $MATRIX_JSON | jq -r '.include[].project'); do
echo "Deleting EAS branch for project: $project"
# Change to the project directory
cd apps/$project
# Run the EAS command in the project directory
eas branch:delete --non-interactive $BRANCH_NAME
# Change back to the original directory
cd -
done