commit 5fe4a61ec72ff613a6c1fb476f50f77e36296379 Author: dnomd343 Date: Mon May 30 10:47:34 2022 +0800 feat: publish by github actions diff --git a/.github/workflows/GeoLite2.yml b/.github/workflows/GeoLite2.yml new file mode 100644 index 0000000..20d6e36 --- /dev/null +++ b/.github/workflows/GeoLite2.yml @@ -0,0 +1,43 @@ +name: Publish + +on: + workflow_dispatch: + schedule: + - cron: 0 0 * * * + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Download + run: | + URI="https://download.maxmind.com/app/geoip_download?license_key=${{ secrets.LICENSE_KEY }}&suffix=tar.gz&edition_id=GeoLite2-" + TAG=$(curl -sI "${URI}ASN" | grep -i ^Content-Disposition | grep -oP '[0-9]{8}') + LOCAL_TAG=$(git tag | grep -P '[0-9]{8}' | sort | tail -n1) + echo "${LOCAL_TAG} -> ${TAG}" + [ "${TAG}" == "${LOCAL_TAG}" ] && echo "No need to update, bye!" && exit 1 + echo -e "| File | Size | Date | SHA1 |\n| :-: | :-: | :-: | :-: |" > info + mkdir dist && echo "TAG_NAME=${TAG}" >> $GITHUB_ENV + for name in ASN City Country; do + wget "${URI}${name}" -qO - | tar xzf - + mv GeoLite2-*/*.mmdb dist/${name}.mmdb + SIZE=$(du -b dist/${name}.mmdb | awk '{print $1}') + HASH=$(sha1sum dist/${name}.mmdb | awk '{print $1}') + DATE=$(stat dist/${name}.mmdb | grep Modify | grep -oP '[0-9]{4}(-[0-9]{2}){2} ([0-9]{2}:){2}[0-9]{2}') + echo "| ${name}.mmdb | ${SIZE} | \`${DATE} UTC\` | \`${HASH}\` |" >> info + done + cd dist && sha1sum *.mmdb > sha1sums.txt + + - name: Release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + files: dist/* + tag_name: ${{ env.TAG_NAME }} + body_path: ${{ github.workspace }}/info