Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
managed/CounterStrikeSharp.API/Generated/**/*.cs text eol=crlf
83 changes: 83 additions & 0 deletions .github/workflows/sync-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Synchronize - Schema

on:
schedule:
- cron: '0 8 * * *'
workflow_dispatch:

jobs:
update-schema:
runs-on: ubuntu-latest
if: github.repository == 'roflmuffin/CounterStrikeSharp'
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Install lftp
run: sudo apt-get update && sudo apt-get install -y lftp

- name: Run schema update script
env:
GS_HOST: ${{ secrets.GS_HOST }}
GS_PORT: ${{ secrets.GS_PORT }}
GS_PASS: ${{ secrets.GS_PASS }}
SFTP_HOST: ${{ secrets.SFTP_HOST }}
SFTP_USER: ${{ secrets.SFTP_USER }}
SFTP_PASS: ${{ secrets.SFTP_PASS }}
run: |
mkdir -p ~/.lftp
echo "set sftp:auto-confirm yes" >> ~/.lftp/rc
echo "set ssl:verify-certificate no" >> ~/.lftp/rc
chmod +x eng/update-schema.sh
chmod +x eng/rcon
./eng/update-schema.sh

- name: Get patch version
id: version
run: |
PATCH_VERSION=$(jq -r ".game_info.PatchVersion" managed/CounterStrikeSharp.SchemaGen/Schema/server.json)
echo "patch_version=$PATCH_VERSION" >> $GITHUB_OUTPUT

- name: Check for changes
id: changes
run: |
if [[ -n $(git status --porcelain managed/CounterStrikeSharp.API/Generated/) ]]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected in Generated folder:"
git status --porcelain managed/CounterStrikeSharp.API/Generated/
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi

- name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: update schema definitions to ${{ steps.version.outputs.patch_version }}"
title: "chore: Update Schema Definitions to ${{ steps.version.outputs.patch_version }}"
body: |
This PR was automatically generated by the schema update workflow.

## Changes
- Updated schema definitions from the game server
- Regenerated schema code using `CounterStrikeSharp.SchemaGen`
- Patch Version: `${{ steps.version.outputs.patch_version }}`

---
*This is an automated PR. Please review the changes before merging.*
branch: chore/automated/schema-update
delete-branch: true

- name: No changes detected
if: steps.changes.outputs.has_changes == 'false'
run: echo "::notice::No schema changes detected. No PR will be created."
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env

.ccls-cache/
.cmake/
cmake-build-*/
Expand Down
Binary file added eng/rcon
Binary file not shown.
32 changes: 32 additions & 0 deletions eng/update-schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

HERE=`dirname $0`

set -a
[ -f .env ] && source .env
set +a

set -e
set -u

# Game server RCON details - must come from the environment
: "${GS_HOST:?GS_HOST env var is required}"
: "${GS_PORT:?GS_PORT env var is required}"
: "${GS_PASS:?GS_PASS env var is required}"

# SFTP connection details - must come from the environment
: "${SFTP_HOST:?SFTP_HOST env var is required}"
: "${SFTP_USER:?SFTP_USER env var is required}"
: "${SFTP_PASS:?SFTP_PASS env var is required}"

OUTPUT=$($HERE/rcon -a $GS_HOST:$GS_PORT -p $GS_PASS "dump_schema all")
FILEPATH=$(echo "$OUTPUT" | grep -oP 'Wrote file output to \K.*')
TRIMMED_PATH="${FILEPATH#/home/container}"

lftp -u "$SFTP_USER,$SFTP_PASS" "$SFTP_HOST" <<EOF
set xfer:clobber on
get "$TRIMMED_PATH" -o "$HERE/../managed/CounterStrikeSharp.SchemaGen/Schema/server.json"
bye
EOF

dotnet run --project $HERE/../managed/CounterStrikeSharp.SchemaGen/CounterStrikeSharp.SchemaGen.csproj -- "$HERE/../managed/CounterStrikeSharp.API/Generated/Schema"
Loading