-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.bit.tag-export
More file actions
83 lines (67 loc) · 2.06 KB
/
Copy pathgithub.bit.tag-export
File metadata and controls
83 lines (67 loc) · 2.06 KB
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
#!/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
# Ensure GitHub token is set
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Error: GITHUB_TOKEN environment variable is required."
exit 1
fi
commit_sha=$(git rev-parse HEAD)
response=$(curl --silent \
--header "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/$commit_sha/pulls")
if [[ $? -ne 0 ]]; then
echo "Error: Failed to fetch data from GitHub API for commit: $commit_sha."
exit 1
fi
if echo "$response" | jq '. | type' | grep -q "array" && [[ "$(echo "$response" | jq 'length')" -gt 0 ]]; then
PR_TITLE=$(echo "$response" | jq -r '.[0].title')
PR_LABELS=$(echo "$response" | jq -r '.[0].labels[].name')
else
PR_TITLE=""
PR_LABELS=""
fi
keywords=("patch" "major" "minor" "pre-release")
version="Unknown"
for label in $PR_LABELS; do
if [[ " ${keywords[*]} " == *"$label"* ]]; then
version="$label"
break
fi
done
if [[ "$version" == "Unknown" ]]; then
for keyword in "${keywords[@]}"; do
if [[ "$PR_TITLE" == *"[${keyword}]"* ]]; then
version="$keyword"
break
fi
done
fi
if [[ "$version" == "Unknown" ]]; then
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
for keyword in "${keywords[@]}"; do
if [[ "$COMMIT_MESSAGE" == *"[${keyword}]"* ]]; then
version="$keyword"
break
fi
done
fi
echo "Determined Version: $version"
command="bit tag -m 'CI' --build"
if [[ "$version" != "Unknown" ]]; then
command+=" --$version"
fi
if [[ " $@ " == *"--persist"* ]]; then
command+=" --persist"
fi
echo "Executing: $command"
$command
bit export