stdlib/fedora: Use grep -F when matching %fedora-rebuild-name
[goals.git] / stdlib / fedora.gl
index f4106bc..a9f43ed 100644 (file)
 # detect if a rebuild has been attempted before in this run.
 # eg. "Perl 5.99 rebuild"
 #
+# %fedora-retry-failed:
+# If set to 1 then failed builds are retried automatically.
+# If set to 0 then failed builds must be manually restarted.
+# Normally you want this to be 0.
+#
 # %fedora-source-packages:
 # List of source packages that will be rebuilt.
 #
@@ -56,9 +61,14 @@ predicate is-koji-built (pkg) = {
         if [ %pkg = "$p" ]; then exit 0; fi
     done
 
-    # If the specfile doesn't have the magic string then the
-    # package definitely needs to be rebuilt.
-    grep -sq %fedora-rebuild-name $specfile || exit 99
+    if ! grep -sq "^%%autochangelog" $specfile; then
+        # If the specfile doesn't have the magic string then the
+        # package definitely needs to be rebuilt.
+        grep -sqF %fedora-rebuild-name $specfile || exit 99
+    else
+        # Using autochangelog.
+        git log | grep -sqF %fedora-rebuild-name || exit 99
+    fi
 
     # Else we must check Koji itself.
     # Koji sends some messages to stderr.
@@ -77,8 +87,13 @@ predicate is-koji-built (pkg) = {
         # Complete so we don't need to rebuild.
         exit 0 ;;
     FAILED)
-        # Failed builds must be examined and fixed manually.
-        exit 1 ;;
+        if [ %fedora-retry-failed -ne 0 ]; then
+            # Resubmit it automatically.
+            exit 99
+        else
+            # Fail, must be examined and retried manually.
+            exit 1
+        fi ;;
     BUILDING)
         # Cancel the build, we will resubmit it.
         koji cancel $taskid ||:
@@ -103,6 +118,7 @@ is-koji-built ("%pkg") :
     # before we can start the new build.
     for p in %<; do
         nvr=$(koji --quiet latest-build %fedora-tag $p | awk '{print $1}')
+        test -n "$nvr" || exit 1
         while ! koji wait-repo --timeout=10000 %fedora-tag --build=$nvr; do sleep 1m; done
     done
 
@@ -111,21 +127,33 @@ is-koji-built ("%pkg") :
     # would need to be corrected/integrated by hand.
     git pull
 
-    # If we're not building for Rawhide then we must use the rightmost
-    # (-r) flag so there's an upgrade path to Rawhide.
-    rightmost=
-    if test %fedora-branch != "rawhide"; then rightmost=-r; fi
+    # Add the new commit.
+    if ! grep -sq "^%%autochangelog" $specfile; then
+        # If we're not building for Rawhide then we must use the
+        # rpmdev-bumpspec rightmost (-r) flag so there's an upgrade
+        # path to Rawhide.
+        rightmost=
+        if test %fedora-branch != "rawhide"; then rightmost=-r; fi
+
+        # If the specfile doesn't have the magic string then add
+        # that now.
+        if ! grep -sqF %fedora-rebuild-name $specfile; then
+            rpmdev-bumpspec -c "- "%fedora-rebuild-name $rightmost *.spec
+        else
+            rpmdev-bumpspec -c "- Bump release and rebuild" $rightmost *.spec
+        fi
 
-    # If the specfile doesn't have the magic string then add
-    # that now.
-    if ! grep -sq %fedora-rebuild-name $specfile; then
-        rpmdev-bumpspec -c "- "%fedora-rebuild-name $rightmost *.spec
+        fedpkg commit -c
     else
-        rpmdev-bumpspec -c "- Bump release and rebuild." $rightmost *.spec
+        # Using autochangelog.
+        if ! git log | grep -sqF %fedora-rebuild-name; then
+            git commit --allow-empty -m %fedora-rebuild-name
+        else
+            git commit --allow-empty -m "Bump release and rebuild"
+        fi
     fi
 
-    # Commit and push the change.
-    fedpkg commit -c
+    # Push the new commit.
     fedpkg push
 
     # Do the Koji build in the side tag.