diff --git a/.github/workflows/optional-modifications.yml b/.github/workflows/optional-modifications.yml new file mode 100644 index 0000000000..4cc8c3001b --- /dev/null +++ b/.github/workflows/optional-modifications.yml @@ -0,0 +1,75 @@ +name: Optional Modifications + +on: + workflow_dispatch: + schedule: + - cron: "0 0 */7 * *" + pull_request: + paths: + - "optional-modifications/**" + - ".github/workflows/optional-modifications.yml" + +concurrency: + group: self-hosted-optional-modifications + cancel-in-progress: true + +defaults: + run: + shell: bash + +jobs: + test-apply-patch: + name: Test Apply Patch + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + 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 "Checking for existing issue for $patch_file" + patch_base_file_name=$(basename "$patch_file" .patch) + 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 + 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 "Creating issue for $patch_dir" + gh issue create --title "$issue_title" --body "${issue_body[*]}" + fi + fi + + echo "::debug::Reset the repository state" + git reset --hard + + echo "::endgroup::" + done