From f53b34c171ce1abd18bf4a9e5abbd342aab6befe Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Fri, 28 Oct 2022 14:44:58 +1100
Subject: [PATCH] infra-prod: Move project-config reset into base-jobs

Currently we reset trees to master in two places; here and in
sync-project-config (Ib999731fe132b1e9f197e51d74066fa75cb6c69b).  This
is a bit confusing, and requires delegating tasks to the bridge node
which isn't great.  Also, as we think about trying to make jobs run in
parallel it's another place to get things wrong.

This merges the update into one place.

Change-Id: I6ffeb6e6562fb34db89f4e475da27b60e30f6fe7
---
 playbooks/infra-prod/setup-src.yaml | 30 +++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/playbooks/infra-prod/setup-src.yaml b/playbooks/infra-prod/setup-src.yaml
index 557aa39..1738140 100644
--- a/playbooks/infra-prod/setup-src.yaml
+++ b/playbooks/infra-prod/setup-src.yaml
@@ -24,16 +24,30 @@
       include_role:
         name: prepare-workspace-git
 
-    # When running from periodic/hourly we want to explicitly override
-    # to run from the tip of master
+    # The intent of the periodic jobs is to run with latest master. If
+    # they get enqueued, then other patches land, they'll still run
+    # with the value of the zuul ref from when they were
+    # enqueued. That's not what we want for prod, as it can lead to
+    # running or deploying old versions of config files.  Reset them
+    # to master.
     - name: Should we run from master
       set_fact:
         infra_prod_run_from_master: "{{ zuul.pipeline|default('') in ['periodic', 'opendev-prod-hourly'] }}"
 
-    - name: Update from master
+    - name: Reset checkouts to master for periodic jobs
       when: infra_prod_run_from_master|bool
-      git:
-        repo: https://opendev.org/opendev/system-config
-        dest: /home/zuul/src/opendev.org/opendev/system-config
-        force: yes
-        version: master
+      block:
+        - name: Update system-config from master
+          git:
+            repo: 'https://opendev.org/opendev/system-config'
+            dest: '/home/zuul/src/opendev.org/opendev/system-config'
+            force: yes
+            version: 'master'
+
+        - name: Update project-config from master
+          when: '"opendev.org/openstack/project-config" in zuul.projects'
+          git:
+            repo: 'https://opendev.org/openstack/project-config'
+            dest: '/home/zuul/src/opendev.org/openstack/project-config'
+            force: yes
+            version: 'master'