]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Scheduled fuzzing: Merge and push pack the corpus (#4313)
authorTerry Burton <tez@terryburton.co.uk>
Fri, 12 Nov 2021 23:19:34 +0000 (23:19 +0000)
committerGitHub <noreply@github.com>
Fri, 12 Nov 2021 23:19:34 +0000 (18:19 -0500)
.github/workflows/ci-scheduled-fuzzing.yml
scripts/ci/commit_lfs_file_update.py [new file with mode: 0644]

index 5e8717517d367ebff11e74e3983afcc8dd73b157..8eb83fadfb2f8cdda410e7ef032db1343441400d 100644 (file)
@@ -144,7 +144,9 @@ jobs:
         path: .git/lfs
         key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1
 
-    # Now the LFS pull will be local if we hit the cache, or remote otherwise
+    #
+    #  Now the LFS pull will be local if we hit the cache, or remote otherwise
+    #
     - name: Git LFS pull
       run: git lfs pull
 
@@ -183,11 +185,13 @@ jobs:
         pcre-config --libs-posix --version 2>/dev/null || :
         pcre2-config --libs-posix --version 2>/dev/null || :
 
-    # We walk up the tree if necessary to find a commit that builds so that we
-    # will fuzz something
     #
-    # When we find a working commit we run the unit tests to create seed data
-    # from the latest versions of the unit tests.
+    #  We walk up the tree if necessary to find a commit that builds so that we
+    #  will fuzz something
+    #
+    #  When we find a working commit we run the unit tests to create seed data
+    #  from the latest versions of the unit tests.
+    #
     - name: Find a commit that builds
       id: pick_commit
       run: |
@@ -230,3 +234,25 @@ jobs:
         path: build/fuzzer
         retention-days: 30
       if: ${{ failure() }}
+
+    #
+    #  Merge and push back the corpus
+    #
+    #  We can push the LFS file directly, but we must use the GitHub API to
+    #  create the actual commit due to the "signed-commits" branch protection
+    #  rule for the master branch.
+    #
+    - name: Push back the merged corpus
+      run: |
+        make test.fuzzer.$PROTOCOL.merge
+        export FILE=src/tests/fuzzer-corpus/$PROTOCOL.tar
+        if ! git diff --exit-code "$FILE"; then
+          pip install PyGithub
+          git add "$FILE"
+          OID="$(git lfs ls-files -l -I "$FILE" | cut -f1 -d ' ')"
+          git lfs push --object-id origin "$OID"
+          export CONTENTS="$(git show ":$FILE")"
+          python3 scripts/ci/commit_lfs_file_update.py
+        fi
+      env:
+        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
diff --git a/scripts/ci/commit_lfs_file_update.py b/scripts/ci/commit_lfs_file_update.py
new file mode 100644 (file)
index 0000000..4a088df
--- /dev/null
@@ -0,0 +1,24 @@
+#
+#  Called from the ci-scheduled-fuzzing.yml workflow to push back the merged
+#  fuzzer corpus
+#
+
+import os
+
+from github import Github
+
+repo_env = os.environ["GITHUB_REPOSITORY"]
+branch_env = os.environ["GITHUB_REF"]
+token_env = os.environ["GITHUB_TOKEN"]
+
+filename = os.environ["FILE"]
+contents = os.environ["CONTENTS"]
+
+print("About to commit update of " + filename + " to " + repo_env + ":" + branch_env)
+
+gh = Github(token_env)
+repo = gh.get_repo(repo_env)
+fc = repo.get_contents(filename, branch_env)
+repo.update_file(fc.path, "Scheduled fuzzing: Update " + fc.path, contents, fc.sha, branch=branch_env)
+
+print("Committed")