Skip to content

Commit e74800c

Browse files
committed
add nightly build with scripts
1 parent d4fa47e commit e74800c

File tree

3 files changed

+270
-0
lines changed

3 files changed

+270
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Nightly Upstream Snapshot Build
2+
3+
on:
4+
schedule:
5+
- cron: "21 3 * * *"
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- zhaez/nightly-build
10+
11+
jobs:
12+
build-and-test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Configure git and create branch
23+
run: |
24+
git config --local user.email "[email protected]"
25+
git config --local user.name "GitHub Action"
26+
BRANCH_NAME="nightly-deps-$(date +%Y%m%d)"
27+
git checkout -b "$BRANCH_NAME"
28+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: '3.11'
34+
35+
- name: Install build tools
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install build pytest toml requests
39+
40+
- name: Get latest upstream versions
41+
id: get_versions
42+
run: python scripts/get_upstream_versions.py
43+
44+
- name: Update dependencies
45+
env:
46+
OTEL_PYTHON_VERSION: ${{ steps.get_versions.outputs.otel_python_version }}
47+
OTEL_CONTRIB_VERSION: ${{ steps.get_versions.outputs.otel_contrib_version }}
48+
run: python scripts/update_dependencies.py
49+
50+
- name: Check for changes and run tests
51+
id: check_changes
52+
run: |
53+
if git diff --quiet; then
54+
echo "No dependency updates needed"
55+
echo "has_changes=false" >> $GITHUB_OUTPUT
56+
else
57+
echo "Dependencies were updated"
58+
echo "has_changes=true" >> $GITHUB_OUTPUT
59+
fi
60+
61+
- name: Build and test
62+
if: steps.check_changes.outputs.has_changes == 'true'
63+
uses: ./.github/actions/artifacts_build
64+
with:
65+
image_uri_with_tag: adot-python-nightly:snapshot
66+
push_image: false
67+
load_image: true
68+
python_version: "3.11"
69+
package_name: aws-opentelemetry-distro
70+
os: ubuntu-latest
71+
72+
- name: Build and Test Lambda Layer
73+
if: steps.check_changes.outputs.has_changes == 'true'
74+
uses: ./.github/actions/lambda_artifacts_build
75+
with:
76+
python_version: "3.12"
77+
layer_directory: lambda-layer
78+
staging_s3_bucket: "nightly-test-bucket"
79+
os: ubuntu-latest
80+
81+
- name: Run contract tests
82+
if: steps.check_changes.outputs.has_changes == 'true'
83+
run: |
84+
bash scripts/set-up-contract-tests.sh
85+
pip install pytest
86+
pytest contract-tests/tests
87+
88+
- name: Create PR if changes exist
89+
if: steps.check_changes.outputs.has_changes == 'true'
90+
run: |
91+
git add aws-opentelemetry-distro/pyproject.toml
92+
git commit -m "chore: update OpenTelemetry dependencies to ${{ steps.get_versions.outputs.otel_python_version }}/${{ steps.get_versions.outputs.otel_contrib_version }}"
93+
git push origin "$BRANCH_NAME"
94+
95+
gh pr create \
96+
--title "Nightly dependency update: OpenTelemetry ${{ steps.get_versions.outputs.otel_python_version }}/${{ steps.get_versions.outputs.otel_contrib_version }}" \
97+
--body "Automated update of OpenTelemetry dependencies.
98+
99+
**Updated versions:**
100+
- OpenTelemetry Python: ${{ steps.get_versions.outputs.otel_python_version }}
101+
- OpenTelemetry Contrib: ${{ steps.get_versions.outputs.otel_contrib_version }}
102+
103+
**Tests completed:**
104+
- Unit tests (tox)
105+
- Wheel building
106+
- Docker image building
107+
- Lambda layer building and testing
108+
- Contract tests
109+
110+
This PR will trigger additional validation via pr-build workflow including multi-version testing and linting." \
111+
--base main \
112+
--head "$BRANCH_NAME" \
113+
--label "dependencies"
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

scripts/get_upstream_versions.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
import requests
4+
import os
5+
import sys
6+
import re
7+
8+
def get_latest_otel_versions():
9+
"""Get latest OpenTelemetry versions from GitHub releases."""
10+
try:
11+
# Query GitHub API for latest release
12+
response = requests.get('https://api.github.com/repos/open-telemetry/opentelemetry-python/releases/latest')
13+
response.raise_for_status()
14+
15+
release_data = response.json()
16+
release_title = release_data['name']
17+
18+
# Parse "Version 1.37.0/0.58b0" format
19+
match = re.search(r'Version\s+(\d+\.\d+\.\d+)/(\d+\.\d+b\d+)', release_title)
20+
if not match:
21+
print(f"Could not parse release title: {release_title}")
22+
sys.exit(1)
23+
24+
otel_python_version = match.group(1) # e.g., "1.37.0"
25+
otel_contrib_version = match.group(2) # e.g., "0.58b0"
26+
27+
return otel_python_version, otel_contrib_version
28+
29+
except Exception as e:
30+
print(f"Error getting OpenTelemetry versions: {e}")
31+
sys.exit(1)
32+
33+
def main():
34+
otel_python_version, otel_contrib_version = get_latest_otel_versions()
35+
36+
print(f'OTEL_PYTHON_VERSION={otel_python_version}')
37+
print(f'OTEL_CONTRIB_VERSION={otel_contrib_version}')
38+
39+
# Write to GitHub output if in CI
40+
if 'GITHUB_OUTPUT' in os.environ:
41+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
42+
f.write(f'otel_python_version={otel_python_version}\n')
43+
f.write(f'otel_contrib_version={otel_contrib_version}\n')
44+
45+
if __name__ == '__main__':
46+
main()

