-
Notifications
You must be signed in to change notification settings - Fork 887
135 lines (121 loc) · 4.57 KB
/
Copy pathbuild.yml
File metadata and controls
135 lines (121 loc) · 4.57 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
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
name: Build geoip files
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 4"
push:
branches:
- master
paths-ignore:
- "assets/*"
- ".gitignore"
- "LICENSE*"
- "*.md"
pull_request:
branches:
- master
paths-ignore:
- "assets/*"
- ".gitignore"
- "LICENSE*"
- "*.md"
permissions:
contents: write
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout codebase
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: ./go.mod
cache-dependency-path: ./go.sum
- name: Set variables
run: |
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
echo "RELEASE_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
shell: bash
- name: Download GeoLite2 databases
env:
LICENSE_KEY: ${{ secrets.MAXMIND_GEOLITE2_LICENSE }}
run: |
mkdir -p output
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${LICENSE_KEY}&suffix=tar.gz" -o ./output/GeoLite2-ASN.tar.gz
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=${LICENSE_KEY}&suffix=zip" -o ./output/GeoLite2-ASN-CSV.zip
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${LICENSE_KEY}&suffix=tar.gz" -o ./output/GeoLite2-Country.tar.gz
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=${LICENSE_KEY}&suffix=zip" -o ./output/GeoLite2-Country-CSV.zip
- name: Prepare GeoLite2 databases
run: |
cp ./output/{*.gz,*.zip} ./
unzip GeoLite2-Country-CSV.zip
unzip GeoLite2-ASN-CSV.zip
tar -xvzf GeoLite2-Country.tar.gz
tar -xvzf GeoLite2-ASN.tar.gz
cp GeoLite2-Country_*/*.mmdb ./output/
cp GeoLite2-ASN_*/*.mmdb ./output/
cp GeoLite2-Country-CSV_*/{GeoLite2-Country-Blocks-*,GeoLite2-Country-Locations-en,GeoLite2-Country-Locations-zh-CN}.csv ./output/
cp GeoLite2-ASN-CSV_*/*.csv ./output/
mkdir -p geolite2
cp GeoLite2-Country-CSV_*/*.csv ./geolite2/
cp GeoLite2-ASN-CSV_*/*.csv ./geolite2/
- name: Build geoip files
run: |
go build ./
./geoip convert -c ./config.json
- name: Verify mmdb files
run: |
cd ./output || exit 1
go install -v github.com/maxmind/mmdbverify@latest
for name in $(ls *.mmdb); do
$(go env GOPATH)/bin/mmdbverify -file ${name}
done
- name: Generate sha256 checksum for dat files
run: |
cd ./output || exit 1
for name in $(ls *.dat); do
sha256sum ${name} > ./${name}.sha256sum
done
- name: Generate sha256 checksum for mmdb files
run: |
cd ./output || exit 1
for name in $(ls *.mmdb); do
sha256sum ${name} > ./${name}.sha256sum
done
- name: Git push assets to "release" branch
if: github.event_name != 'pull_request'
run: |
cd output || exit 1
git init
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b release
git add -A
git commit -m "${{ env.RELEASE_NAME }}"
git remote add geoip "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u geoip release
- name: Purge jsdelivr CDN
if: github.event_name != 'pull_request'
run: |
cd output || exit 1
for file in $(ls); do
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/${file}"
done
- name: Remove some files to avoid publishing to GitHub release
if: github.event_name != 'pull_request'
run: |
rm -rf ./output/*.{gz,zip}
rm -rf ./output/GeoLite2-*.csv
rm -rf ./output/GeoLite2-*.mmdb
rm -rf ./output/GeoLite2-*.sha256sum
rm -rf ./output/{clash,dat,mrs,nginx,srs,surge,text}
- name: Upload files to GitHub release
if: github.event_name != 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ env.TAG_NAME }} --title "${{ env.RELEASE_NAME }}" ./output/*