Welcome to mirror list, hosted at ThFree Co, Russian Federation.

update-geoip.yml « workflows « .github - github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fbae4ece7c61971d802c248ee33869ff95390cfc (plain)
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
name: Update GeoIP DB

on:
  # Run every Monday at 13:37
  schedule:
    - cron: '37 13 * * 1'
  # Run manually
  workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
  # The concurrency group contains the workflow name and the branch name.
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  update-geoip:
    name: "Check for updated GeoIP DB"

    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Generate token
        uses: tibdex/github-app-token@v1
        id: generate-token
        with:
          app_id: ${{ secrets.BOT_APP_ID }}
          private_key: ${{ secrets.BOT_PRIVATE_KEY }}

      - name: Check if newer GeoIP DB
        env:
          MAXMIND_API_KEY: ${{ secrets.MAXMIND_API_KEY }}
        run: |
          URL="https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${MAXMIND_API_KEY}&suffix=tar.gz"
          REMOTE_MODIFIED=$(curl --silent --head "$URL" | grep "last-modified" | sed 's/last-modified: //')
          REMOTE_CTIME=$(date -d "$REMOTE_MODIFIED" +%s)
          LOCAL_MODIFIED=$(curl -sL https://api.github.com/repos/YOURLS/YOURLS/commits?path=includes/geo/GeoLite2-Country.mmdb | \
            jq -r '.[0]["commit"]["author"]["date"]')
          LOCAL_CTIME=$(date -d "$LOCAL_MODIFIED" +%s)
          echo "Remote: $REMOTE_CTIME ($(date -d @$REMOTE_CTIME))"
          echo "Local: $LOCAL_CTIME ($(date -d @$LOCAL_CTIME))"
          if [ $LOCAL_CTIME -lt $REMOTE_CTIME ] ; then curl -s "$URL" | tar -zvx -C includes/geo/ --strip-components 1 -- ; fi

      - name: "Debug info: Show git status"
        run: git status -vv --untracked=all

      - name: "Get date"
        id: get-date
        run: echo "::set-output name=DATE::$(/bin/date -u "+%F")"

      - name: Create pull request
        uses: peter-evans/create-pull-request@v4
        with:
          token: ${{ steps.generate-token.outputs.token }}
          base: master
          branch: auto-update-geoip
          commit-message: "Update GeoIP DB"
          title: "Update GeoIP DB"
          body: |
            Updated GeoIP database, last verified on ${{ steps.get-date.outputs.DATE }}.

            Source: https://www.maxmind.com/en/account/login
          labels: |
            dependencies