-
-
Notifications
You must be signed in to change notification settings - Fork 6
139 lines (122 loc) · 5.01 KB
/
auto.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Automatic Release
on:
schedule:
- cron: 15 */8 * * *
workflow_dispatch:
jobs:
Check:
outputs:
json: ${{ steps.setVariables.outputs.json }}
new_avail: ${{ steps.setVariables.outputs.new_avail }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Latest Releases
run: |
# ----------------------------- #
# --- get release version --- #
# ----------------------------- #
echo "< Fetching versions >"
BRAVE="$(curl -s https://api.github.com/repos/brave/brave-browser/releases?per_page=5)"
RELEASES="$(echo "$BRAVE" | jq -S -r '.[] | {name,tag_name}' | sed 's/ \\n\\n//g')"
TAG_NAMES=$(echo "$RELEASES" | jq '.tag_name')
# Only include latest version of release type to avoid conflict.
# It's also pointless building outdated releases.
LATEST_NIGHTLY=false
LATEST_DEV=false
LATEST_BETA=false
LATEST_RELEASE=false
OUT="{\"include\":[]}"
# --------------------------------- #
# --- check release existence --- #
# --------------------------------- #
echo "[ CHECKING ][ "$TAG_NAMES" ]"
while read -r TAG; do
# -- Skip existent releases --
ID="$(curl -s "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" | jq -r .id)"
if [ "$ID" != "null" ]; then
echo -e "Release ${TAG} already exists."
else
# -- check download links --
NAME="$(echo "$RELEASES" | jq --arg TAG "$TAG" '. | select(.tag_name==$TAG) | .name' | sed 's/\"//g')"
EXISTS=$(echo "$BRAVE" | jq --arg TAG "$TAG" -r '.[] | select(.tag_name==$TAG) |
.assets[].browser_download_url | contains("linux")' | sort | uniq)
if [ "$EXISTS" = "false" ]; then
echo "< Download links unavailable for ${NAME} >"
else
echo -e "< New Release: ${NAME} >"
SKIP=true
# -------------------------------- #
# --- determine release type --- #
# -------------------------------- #
# -- Nightly
if [[ $NAME =~ "Nightly" ]]; then
BRAVE_PRERELEASE=true
BRAVE_TYPE=nightly
if [[ $LATEST_NIGHTLY == false ]]; then
LATEST_NIGHTLY=true
SKIP=false
fi
# -- Development
elif [[ $NAME =~ "Dev" ]]; then
BRAVE_PRERELEASE=true
BRAVE_TYPE=dev
if [[ $LATEST_DEV == false ]]; then
LATEST_DEV=true
SKIP=false
fi
# -- Beta
elif [[ $NAME =~ "Beta" ]]; then
BRAVE_PRERELEASE=true
BRAVE_TYPE=beta
if [[ $LATEST_BETA == false ]]; then
LATEST_BETA=true
SKIP=false
fi
# -- Release
elif [[ $NAME =~ "Release" ]]; then
BRAVE_PRERELEASE=false
BRAVE_TYPE=stable
if [[ $LATEST_RELEASE == false ]]; then
LATEST_RELEASE=true
SKIP=false
fi
fi
# -- Add latest release to output --
if [[ $SKIP == false ]]; then
OUT="$(echo $OUT | jq -c \
--arg TAG "$TAG" \
--arg TYPE "$BRAVE_TYPE" \
--arg PRERELEASE "$BRAVE_PRERELEASE" \
'.include |= . +
[{
"tag": $TAG,
"type": $TYPE,
"prerelease": $PRERELEASE,
}]')"
fi
fi
fi
done < <(echo "$RELEASES" | jq '.tag_name' | sed 's/\"//g')
# -- Build releases, if they exist --
if [ "$OUT" == "{\"include\":[]}" ]; then
echo "NEW_AVAILABLE=false" >> $GITHUB_ENV
else
echo "NEW_AVAILABLE=true" >> $GITHUB_ENV
echo "OUT<<EOF" >> $GITHUB_ENV
echo $OUT >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
- env:
input_json: ${{ env.OUT }}
input_avail: ${{ env.NEW_AVAILABLE }}
id: setVariables
run: |
echo "json=$input_json" >> $GITHUB_OUTPUT
echo "new_avail=$input_avail" >> $GITHUB_OUTPUT
Build:
needs: Check
if: ${{ fromJson(needs.check.outputs.new_avail) }}
uses: ./.github/workflows/release.yml
with:
input_json: ${{ needs.check.outputs.json }}