Build geoip.dat #158
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build geoip.dat | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * 4" | |
push: | |
branches: | |
- master | |
paths-ignore: | |
- "**/README.md" | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Go 1.x.y | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ^1.16 | |
- 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: Checkout codebase | |
uses: actions/[email protected] | |
- name: Get GeoLite2 | |
env: | |
LICENSE_KEY: ${{ secrets.MAXMIND_GEOLITE2_LICENSE }} | |
run: | | |
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=${LICENSE_KEY}&suffix=zip" -o GeoLite2-Country-CSV.zip | |
unzip GeoLite2-Country-CSV.zip | |
rm -f GeoLite2-Country-CSV.zip | |
mv GeoLite2* geoip | |
- name: Build geoip.dat file | |
run: | | |
go run ./ --country=./geoip/GeoLite2-Country-Locations-en.csv --ipv4=./geoip/GeoLite2-Country-Blocks-IPv4.csv --ipv6=./geoip/GeoLite2-Country-Blocks-IPv6.csv --ipv4CN=https://raw.githubusercontent.com/17mon/china_ip_list/master/china_ip_list.txt | |
- name: Generate geoip.dat sha256 hash | |
run: | | |
sha256sum geoip.dat > geoip.dat.sha256sum | |
- name: Download GeoLite2 | |
env: | |
LICENSE_KEY: ${{ secrets.MAXMIND_GEOLITE2_LICENSE }} | |
run: | | |
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${LICENSE_KEY}&suffix=tar.gz" -o 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 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 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 GeoLite2-Country-CSV.zip | |
- name: Move files to publish directory | |
run: | | |
mkdir -p publish | |
mv geoip.dat geoip.dat.sha256sum *.gz *.zip ./publish | |
- name: Git push assets to "release" branch | |
run: | | |
cd publish || exit 1 | |
git init | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "358289258+github-actions[bot]@users.noreply.github.com" | |
git checkout -b release | |
git add geoip.dat geoip.dat.sha256sum *.gz *.zip | |
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: Create a release | |
id: create_release | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.TAG_NAME }} | |
release_name: ${{ env.RELEASE_NAME }} | |
draft: false | |
prerelease: false | |
- name: Upload geoip.dat | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./publish/geoip.dat | |
asset_name: geoip.dat | |
asset_content_type: application/octet-stream | |
- name: Upload geoip.dat sha256sum | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./publish/geoip.dat.sha256sum | |
asset_name: geoip.dat.sha256sum | |
asset_content_type: text/plain |