forked from YOURLS/YOURLS
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (78 loc) 路 3.49 KB
/
Copy pathupdate-geoip.yml
File metadata and controls
92 lines (78 loc) 路 3.49 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
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
permissions:
contents: write
pull-requests: write
jobs:
update-geoip:
name: "Check for updated GeoIP DB"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Generate token
uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.BOT_APP_ID }}
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- 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 -fsSL 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 -fsSL "$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 "DATE=$(/bin/date -u "+%F")" >> $GITHUB_OUTPUT
- name: Create pull request
uses: peter-evans/create-pull-request@v7
id: pull-request
with:
token: ${{ steps.app-token.outputs.token }}
author: "${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>"
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
- name: Approve a PR
if: ${{ steps.pull-request.outputs.pull-request-url && steps.pull-request.outputs.pull-request-operation != 'none' }}
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ steps.pull-request.outputs.pull-request-url }}
GITHUB_TOKEN: ${{ github.token }}
- name: Enable Pull Request Automerge
if: ${{ steps.pull-request.outputs.pull-request-url && steps.pull-request.outputs.pull-request-operation != 'none' }}
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{ steps.pull-request.outputs.pull-request-url }}
GITHUB_TOKEN: ${{ github.token }}