[BE] delete GHA generated workflow files before regen (#63148)
authorRong Rong (AI Infra) <rongr@fb.com>
Thu, 12 Aug 2021 21:40:29 +0000 (14:40 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 12 Aug 2021 21:43:00 +0000 (14:43 -0700)
Summary:
Unlike circle which all workflow goes in one file, GHA legacy generated files will stay silently in once's PR. e.g. when we change build_environment name and that's not ideal.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/63148

Reviewed By: bdhirsh

Differential Revision: D30283382

Pulled By: walterddr

fbshipit-source-id: ffdd5bf9561dd38499052855a12ee5cf838a20b0

.github/scripts/generate_ci_workflows.py

index b5e1075..6faa27c 100755 (executable)
@@ -6,6 +6,7 @@ from typing import Dict, Set
 
 import jinja2
 import json
+import os
 from typing_extensions import Literal
 
 YamlShellBool = Literal["''", 1]
@@ -445,6 +446,14 @@ if __name__ == "__main__":
         (jinja_env.get_template("windows_ci_workflow.yml.j2"), WINDOWS_WORKFLOWS),
         (jinja_env.get_template("bazel_ci_workflow.yml.j2"), BAZEL_WORKFLOWS),
     ]
+    # Delete the existing generated files first, this should align with .gitattributes file description.
+    existing_workflows = GITHUB_DIR.glob("workflows/generated-*")
+    for w in existing_workflows:
+        try:
+            os.remove(w)
+        except Exception as e:
+            print(f"Error occurred when deleting file {w}: {e}")
+
     ciflow_ruleset = CIFlowRuleset()
     for template, workflows in template_and_workflows:
         for workflow in workflows: