-
Notifications
You must be signed in to change notification settings - Fork 1.3k
135 lines (118 loc) · 4.26 KB
/
validate-upload.yml
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: Validate and upload
on:
push:
branches:
- master
pull_request_target:
branches:
- "*"
jobs:
changes:
runs-on: ubuntu-latest
name: Determine Changes
outputs:
servers: ${{ steps.filter.outputs.servers }}
servers_files: ${{ steps.filter.outputs.servers_files }}
dry: ${{ steps.filter.outputs.dry }}
steps:
- name: Checkout from Github
uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: filter
with:
list-files: json
filters: |
servers:
- added|modified|deleted: 'servers/**'
dry:
- added|modified|deleted: '.scripts/**'
- added|modified|deleted: '.github/**'
validate-servers:
name: Validate Servers
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- name: Checkout from GitHub
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup Python 3.x
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install Python dependencies
run: pip install -r .scripts/requirements.txt
- name: Validate Servers
run: |
python .scripts/validate.py \
--servers_dir servers \
--metadata_schema metadata.schema.json \
--inactive_file inactive.json \
--inactive_schema inactive.schema.json \
--no-validate_inactive
env:
PR_ID: ${{ github.event.pull_request.number }}
BOT_PAT: ${{ secrets.BOT_PAT }}
USE_ARGS: "true"
upload-servers:
name: Upload Servers
needs: [validate-servers, changes]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout from GitHub
uses: actions/checkout@v3
- name: Setup Python 3.x
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install Python dependencies
run: pip install -r .scripts/requirements.txt
- name: Create output folder
run: mkdir .out/
- name: Output Server Media
run: |
python .scripts/convert_media.py \
--servers_dir servers \
--inactive_file inactive.json \
--servers_logos_output .out/logos \
--servers_logos_sizes 256 128 64 32 \
--servers_backgrounds_output .out/backgrounds \
--servers_backgrounds_sizes 1280x720 852x480 \
--servers_banners_output .out/banners \
--changed_files '${{ needs.changes.outputs.servers_files }}' \
--dry_upload ${{ needs.changes.outputs.dry }}
env:
USE_ARGS: "true"
- name: Create Index File
run: |
python .scripts/create_index.py \
--servers_dir servers \
--inactive_file inactive.json \
--json_output .out/servers.json \
--csv_output .out/servers.csv \
--no-include_inactive
- name: Upload to Cloudflare
env:
R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }}
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
run: |
aws s3 sync .out s3://servermappings-lunarclientcdn-com --endpoint-url $R2_ENDPOINT
aws s3 cp .out/servers.json s3://servermappings-lunarclientcdn-com/servers.json --content-type "application/json" --endpoint-url $R2_ENDPOINT
aws s3 cp .out/servers.csv s3://servermappings-lunarclientcdn-com/servers.csv --content-type "text/csv" --endpoint-url $R2_ENDPOINT
- name: Purge Cloudflare cache
env:
CLOUDFLARE_PURGE_TOKEN: ${{ secrets.CLOUDFLARE_PURGE_TOKEN }}
run: |
curl -X POST "https://api.cloudflare.com/client/v4/zones/6ec53997a971431c0d92ac795f35502b/purge_cache" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $CLOUDFLARE_PURGE_TOKEN" \
--data '{"hosts":["servermappings.lunarclientcdn.com"]}'