Skip to content

Commit

Permalink
Add script & workflow to update contrib repo SHA from branch (#3117)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv authored Jan 18, 2023
1 parent 5a996fd commit f879d38
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 73 deletions.
153 changes: 80 additions & 73 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: >-
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
50 changes: 50 additions & 0 deletions .github/workflows/update-sha.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 58 additions & 0 deletions scripts/update_sha.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit f879d38

Please sign in to comment.