From d0527474bb7a06ec483e18ca45ce3ac2067053c0 Mon Sep 17 00:00:00 2001 From: tintinhamans <5984296+tintinhamans@users.noreply.github.com> Date: Thu, 10 Apr 2025 21:16:00 +0200 Subject: [PATCH 1/3] [GITHUB] Remove "[BUG]: " from title in issue template --- .github/ISSUE_TEMPLATE/{bug_report.yaml => bug-report.yaml} | 1 - 1 file changed, 1 deletion(-) rename .github/ISSUE_TEMPLATE/{bug_report.yaml => bug-report.yaml} (98%) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug-report.yaml similarity index 98% rename from .github/ISSUE_TEMPLATE/bug_report.yaml rename to .github/ISSUE_TEMPLATE/bug-report.yaml index b876198668..5922ddcabd 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug-report.yaml @@ -1,6 +1,5 @@ name: Bug Report description: Report bugs or issues you've encountered while playing the game -title: "[Bug]: " type: Bug labels: [ "Bug", "⚠️ Triage" ] From 023d9faa364e1c17ad4224561f41b0e16da6c74a Mon Sep 17 00:00:00 2001 From: tintinhamans <5984296+tintinhamans@users.noreply.github.com> Date: Fri, 11 Apr 2025 20:51:40 +0200 Subject: [PATCH 2/3] [GITHUB] Add detection of changes in "Core" to CI --- .github/workflows/ci.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40af639454..0f58d9478e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,12 +41,13 @@ jobs: generalsmd: - 'GeneralsMD/**' shared: - - 'Dependencies/**' - - 'cmake/**' + - '.github/workflows/build-toolchain.yml' + - '.github/workflows/ci.yml' - 'CMakeLists.txt' - 'CMakePresets.json' - - ".github/workflows/ci.yml" - - '.github/workflows/build-toolchain.yml' + - 'cmake/**' + - 'Core/**' + - 'Dependencies/**' - name: Changes Summary run: | From 6b133d2f59defb341fe4f2610742c843c44f16f5 Mon Sep 17 00:00:00 2001 From: tintinhamans <5984296+tintinhamans@users.noreply.github.com> Date: Fri, 11 Apr 2025 20:58:45 +0200 Subject: [PATCH 3/3] [GITHUB] Add PR title and commit validation to CI workflow --- .github/workflows/valid-tags.txt | 6 ++ .github/workflows/validate-pull-request.yml | 96 +++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .github/workflows/valid-tags.txt create mode 100644 .github/workflows/validate-pull-request.yml diff --git a/.github/workflows/valid-tags.txt b/.github/workflows/valid-tags.txt new file mode 100644 index 0000000000..253a3b9f53 --- /dev/null +++ b/.github/workflows/valid-tags.txt @@ -0,0 +1,6 @@ +[GEN] +[ZH] +[CMAKE] +[GITHUB] +[CORE] +[LINUX] diff --git a/.github/workflows/validate-pull-request.yml b/.github/workflows/validate-pull-request.yml new file mode 100644 index 0000000000..353b15d6dc --- /dev/null +++ b/.github/workflows/validate-pull-request.yml @@ -0,0 +1,96 @@ +name: Validate Pull Request + +permissions: + contents: read + pull-requests: write + +on: + pull_request: + branches: + - main + types: + - opened + - edited + - synchronize + - reopened + +jobs: + validate-title-and-commits: + name: Validate Title and Commits + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Load valid tags + id: load-tags + run: | + if [ ! -f ./.github/workflows/valid-tags.txt ]; then + echo "::error::.github/workflows/valid-tags.txt file not found" + exit 1 + fi + + echo "**Valid tags**: $(cat ./.github/workflows/valid-tags.txt | tr '\n' ',' | sed 's/,/, /g' | sed 's/, $//')" >> $GITHUB_STEP_SUMMARY + + TAG_REGEX=$(sed 's/[]\/$*.^|[]/\\&/g' ./.github/workflows/valid-tags.txt | paste -sd "|" -) + + # Matches: + # 1) One or more valid tags at the beginning, directly adjacent, followed by at least one space, then text + # 2) Text that does not start with '[' (i.e. no tags) + echo "regex=^((($TAG_REGEX)){1,}[[:space:]]+.*|[^[]+.*)$" >> $GITHUB_OUTPUT + + echo "Built the regex: ^((($TAG_REGEX)){1,}[[:space:]]+.*|[^[]+.*)$" + + - name: Validate PR title + id: validate_title + run: | + echo "### Validate PR Title" >> $GITHUB_STEP_SUMMARY + REGEX="${{ steps.load-tags.outputs.regex }}" + TITLE=$(jq -r '.pull_request.title // "No title found"' "$GITHUB_EVENT_PATH") + + ESCAPED_TITLE=$(echo "$TITLE" | sed 's/["\`\\$]/\\&/g') + + if [[ ! "$TITLE" =~ $REGEX ]]; then + echo "- ❌ PR title \"$ESCAPED_TITLE\" is invalid." >> $GITHUB_STEP_SUMMARY + echo "TITLE_VALID=false" >> $GITHUB_OUTPUT + else + echo "- ✅ PR title \"$ESCAPED_TITLE\" is valid." >> $GITHUB_STEP_SUMMARY + echo "TITLE_VALID=true" >> $GITHUB_OUTPUT + fi + + - name: Validate PR commits + id: validate_commits + run: | + echo "### Validate PR Commits" >> $GITHUB_STEP_SUMMARY + REGEX="${{ steps.load-tags.outputs.regex }}" + git fetch --prune --unshallow origin ${{ github.base_ref }} + COMMITS=$(git log origin/${{ github.base_ref }}..HEAD --pretty=format:"%s" --no-merges) + + INVALID_COMMITS=0 + + while read -r COMMIT_MSG; do + if [[ -z "$COMMIT_MSG" ]]; then + continue + fi + ESCAPED_MSG=$(echo "$COMMIT_MSG" | sed 's/["\`\\$]/\\&/g') + if [[ ! "$COMMIT_MSG" =~ $REGEX ]]; then + echo "- ❌ Commit message \"$ESCAPED_MSG\" is invalid." >> $GITHUB_STEP_SUMMARY + INVALID_COMMITS=$((INVALID_COMMITS+1)) + else + echo "- ✅ Commit message \"$ESCAPED_MSG\" is valid." >> $GITHUB_STEP_SUMMARY + fi + done <<< "$COMMITS" + + if [[ $INVALID_COMMITS -gt 0 ]]; then + echo "COMMITS_VALID=false" >> $GITHUB_OUTPUT + else + echo "COMMITS_VALID=true" >> $GITHUB_OUTPUT + fi + + - name: Validation return code + run: | + if [[ "${{ steps.validate_title.outputs.TITLE_VALID }}" != "true" || "${{ steps.validate_commits.outputs.COMMITS_VALID }}" != "true" ]]; then + exit 1 + fi