scripts/update_dependencies.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env python3
2+
3+
import toml
4+
import sys
5+
import os
6+
7+
# Dependencies that use the first version number (opentelemetry-python)
8+
PYTHON_CORE_DEPS = [
9+
'opentelemetry-api',
10+
'opentelemetry-sdk',
11+
'opentelemetry-exporter-otlp',
12+
'opentelemetry-exporter-otlp-proto-grpc',
13+
'opentelemetry-exporter-otlp-proto-http',
14+
'opentelemetry-propagator-b3',
15+
'opentelemetry-propagator-jaeger',
16+
'opentelemetry-exporter-otlp-proto-common',
17+
]
18+
19+
# Dependencies that use the second version number (opentelemetry-python-contrib)
20+
CONTRIB_DEPS = [
21+
'opentelemetry-distro',
22+
'opentelemetry-processor-baggage',
23+
'opentelemetry-propagator-ot-trace',
24+
'opentelemetry-instrumentation',
25+
'opentelemetry-instrumentation-aws-lambda',
26+
'opentelemetry-instrumentation-aio-pika',
27+
'opentelemetry-instrumentation-aiohttp-client',
28+
'opentelemetry-instrumentation-aiopg',
29+
'opentelemetry-instrumentation-asgi',
30+
'opentelemetry-instrumentation-asyncpg',
31+
'opentelemetry-instrumentation-boto',
32+
'opentelemetry-instrumentation-boto3sqs',
33+
'opentelemetry-instrumentation-botocore',
34+
'opentelemetry-instrumentation-celery',
35+
'opentelemetry-instrumentation-confluent-kafka',
36+
'opentelemetry-instrumentation-dbapi',
37+
'opentelemetry-instrumentation-django',
38+
'opentelemetry-instrumentation-elasticsearch',
39+
'opentelemetry-instrumentation-falcon',
40+
'opentelemetry-instrumentation-fastapi',
41+
'opentelemetry-instrumentation-flask',
42+
'opentelemetry-instrumentation-grpc',
43+
'opentelemetry-instrumentation-httpx',
44+
'opentelemetry-instrumentation-jinja2',
45+
'opentelemetry-instrumentation-kafka-python',
46+
'opentelemetry-instrumentation-logging',
47+
'opentelemetry-instrumentation-mysql',
48+
'opentelemetry-instrumentation-mysqlclient',
49+
'opentelemetry-instrumentation-pika',
50+
'opentelemetry-instrumentation-psycopg2',
51+
'opentelemetry-instrumentation-pymemcache',
52+
'opentelemetry-instrumentation-pymongo',
53+
'opentelemetry-instrumentation-pymysql',
54+
'opentelemetry-instrumentation-pyramid',
55+
'opentelemetry-instrumentation-redis',
56+
'opentelemetry-instrumentation-remoulade',
57+
'opentelemetry-instrumentation-requests',
58+
'opentelemetry-instrumentation-sqlalchemy',
59+
'opentelemetry-instrumentation-sqlite3',
60+
'opentelemetry-instrumentation-starlette',
61+
'opentelemetry-instrumentation-system-metrics',
62+
'opentelemetry-instrumentation-tornado',
63+
'opentelemetry-instrumentation-tortoiseorm',
64+
'opentelemetry-instrumentation-urllib',
65+
'opentelemetry-instrumentation-urllib3',
66+
'opentelemetry-instrumentation-wsgi',
67+
'opentelemetry-instrumentation-cassandra',
68+
]
69+
70+
def main():
71+
otel_python_version = os.environ.get('OTEL_PYTHON_VERSION')
72+
otel_contrib_version = os.environ.get('OTEL_CONTRIB_VERSION')
73+
74+
if not otel_python_version or not otel_contrib_version:
75+
print("Error: OTEL_PYTHON_VERSION and OTEL_CONTRIB_VERSION environment variables required")
76+
sys.exit(1)
77+
78+
pyproject_path = 'aws-opentelemetry-distro/pyproject.toml'
79+
80+
try:
81+
with open(pyproject_path, 'r') as f:
82+
data = toml.load(f)
83+
84+
deps = data.get('project', {}).get('dependencies', [])
85+
updated = False
86+
87+
for i, dep in enumerate(deps):
88+
dep_name = dep.split('==')[0].strip()
89+
90+
if dep_name in PYTHON_CORE_DEPS:
91+
deps[i] = f'{dep_name} == {otel_python_version}'
92+
updated = True
93+
elif dep_name in CONTRIB_DEPS:
94+
deps[i] = f'{dep_name} == {otel_contrib_version}'
95+
updated = True
96+
97+
if updated:
98+
with open(pyproject_path, 'w') as f:
99+
toml.dump(data, f)
100+
print(f'Dependencies updated to Python {otel_python_version} / Contrib {otel_contrib_version}')
101+
else:
102+
print('No OpenTelemetry dependencies found to update')
103+
104+
except Exception as e:
105+
print(f"Error updating dependencies: {e}")
106+
sys.exit(1)
107+
108+
if __name__ == '__main__':
109+
main()

0 commit comments

Comments
 (0)