-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.bit.branch-lane
40 lines (31 loc) · 1.36 KB
/
github.bit.branch-lane
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
#!/bin/bash
# Check if $BIT_CONFIG_ACCESS_TOKEN is set
if [[ -z "$BIT_CONFIG_USER_TOKEN" && -z "$BIT_CONFIG_ACCESS_TOKEN" ]]; then
echo "Error: BIT_CONFIG_ACCESS_TOKEN environment variable is not set. It is required!"
exit 1
fi
# Assign BIT_CONFIG_ACCESS_TOKEN to BIT_CONFIG_USER_TOKEN
if [[ -z "$BIT_CONFIG_USER_TOKEN" ]]; then
BIT_CONFIG_USER_TOKEN="$BIT_CONFIG_ACCESS_TOKEN"
export BIT_CONFIG_USER_TOKEN
fi
# Extract branch name from GITHUB_REF. Format of GITHUB_REF is refs/heads/<branch_name>
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if [[ -z "${GITHUB_REPOSITORY}" || -z "$BRANCH_NAME" ]]; then
echo "Error: Ensure this task is triggered when creating a new branch"
exit 1
fi
# Determine if there are any new or modified components
statusRaw=$(bit status --json)
newComponentsCount=$(echo "$statusRaw" | jq '.newComponents | length')
modifiedComponentsCount=$(echo "$statusRaw" | jq '.modifiedComponents | length')
laneName="$BRANCH_NAME"
if [ "$newComponentsCount" -gt 0 ] || [ "$modifiedComponentsCount" -gt 0 ]; then
laneLink="https://bit.cloud/${ORG}/${SCOPE}/~lane/${laneName}"
# Operations on bit lane
bit lane remove "${ORG}.${SCOPE}/${laneName}" --remote --silent --force &> /dev/null || echo "Warning: Failed to remove the lane."
bit status --strict
bit lane create "${laneName}"
bit snap -m "CI" --build
bit export
fi