Explorar o código

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.
Daniel Gibbs hai 1 mes
pai
achega
3a56a6cef3

+ 6 - 0
.github/scripts/details-check-generate-matrix.sh

@@ -8,6 +8,12 @@ echo -n "\"include\":[" >> "shortnamearray.json"
 
 
 while read -r line; do
 while read -r line; do
 	shortname=$(echo "$line" | awk -F, '{ print $1 }')
 	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
 	export shortname
 	servername=$(echo "$line" | awk -F, '{ print $2 }')
 	servername=$(echo "$line" | awk -F, '{ print $2 }')
 	export servername
 	export servername

+ 81 - 5
.github/workflows/details-check.yml

@@ -5,6 +5,9 @@ on:
   push:
   push:
     branches:
     branches:
       - develop
       - develop
+  pull_request:
+    branches:
+      - develop
 
 
 permissions:
 permissions:
   contents: read
   contents: read
@@ -25,15 +28,56 @@ jobs:
       - name: Checkout
       - name: Checkout
         uses: actions/checkout@v6
         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
       - 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
       - name: Set Matrix
         id: set-matrix
         id: set-matrix
         run: |
         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:
   details-check:
     if: github.repository_owner == 'GameServerManagers'
     if: github.repository_owner == 'GameServerManagers'
@@ -50,8 +94,14 @@ jobs:
       - name: Download linuxgsm.sh
       - name: Download linuxgsm.sh
         run: wget "https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/${LGSM_REF}/linuxgsm.sh"; chmod +x 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
       - 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
       - name: Create serverfiles directory
         run: mkdir -p serverfiles
         run: mkdir -p serverfiles
@@ -91,10 +141,36 @@ jobs:
         run: grep "startparameters" lgsm/config-default/config-lgsm/${{ matrix.shortname }}server/_default.cfg
         run: grep "startparameters" lgsm/config-default/config-lgsm/${{ matrix.shortname }}server/_default.cfg
 
 
       - name: Details
       - name: Details
+        id: details
         run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server details
         run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server details
 
 
       - name: Detect details
       - name: Detect details
+        id: detect-details
         run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server parse-game-details
         run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server parse-game-details
 
 
       - name: Query Raw
       - name: Query Raw
+        id: query-raw
         run: LGSM_GITHUBBRANCH="${LGSM_REF}" ./${{ matrix.shortname }}server 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"