-
Notifications
You must be signed in to change notification settings - Fork 1.2k
169 lines (148 loc) · 5.63 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Validate and upload
on:
push:
branches:
- master
pull_request_target:
branches:
- "*"
schedule:
- cron: "0 0 * * *"
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@v4
- name: Determine Changes
uses: dorny/paths-filter@v3
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@v4
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@v5
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' || github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout from GitHub
uses: actions/checkout@v4
- name: Setup Python 3.x
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install Python dependencies
run: pip install -r .scripts/requirements.txt
- name: Create server output folder
run: mkdir .out/
- name: Create Crowdin upload target
run: mkdir -p ServerMappings/locales/ && touch ServerMappings/locales/en_US.json
- name: Download translations from Crowdin
uses: crowdin/github-action@v2
with:
command: "download"
command_args: "--source ServerMappings/locales/en_US.json --translation ServerMappings/locales/%locale%.json --export-only-approved"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: "424304"
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_TOKEN }}
- 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 \
--servers_wordmarks_output .out/wordmarks \
--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 \
--translations_folder ServerMappings/locales/ \
--translations_output ServerMappings/locales/en_US.json \
--json_output .out/servers.json \
--csv_output .out/servers.csv \
--no-include_inactive
- name: Sync to Crowdin
uses: crowdin/github-action@v2
with:
upload_sources: true
upload_translations: false
download_translations: false
upload_sources_args: "--preserve-hierarchy"
source: ServerMappings/locales/en_US.json
translation: ServerMappings/locales/%locale%.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: "424304"
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_TOKEN }}
- 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"]}'