diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b138e95482d..e0951b7afd0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ env: # Otherwise, set variable to the commit of your branch on # opentelemetry-python-contrib which is compatible with these Core repo # changes. - CONTRIB_REPO_SHA: ce5dac763790203d68217cd3870b6be5517692fe + CONTRIB_REPO_SHA: 1f0dda9865b3c83e6dea2f2b127a2b0971853543 # This is needed because we do not clone the core repo in contrib builds anymore. # When running contrib builds as part of core builds, we use actions/checkout@v2 which # does not set an environment variable (simply just runs tox), which is different when @@ -29,37 +29,41 @@ jobs: py310: "3.10" py311: "3.11" pypy3: pypy-3.7 - RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }} + RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ + matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false # ensures the entire test matrix is run, even if one permutation fails matrix: - python-version: [ py37, py38, py39, py310, py311, pypy3 ] - package: ["api", "sdk", "semantic", "getting", "shim", "exporter", "protobuf", "propagator"] - os: [ ubuntu-20.04, windows-2019 ] + python-version: [py37, py38, py39, py310, py311, pypy3] + package: ["api", "sdk", "semantic", "getting", "shim", "exporter", "protobuf", + "propagator"] + os: [ubuntu-20.04, windows-2019] steps: - - name: Checkout Core Repo @ SHA - ${{ github.sha }} - uses: actions/checkout@v2 - - name: Set up Python ${{ env[matrix.python-version] }} - uses: actions/setup-python@v2 - with: - python-version: ${{ env[matrix.python-version] }} - architecture: 'x64' - - name: Install tox - run: pip install tox==3.27.1 -U tox-factor - - name: Cache tox environment + - name: Checkout Core Repo @ SHA - ${{ github.sha }} + uses: actions/checkout@v2 + - name: Set up Python ${{ env[matrix.python-version] }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env[matrix.python-version] }} + architecture: 'x64' + - name: Install tox + run: pip install tox==3.27.1 -U tox-factor + - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v2 - with: - path: | - .tox - ~/.cache/pip - key: v3-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core - - name: Windows does not let git check out files with long names - if: ${{ matrix.os == 'windows-2019'}} - run: git config --system core.longpaths true - - name: run tox - run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json + uses: actions/cache@v2 + with: + path: | + .tox + ~/.cache/pip + key: v3-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', + 'dev-requirements.txt') }}-core + - name: Windows does not let git check out files with long names + if: ${{ matrix.os == 'windows-2019'}} + run: git config --system core.longpaths true + - name: run tox + run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ + env.RUN_MATRIX_COMBINATION }}-benchmark.json # - name: Find and merge benchmarks # id: find_and_merge_benchmarks # run: >- @@ -87,29 +91,31 @@ jobs: strategy: fail-fast: false matrix: - tox-environment: [ "docker-tests-proto3", "docker-tests-proto4", "lint", "spellcheck", "docs", "mypy", "mypyinstalled", "tracecontext" ] + tox-environment: ["docker-tests-proto3", "docker-tests-proto4", "lint", "spellcheck", + "docs", "mypy", "mypyinstalled", "tracecontext"] name: ${{ matrix.tox-environment }} runs-on: ubuntu-20.04 steps: - - name: Checkout Core Repo @ SHA - ${{ github.sha }} - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9 - architecture: 'x64' - - name: Install tox - run: pip install tox==3.27.1 - - name: Cache tox environment + - name: Checkout Core Repo @ SHA - ${{ github.sha }} + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9 + architecture: 'x64' + - name: Install tox + run: pip install tox==3.27.1 + - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v2 - with: - path: | - .tox - ~/.cache/pip - key: v3-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core - - name: run tox - run: tox -e ${{ matrix.tox-environment }} + uses: actions/cache@v2 + with: + path: | + .tox + ~/.cache/pip + key: v3-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') + }}-core + - name: run tox + run: tox -e ${{ matrix.tox-environment }} # Contrib unit test suite in order to ensure changes in core do not break anything in contrib. # We only run contrib unit tests on the oldest supported Python version (3.7) as running the same tests @@ -122,34 +128,35 @@ jobs: strategy: fail-fast: false # ensures the entire test matrix is run, even if one permutation fails matrix: - python-version: [ py37 ] + python-version: [py37] package: ["instrumentation", "exporter"] - os: [ ubuntu-20.04] + os: [ubuntu-20.04] steps: - - name: Checkout Contrib Repo @ SHA - ${{ env.CONTRIB_REPO_SHA }} - uses: actions/checkout@v2 - with: - repository: open-telemetry/opentelemetry-python-contrib - ref: ${{ env.CONTRIB_REPO_SHA }} - - name: Checkout Core Repo @ SHA ${{ github.sha }} - uses: actions/checkout@v2 - with: - repository: open-telemetry/opentelemetry-python - path: opentelemetry-python-core - - name: Set up Python ${{ env[matrix.python-version] }} - uses: actions/setup-python@v2 - with: - python-version: ${{ env[matrix.python-version] }} - architecture: 'x64' - - name: Install tox - run: pip install tox==3.27.1 -U tox-factor - - name: Cache tox environment + - name: Checkout Contrib Repo @ SHA - ${{ env.CONTRIB_REPO_SHA }} + uses: actions/checkout@v2 + with: + repository: open-telemetry/opentelemetry-python-contrib + ref: ${{ env.CONTRIB_REPO_SHA }} + - name: Checkout Core Repo @ SHA ${{ github.sha }} + uses: actions/checkout@v2 + with: + repository: open-telemetry/opentelemetry-python + path: opentelemetry-python-core + - name: Set up Python ${{ env[matrix.python-version] }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env[matrix.python-version] }} + architecture: 'x64' + - name: Install tox + run: pip install tox==3.27.1 -U tox-factor + - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v2 - with: - path: | - .tox - ~/.cache/pip - key: v3-tox-cache-${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib - - name: run tox - run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} + uses: actions/cache@v2 + with: + path: | + .tox + ~/.cache/pip + key: v3-tox-cache-${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os + }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib + - name: run tox + run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} diff --git a/.github/workflows/update-sha.yml b/.github/workflows/update-sha.yml new file mode 100644 index 00000000000..0a983a7e804 --- /dev/null +++ b/.github/workflows/update-sha.yml @@ -0,0 +1,50 @@ +name: Update SHA + +on: issue_comment + +jobs: + update-pr-sha: + name: Update SHA + if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'update-sha') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + token: ${{ secrets.BOT_TOKEN }} + + # GitHub doesn't support string split expression + - name: Extract branch name from comment to get commit SHA + uses: jungwinter/split@v2 + id: split + with: + msg: ${{ github.event.comment.body }} + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Use CLA approved github bot + run: .github/scripts/use-cla-approved-github-bot.sh + + - name: Checkout Pull Request + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + PR_URL="${{ github.event.issue.pull_request.url }}" + PR_NUM=${PR_URL##*/} + echo "Checking out from PR #$PR_NUM based on URL: $PR_URL" + hub pr checkout $PR_NUM + + # caching is not supported for this event type + - name: Run script + run: | + python -m pip install requests==2.28.1 ruamel.yaml==0.17.21 + python scripts/update_sha.py --branch ${{ steps.split.outputs._1 }} + + - name: Commit and Push changes + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + git commit -a -m "Update SHA" + git push diff --git a/dev-requirements.txt b/dev-requirements.txt index cb17b500407..ff7379256a3 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -22,3 +22,5 @@ mypy-protobuf~=3.0.0 markupsafe==2.0.1 bleach==4.1.0 # This dependency was updated to a breaking version. codespell==2.1.0 +requests==2.28.1 +ruamel.yaml==0.17.21 diff --git a/scripts/update_sha.py b/scripts/update_sha.py new file mode 100644 index 00000000000..c7da2e1a546 --- /dev/null +++ b/scripts/update_sha.py @@ -0,0 +1,58 @@ +# 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-contrib/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"]["CONTRIB_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()