Skip to content

Commit af8aad2

Browse files
xPawLifeismana
andcommitted
Add a script to push to source 2 schema explorer
Co-Authored-By: Antoine Rybacki <[email protected]>
1 parent 75bf92b commit af8aad2

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

.github/workflows/gametracking.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ on:
2222
required: false
2323
type: boolean
2424
default: false
25+
dumpsource2-schema-json:
26+
required: false
27+
type: string
28+
default: ''
2529
secrets:
2630
STEAM_USERNAME:
2731
required: true
@@ -129,10 +133,12 @@ jobs:
129133

130134
- name: Set commit status
131135
if: always() && steps.before.outputs.sha
136+
id: set-status
132137
working-directory: ${{ github.workspace }}/tracked_game
133138
shell: bash
134139
run: |
135140
NEW_SHA=$(git rev-parse HEAD)
141+
echo "sha=$NEW_SHA" >> $GITHUB_OUTPUT
136142
137143
if [[ "$NEW_SHA" == "${{ steps.before.outputs.sha }}" ]]; then
138144
echo "No new commit was pushed, skipping status"
@@ -153,6 +159,25 @@ jobs:
153159
env:
154160
GH_TOKEN: ${{ github.token }}
155161

162+
- name: Checkout DumpSource2 JSON Repo
163+
if: ${{ inputs.dumpsource2-schema-json != '' }}
164+
uses: actions/checkout@v6
165+
with:
166+
fetch-depth: 1
167+
path: dumps2_json
168+
repository: 'ValveResourceFormat/SchemaExplorer'
169+
token: ${{ secrets.DUMPSOURCE2_EXPLORER_TOKEN }}
170+
171+
- name: Push DumpSource2 JSON
172+
if: ${{ inputs.dumpsource2-schema-json != '' }}
173+
working-directory: ${{ github.workspace }}/dumps2_json/schemas
174+
shell: bash
175+
run: |
176+
"${{ github.workspace }}/tools/push_schema_json.sh" \
177+
"${{ inputs.dumpsource2-schema-json }}" \
178+
"${{ github.workspace }}/tracked_game" \
179+
"https://github.com/${{ github.repository }}/commit/${{ steps.set-status.outputs.sha }}"
180+
156181
- name: Dispatch sync to ValveProtobufs
157182
if: ${{ env.GH_TOKEN != '' }}
158183
run: gh api repos/SteamTracking/Protobufs/dispatches -f event_type=sync

tools/push_schema_json.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
if [[ $# -ne 3 ]]; then
5+
echo "Usage: $(basename "$0") <schema-name> <source-dir> <commit-url>"
6+
exit 1
7+
fi
8+
9+
# @param $1 - Schema name used as the output filename (e.g. "dota2")
10+
# @param $2 - Source directory containing DumpSource2/schemas.json
11+
# @param $3 - Commit URL included in the commit body
12+
SCHEMA_NAME="$1"
13+
SOURCE_DIR="$2"
14+
COMMIT_URL="$3"
15+
16+
NEW_JSON="$SOURCE_DIR/DumpSource2/schemas.json"
17+
EXISTING_GZ="$SCHEMA_NAME.json.gz"
18+
19+
# strip_metadata - Strips revision, version_date, and version_time fields from schema JSON.
20+
# Reads from a file argument or stdin. Output is sorted and compact for consistent comparison.
21+
strip_metadata() {
22+
jq --sort-keys --compact-output 'del(.revision, .version_date, .version_time)' "$@"
23+
}
24+
25+
if [[ -f "$EXISTING_GZ" ]]; then
26+
OLD_STRIPPED=$(gzip --decompress --stdout "$EXISTING_GZ" | strip_metadata)
27+
NEW_STRIPPED=$(strip_metadata "$NEW_JSON")
28+
29+
if [[ "$NEW_STRIPPED" == "$OLD_STRIPPED" ]]; then
30+
echo "No schema changes for $SCHEMA_NAME, skipping"
31+
exit 0
32+
fi
33+
fi
34+
35+
REVISION=$(jq --raw-output '.revision' "$NEW_JSON")
36+
37+
mv "$NEW_JSON" "$SCHEMA_NAME.json"
38+
gzip --force --best --no-name "$SCHEMA_NAME.json"
39+
git add "$SCHEMA_NAME.json.gz"
40+
git commit -m "Update $SCHEMA_NAME schema (revision $REVISION)" -m "$COMMIT_URL"
41+
42+
# Retry push in case another game updated the repo concurrently
43+
for i in 1 2 3; do
44+
if git push; then
45+
exit 0
46+
fi
47+
echo "Push failed (attempt $i), pulling and retrying..."
48+
sleep "$((i * 5))"
49+
git pull --rebase
50+
done
51+
52+
echo "Push failed after 3 attempts"
53+
exit 1

0 commit comments

Comments
 (0)