From b2168fe9a224d2b0686a4c2f09a5ac4724a1e1d8 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 16 Jul 2024 11:12:16 -0600 Subject: [PATCH] Add contrib template --- .../src/generate_workflows_lib/__init__.py | 57 ++++++++++++++++++- .../src/generate_workflows_lib/contrib.yml.j2 | 46 +++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/generate_workflows_lib/src/generate_workflows_lib/contrib.yml.j2 diff --git a/.github/workflows/generate_workflows_lib/src/generate_workflows_lib/__init__.py b/.github/workflows/generate_workflows_lib/src/generate_workflows_lib/__init__.py index afc6bbce62..11e1341228 100644 --- a/.github/workflows/generate_workflows_lib/src/generate_workflows_lib/__init__.py +++ b/.github/workflows/generate_workflows_lib/src/generate_workflows_lib/__init__.py @@ -134,6 +134,47 @@ def get_lint_jobs_data(tox_envs: list) -> list: return lint_jobs_data +def get_contrib_jobs_data(tox_envs: list) -> list: + + contrib_jobs_data = [] + + tox_contrib_env_regex = re_compile( + r"py38-contrib-(?P[-\w]+\w)-?(?P\d+)?" + ) + + for tox_env in tox_envs: + + tox_contrib_env_match = tox_contrib_env_regex.match(tox_env) + + if tox_contrib_env_match is None: + continue + + groups = tox_contrib_env_match.groupdict() + + tox_env = tox_contrib_env_match.string + + contrib_requirements = groups["contrib_requirements"] + + if contrib_requirements is None: + contrib_requirements = " " + + else: + contrib_requirements = f"-{contrib_requirements} " + + contrib_jobs_data.append( + { + "ui_name": ( + f"{groups['name']}" + f"{contrib_requirements}" + ), + "tox_env": tox_env, + } + + ) + + return contrib_jobs_data + + def generate_test_workflow( tox_ini_path: Path, workflow_directory_path: Path, @@ -178,4 +219,18 @@ def generate_lint_workflow( def generate_contrib_workflow( workflow_directory_path: Path, ) -> None: - return get_tox_envs(Path(__file__).parent.joinpath("tox.ini")) + + with ( + open(workflow_directory_path.joinpath("contrib.yml"), "w") as + contrib_yml_file + ): + contrib_yml_file.write( + Environment( + loader=FileSystemLoader(Path(__file__).parent) + ).get_template("contrib.yml.j2").render( + jobs=get_contrib_jobs_data( + get_tox_envs(Path(__file__).parent.joinpath("tox.ini")) + ) + ) + ) + contrib_yml_file.write("\n") diff --git a/.github/workflows/generate_workflows_lib/src/generate_workflows_lib/contrib.yml.j2 b/.github/workflows/generate_workflows_lib/src/generate_workflows_lib/contrib.yml.j2 new file mode 100644 index 0000000000..09facecde0 --- /dev/null +++ b/.github/workflows/generate_workflows_lib/src/generate_workflows_lib/contrib.yml.j2 @@ -0,0 +1,46 @@ +# Do not edit this file. +# This file is generated automatically by executing tox -e generate_workflows + +name: Contrib + +on: + push: + branches-ignore: + - 'release/*' + pull_request: +env: + CONTRIB_REPO_SHA: 141a6a2e473ef7f0ec4915dfb71e3c0fa595283e + CORE_REPO_SHA: ${% raw %}{{ github.sha }}{% endraw %} + PIP_EXISTS_ACTION: w + +jobs: + {%- for job in jobs %} + + {{ job.tox_env }}: + name: {{ job.ui_name }} + runs-on: ubuntu-latest + steps: + - name: Checkout Contrib Repo @ SHA - ${{% raw %}{ env.CONTRIB_REPO_SHA }}{% endraw %} + uses: actions/checkout@v4 + with: + repository: open-telemetry/opentelemetry-python-contrib + ref: ${{ env.CONTRIB_REPO_SHA }}}} + + - name: Checkout Core Repo @ SHA - ${% raw %}{{ github.sha }}{% endraw %} + uses: actions/checkout@v4 + with: + repository: open-telemetry/opentelemetry-python + path: opentelemetry-python-core + + - name: Set up Python 3.8 + uses: actions/setup-python@v5 + with: + python-version: "3.8" + architecture: "x64" + + - name: Install tox + run: pip install tox + + - name: Run tests + run: tox -e {{ job.tox_env }} -- -ra + {%- endfor %}