Repository: open-telemetry/opentelemetry-python-contrib

Issue:
Automate release workflow
Similar to [this](https://github.com/open-telemetry/opentelemetry-python/pull/2649) for the core repo, automate the release workflow for contrib. This might be a bit tricky if we want to still require builds needing to pass for release branches (since the whole relationship between the core and contrib releases needing to change SHAs). We can either 1. Not require builds to pass for releases or 2. Change the SHAs automatically as part of the release workflow.

@srikanthccv @ocelotl 


Discussion:
@lzchen, here is what I am thinking about updating the SHAs. We will create a new workflow that runs a script to update the SHA automatically. This script takes the branch name for core/contrib and updates `test.yaml` with the latest commit ID. First, we will let the bot create the release branches and then run another workflow to update SHA. What do you think?
@srikanthccv 

Would a new PR be created to update the SHA on the release branches or will that automatically be done committed?
The way I was thinking was the prepare-release workflow creates PRs in core and contrib. And then you would add a label `update-sha` which runs another workflow, and the bot updates the SHA for its corresponding core/contrib repo.
Adding a label makes sense to me. So the flow for maintainers when releasing would be:

1. Run release workflow for core, 2 PRs will be created (one against the release branch, one against main)
2. Run release workflow for contrib (when we automate it eventually), 2 PRS will be created as well
3. Add `update-sha` label to core repo release branch PR, OT bot will pull the latest SHA from contrib release branch PR and update `test.yml`. Builds should pass now for core.
4. Add `update-sha` label to contrib repo release branch PR, OT bot will pull the latest SHA from core release branch PR and update `test.yml`. Builds should pass now for contrib.
5. Merge both PRs.
6. Run release workflow and continue the workflow as [is](https://github.com/open-telemetry/opentelemetry-python/blob/main/RELEASING.md#making-the-release)

Resolving patch:
diff --git a/scripts/generate_instrumentation_metapackage.py b/scripts/generate_instrumentation_metapackage.py
--- a/scripts/generate_instrumentation_metapackage.py
+++ b/scripts/generate_instrumentation_metapackage.py
@@ -71,7 +71,9 @@ def main():
         root_path, "opentelemetry-contrib-instrumentations", "pyproject.toml"
     )
 
-    deps = [f"{pkg}=={version}" for pkg, version in dependencies]
+    deps = [
+        f"{pkg.strip()}=={version.strip()}" for pkg, version in dependencies
+    ]
     with open(pyproject_toml_path, "rb") as file:
         pyproject_toml = tomli.load(file)
 
diff --git a/scripts/update_sha.py b/scripts/update_sha.py
new file mode 100644
--- /dev/null
+++ b/scripts/update_sha.py
@@ -0,0 +1,60 @@
+# Copyright The OpenTelemetry Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# pylint: disable=import-error,unspecified-encoding
+
+import argparse
+
+import requests
+from ruamel.yaml import YAML
+
+API_URL = (
+    "https://api.github.com/repos/open-telemetry/opentelemetry-python/commits/"
+)
+WORKFLOW_FILE = ".github/workflows/test.yml"
+
+
+def get_sha(branch):
+    url = API_URL + branch
+    response = requests.get(url)
+    response.raise_for_status()
+    return response.json()["sha"]
+
+
+def update_sha(sha):
+    yaml = YAML()
+    yaml.preserve_quotes = True
+    with open(WORKFLOW_FILE, "r") as file:
+        workflow = yaml.load(file)
+    workflow["env"]["CORE_REPO_SHA"] = sha
+    with open(WORKFLOW_FILE, "w") as file:
+        yaml.dump(workflow, file)
+
+
+def main():
+    args = parse_args()
+    sha = get_sha(args.branch)
+    update_sha(sha)
+
+
+def parse_args():
+    parser = argparse.ArgumentParser(
+        description="Updates the SHA in the workflow file"
+    )
+    parser.add_argument("-b", "--branch", help="branch to use")
+    return parser.parse_args()
+
+
+if __name__ == "__main__":
+    main()


Test patch: