From 51cf17e9d192d22546c4df097536107992bef024 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 09:25:04 +0700 Subject: [PATCH 1/9] test: run patch tests for optional modifications Right now we don't know if it's broken, this tests will cover that issue --- .github/workflows/optional-modifications.yml | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/optional-modifications.yml diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml new file mode 100644 index 0000000000..9b027e4690 --- /dev/null +++ b/.github/workflows/optional-modifications.yml @@ -0,0 +1,69 @@ +name: Optional Modifications + +on: + # NOTE(reinaldy): This `pull_request` trigger should be removed once we have it tested on the PR. + pull_request: + workflow_dispatch: + schedule: + - cron: "0 0 */7 * *" + +concurrency: + group: ${{ github.ref_name || github.sha }} + cancel-in-progress: true + +defaults: + run: + shell: bash + +jobs: + test-apply-patch: + name: Test Apply Patch + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Apply patches + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -e + + # For each directory in `optional-modifications/patches/`, we will try to execute: + # `patch < optional-modifications/patches//.patch` + # with `` being the name of the file in the directory that we loop through. + # + # If the patch fails, we will open a GitHub issue with the failing patch file. + # To prevent so many issues created, we will check first whether there is already + # an issue open with the same patch `` (without the file name). + + for patch_dir in optional-modifications/patches/*; do + echo "::group::Checking for existing issue for $patch_dir" + + issue_title="[Optional Modification Failure] $patch_dir" + issue_body=("Failure during applying patches for $patch_dir:") + + for patch_file in "$patch_dir"/*.patch; do + echo "::debug::Checking for existing issue for $patch_file" + patch_base_file_name=$(basename "$patch_file" .patch) + if ! patch -f --dry-run < "$patch_file"; then + problem=$(patch -f --dry-run < "$patch_file") + issue_body+=($problem) + echo "::error::Patch $patch_file failed to apply" + fi + done + + # If the length of `issue_body` array is greater than 1, + # then we have a problem and we need to open an issue. + if [ "${#issue_body[@]}" -gt 1 ]; then + issue_exists=$(gh issue list --search "$issue_title in:title" --state open --json title --jq 'if length == 0 then empty end') + if [ -z "$issue_exists" ]; then + echo "::debug::Creating issue for $patch_dir" + gh issue create --title "$issue_title" --body "${issue_body[*]}" + fi + + echo "::debug::Reset the repository state" + git reset --hard + + echo "::endgroup::" + done From dc9ea6d4bca202765d7c6520b953b35c13828ac2 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 09:26:08 +0700 Subject: [PATCH 2/9] ci: wrong concurrency rule --- .github/workflows/optional-modifications.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index 9b027e4690..a74ff5f178 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -8,7 +8,7 @@ on: - cron: "0 0 */7 * *" concurrency: - group: ${{ github.ref_name || github.sha }} + group: self-hosted-optional-modifications cancel-in-progress: true defaults: From 9a4cd1fab4223dca117e2f674875c06877ceccc5 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 09:39:09 +0700 Subject: [PATCH 3/9] Potential fix for code scanning alert no. 11: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/optional-modifications.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index a74ff5f178..a3d97c28a9 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -19,6 +19,9 @@ jobs: test-apply-patch: name: Test Apply Patch runs-on: ubuntu-latest + permissions: + contents: read + issues: write steps: - name: Checkout uses: actions/checkout@v4 From 6792bfc15a515065669f556a858fc69d421a8a8b Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 09:40:13 +0700 Subject: [PATCH 4/9] fix: missing end if block --- .github/workflows/optional-modifications.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index a3d97c28a9..824a6a625c 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -63,6 +63,7 @@ jobs: if [ -z "$issue_exists" ]; then echo "::debug::Creating issue for $patch_dir" gh issue create --title "$issue_title" --body "${issue_body[*]}" + fi fi echo "::debug::Reset the repository state" From b2ed6b42fe17df257eaa40828e8f65f1d146db29 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 09:48:32 +0700 Subject: [PATCH 5/9] ci: patch should be silent --- .github/workflows/optional-modifications.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index 824a6a625c..d3c5a02965 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -47,9 +47,9 @@ jobs: issue_body=("Failure during applying patches for $patch_dir:") for patch_file in "$patch_dir"/*.patch; do - echo "::debug::Checking for existing issue for $patch_file" + echo "Checking for existing issue for $patch_file" patch_base_file_name=$(basename "$patch_file" .patch) - if ! patch -f --dry-run < "$patch_file"; then + if ! patch -s -f --dry-run < "$patch_file"; then problem=$(patch -f --dry-run < "$patch_file") issue_body+=($problem) echo "::error::Patch $patch_file failed to apply" @@ -61,7 +61,7 @@ jobs: if [ "${#issue_body[@]}" -gt 1 ]; then issue_exists=$(gh issue list --search "$issue_title in:title" --state open --json title --jq 'if length == 0 then empty end') if [ -z "$issue_exists" ]; then - echo "::debug::Creating issue for $patch_dir" + echo "Creating issue for $patch_dir" gh issue create --title "$issue_title" --body "${issue_body[*]}" fi fi From f7236de25f97a255b108235e644cdc0fccab09f9 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 10:20:24 +0700 Subject: [PATCH 6/9] fix: use -p0 flag --- .github/workflows/optional-modifications.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index d3c5a02965..e4d1234bba 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -49,8 +49,8 @@ jobs: for patch_file in "$patch_dir"/*.patch; do echo "Checking for existing issue for $patch_file" patch_base_file_name=$(basename "$patch_file" .patch) - if ! patch -s -f --dry-run < "$patch_file"; then - problem=$(patch -f --dry-run < "$patch_file") + if ! patch -p0 -s -f --dry-run < "$patch_file"; then + problem=$(patch -p0 -f --dry-run < "$patch_file") issue_body+=($problem) echo "::error::Patch $patch_file failed to apply" fi From 1bfe1134d0549127988c6d3a4e5961a0fca70a9b Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 10:52:12 +0700 Subject: [PATCH 7/9] ci: remove pull_request event trigger --- .github/workflows/optional-modifications.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index e4d1234bba..f0ba666570 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -1,8 +1,6 @@ name: Optional Modifications on: - # NOTE(reinaldy): This `pull_request` trigger should be removed once we have it tested on the PR. - pull_request: workflow_dispatch: schedule: - cron: "0 0 */7 * *" From b2ba39f0a198596fbcb1eb92ed4adff20ce15f1d Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 16:48:52 +0700 Subject: [PATCH 8/9] ci: run optional-modifications job on directory changes --- .github/workflows/optional-modifications.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index f0ba666570..b7e2bc64cc 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -4,6 +4,9 @@ on: workflow_dispatch: schedule: - cron: "0 0 */7 * *" + pull_request: + paths: + - "optional-modifications/**" concurrency: group: self-hosted-optional-modifications From 711dd84252ff0f86797f49ec04fe5edc041a57d2 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 8 Jul 2025 16:50:15 +0700 Subject: [PATCH 9/9] ci: run optional-modifications job on GHA file changes --- .github/workflows/optional-modifications.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml index b7e2bc64cc..4cc8c3001b 100644 --- a/.github/workflows/optional-modifications.yml +++ b/.github/workflows/optional-modifications.yml @@ -7,6 +7,7 @@ on: pull_request: paths: - "optional-modifications/**" + - ".github/workflows/optional-modifications.yml" concurrency: group: self-hosted-optional-modifications