-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (169 loc) · 6.43 KB
/
continuous-integration.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Continuous Integration
on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:
inputs:
logLevel:
description: "Log level"
required: true
default: "info"
type: choice
options:
- info
- warning
- debug
env:
TZ: Asia/Jakarta
EMOJI_CHEAT_SHEETS: "👻,😻,💕,🤍,💨,🧚,🧜♀️,🧞,💃,🐣,🐉,🦕,🦖,🐳,🐬,🦋,🌻,🌼,🌱,🌿,🍀,🍃,🍻,🛫,🪂,🚀,🌟,✨,⚡,🔥,🎉"
jobs:
build:
name: Build and Testing
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
prepare:
name: Prepare Branch
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
- name: Remove ${{ vars.ARCHIVE_BRANCH_NAME }} branch if it exists
run: |
if git ls-remote --exit-code --heads origin ${{ vars.ARCHIVE_BRANCH_NAME }}; then
echo "Branch deleted successfully"
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} --delete ${{ vars.ARCHIVE_BRANCH_NAME }}
else
echo "Branch does not exist"
fi
update:
name: Update Proxies
runs-on: ubuntu-latest
needs: [prepare]
permissions:
contents: write
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
- name: Configure GIT
run: |
git config --global user.email $(git log --reverse --format='%ae' | head -n 1)
git config --global user.name $(git log --reverse --format='%an' | head -n 1)
- name: Create ${{ vars.ARCHIVE_BRANCH_NAME }} branch
run: |
git checkout -b ${{ vars.ARCHIVE_BRANCH_NAME }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Install dependencies
run: |
go mod tidy
- name: Run Go program
env:
PROXY_RESOURCES: ${{ secrets.PROXY_RESOURCES }}
run: |
go run ./cmd/main.go
- name: Check for changes
run: |
if [ "$(git status --porcelain)" ]; then
echo "Changes detected"
echo "CHANGES_EXIST=true" >> $GITHUB_ENV
else
echo "No changes to commit"
echo "CHANGES_EXIST=false" >> $GITHUB_ENV
fi
- name: Commit files
if: env.CHANGES_EXIST == 'true'
run: |
git add storage
git commit -m "chore(bot): update proxies at $(date '+%a, %d %b %Y %H:%M:%S (GMT+07:00)' | tr '[:upper:]' '[:lower:]') $(echo $EMOJI_CHEAT_SHEETS | tr ',' '\n' | shuf -n 1)"
- name: Push changes to ${{ vars.ARCHIVE_BRANCH_NAME }} branch
if: env.CHANGES_EXIST == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ vars.ARCHIVE_BRANCH_NAME }}
force: true
release:
name: Release
runs-on: ubuntu-latest
needs: [update]
permissions:
contents: write
steps:
- name: Checkout ${{ vars.ARCHIVE_BRANCH_NAME }} branch
uses: actions/checkout@v4
with:
ref: ${{ vars.ARCHIVE_BRANCH_NAME }}
- name: Configure GIT
run: |
git config --global user.email $(git log --reverse --format='%ae' | head -n 1)
git config --global user.name $(git log --reverse --format='%an' | head -n 1)
- name: Get last commit time on ${{ vars.ARCHIVE_BRANCH_NAME }} branch
run: |
echo "UPDATED_AT=$(date -d "$(git log -1 --format=%cd --date=iso-strict)" "+%A, %B %e, %Y at %H:%M:%S (GMT+07:00)" | awk '{$1=$1; print}')" >> $GITHUB_ENV
- name: Count proxies
run: |
echo "HTTP_PROXY_COUNT=$(grep -v '^$' ./storage/classic/http.txt | wc -l)" >> $GITHUB_ENV
echo "HTTPS_PROXY_COUNT=$(grep -v '^$' ./storage/classic/https.txt | wc -l)" >> $GITHUB_ENV
echo "SOCKS4_PROXY_COUNT=$(grep -v '^$' ./storage/classic/socks4.txt | wc -l)" >> $GITHUB_ENV
echo "SOCKS5_PROXY_COUNT=$(grep -v '^$' ./storage/classic/socks5.txt | wc -l)" >> $GITHUB_ENV
- name: Extract 10 fresh proxies
run: |
echo "HTTP_PROXIES=$(shuf -n 10 ./storage/classic/http.txt | awk '{printf "%s\\n", $0}')" >> $GITHUB_ENV
echo "HTTPS_PROXIES=$(shuf -n 10 ./storage/classic/https.txt | awk '{printf "%s\\n", $0}')" >> $GITHUB_ENV
echo "SOCKS4_PROXIES=$(shuf -n 10 ./storage/classic/socks4.txt | awk '{printf "%s\\n", $0}')" >> $GITHUB_ENV
echo "SOCKS5_PROXIES=$(shuf -n 10 ./storage/classic/socks5.txt | awk '{printf "%s\\n", $0}')" >> $GITHUB_ENV
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
- name: Update documentation
run: |
sed \
-e "s/{{UPDATED_AT}}/${UPDATED_AT}/" \
-e "s/{{HTTP_PROXY_COUNT}}/${HTTP_PROXY_COUNT}/" \
-e "s/{{HTTPS_PROXY_COUNT}}/${HTTPS_PROXY_COUNT}/" \
-e "s/{{SOCKS4_PROXY_COUNT}}/${SOCKS4_PROXY_COUNT}/" \
-e "s/{{SOCKS5_PROXY_COUNT}}/${SOCKS5_PROXY_COUNT}/" \
-e "s/{{HTTP_PROXIES}}/${HTTP_PROXIES}/" \
-e "s/{{HTTPS_PROXIES}}/${HTTPS_PROXIES}/" \
-e "s/{{SOCKS4_PROXIES}}/${SOCKS4_PROXIES}/" \
-e "s/{{SOCKS5_PROXIES}}/${SOCKS5_PROXIES}/" \
./docs/README.template.md > ./README.md
- name: Check for changes
run: |
if [ "$(git status --porcelain)" ]; then
echo "Changes detected"
echo "CHANGES_EXIST=true" >> $GITHUB_ENV
else
echo "No changes to commit"
echo "CHANGES_EXIST=false" >> $GITHUB_ENV
fi
- name: Commit changes
if: env.CHANGES_EXIST == 'true'
run: |
git add README.md
git commit -m "docs: release fresh proxy list $(echo $EMOJI_CHEAT_SHEETS | tr ',' '\n' | shuf -n 1)"
- name: Push changes
if: env.CHANGES_EXIST == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main
force: true