From 3a56a6cef35e15e8883a9d14d62308d82b295657 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 4 May 2026 11:03:30 +0100 Subject: [PATCH] chore(actions): Optimize details-check workflow for PRs Enhances the `details-check` workflow to run more efficiently on pull requests. This commit introduces logic to: - Trigger the workflow on pull requests to the `develop` branch. - Analyze changed files to determine the scope of the checks required: - Run a full matrix if core `details`-related scripts are modified. - Run a targeted matrix only for servers whose `config-lgsm` files are changed. - Skip the check entirely if no relevant files are touched. - Provide a concise summary of the `details`, `parse-game-details`, and `query-raw` outcomes directly in the GitHub Actions job summary. This optimization significantly reduces CI/CD run times and resource consumption for pull requests by avoiding unnecessary checks across all game servers, improving developer efficiency. --- .../scripts/details-check-generate-matrix.sh | 6 ++ .github/workflows/details-check.yml | 86 +++++++++++++++++-- 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/.github/scripts/details-check-generate-matrix.sh b/.github/scripts/details-check-generate-matrix.sh index 1093a46cf..eff7d5416 100755 --- a/.github/scripts/details-check-generate-matrix.sh +++ b/.github/scripts/details-check-generate-matrix.sh @@ -8,6 +8,12 @@ echo -n "\"include\":[" >> "shortnamearray.json" while read -r line; do shortname=$(echo "$line" | awk -F, '{ print $1 }') + # If TARGETED_SHORTNAMES is set, skip servers not in the list + if [ -n "${TARGETED_SHORTNAMES:-}" ]; then + if ! echo "${TARGETED_SHORTNAMES}" | grep -qw "${shortname}"; then + continue + fi + fi export shortname servername=$(echo "$line" | awk -F, '{ print $2 }') export servername diff --git a/.github/workflows/details-check.yml b/.github/workflows/details-check.yml index 2c3d858d6..d4f7f644f 100644 --- a/.github/workflows/details-check.yml +++ b/.github/workflows/details-check.yml @@ -5,6 +5,9 @@ on: push: branches: - develop + pull_request: + branches: + - develop permissions: contents: read @@ -25,15 +28,56 @@ jobs: - name: Checkout uses: actions/checkout@v6 + - name: Detect targeted servers (PR only) + id: targeted + if: github.event_name == 'pull_request' + run: | + changed=$(git diff --name-only origin/${{ github.base_ref }}...HEAD) + echo "Changed files:" + echo "$changed" + + # Only these modules directly affect what 'details', 'parse-game-details' + # and 'query-raw' output. Everything else (install, fix, update, check_*, + # data CSVs, game icons, etc.) is irrelevant to this check. + details_core='^(linuxgsm\.sh|lgsm/modules/(info_game|info_messages|command_details|command_dev_parse_game_details|command_dev_query_raw|core_modules)\.sh)$' + if echo "$changed" | grep -qE "${details_core}"; then + echo "Details-relevant core file changed — using full matrix." + echo "mode=full" >> "$GITHUB_OUTPUT" + else + # Extract shortnames from changed config-lgsm paths + shortnames=$(echo "$changed" \ + | grep -oE 'lgsm/config-default/config-lgsm/[a-z0-9]+server' \ + | sed 's|lgsm/config-default/config-lgsm/||;s|server$||' \ + | sort -u) + if [ -z "$shortnames" ]; then + echo "No server configs or core files changed — skipping matrix." + echo "mode=skip" >> "$GITHUB_OUTPUT" + else + echo "Targeted servers: $shortnames" + echo "mode=targeted" >> "$GITHUB_OUTPUT" + printf '%s\n' $shortnames > targeted_shortnames.txt + fi + fi + - name: Generate matrix with generate-matrix.sh - run: .github/scripts/details-check-generate-matrix.sh + if: github.event_name != 'pull_request' || steps.targeted.outputs.mode != 'skip' + run: | + if [ -f targeted_shortnames.txt ]; then + TARGETED_SHORTNAMES=$(cat targeted_shortnames.txt) .github/scripts/details-check-generate-matrix.sh + else + .github/scripts/details-check-generate-matrix.sh + fi - name: Set Matrix id: set-matrix run: | - shortnamearray=$(cat shortnamearray.json) - echo "${shortnamearray}" - echo -n "matrix=${shortnamearray}" >> "$GITHUB_OUTPUT" + if [ ! -f shortnamearray.json ]; then + echo 'matrix={"include":[]}' >> "$GITHUB_OUTPUT" + else + shortnamearray=$(cat shortnamearray.json) + echo "${shortnamearray}" + echo -n "matrix=${shortnamearray}" >> "$GITHUB_OUTPUT" + fi details-check: if: github.repository_owner == 'GameServerManagers' @@ -50,8 +94,14 @@ jobs: - name: Download linuxgsm.sh run: wget "https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/${LGSM_REF}/linuxgsm.sh"; chmod +x linuxgsm.sh + - name: Cache apt packages + uses: actions/cache@v4 + with: + path: /var/cache/apt/archives + key: apt-${{ runner.os }}-libxml2-utils-jq + - name: Install dependencies - run: sudo apt-get install libxml2-utils jq + run: sudo apt-get install -y --no-install-recommends libxml2-utils jq - name: Create serverfiles directory run: mkdir -p serverfiles @@ -91,10 +141,36 @@ jobs: run: grep "startparameters" lgsm/config-default/config-lgsm/${{ matrix.shortname }}server/_default.cfg - name: Details + id: details run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server details - name: Detect details + id: detect-details run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server parse-game-details - name: Query Raw + id: query-raw run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server query-raw + + - name: Write job summary + if: always() + run: | + status_icon() { + case "$1" in + success) echo "✅" ;; + failure) echo "❌" ;; + skipped) echo "⏭️" ;; + *) echo "⚠️" ;; + esac + } + details_icon=$(status_icon "${{ steps.details.outcome }}") + parse_icon=$(status_icon "${{ steps.detect-details.outcome }}") + query_icon=$(status_icon "${{ steps.query-raw.outcome }}") + { + echo "## ${{ matrix.shortname }}server" + echo "| Step | Result |" + echo "|------|--------|" + echo "| Details | ${details_icon} ${{ steps.details.outcome }} |" + echo "| Parse game details | ${parse_icon} ${{ steps.detect-details.outcome }} |" + echo "| Query raw | ${query_icon} ${{ steps.query-raw.outcome }} |" + } >> "$GITHUB_STEP_SUMMARY"