generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 67
Add nightly dependency bump workflow #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ezhang6811
wants to merge
27
commits into
aws-observability:main
Choose a base branch
from
ezhang6811:zhaez/nightly-build
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
383f29c
add script to bump otel dependencies
ezhang6811 c4395a7
add nightly build workflow
ezhang6811 e12d79c
update main build to run on nightly build branch
ezhang6811 a821678
update contrib dependencies together in script
ezhang6811 ea7f372
add logic to link releases with breaking changes
ezhang6811 8cf6aac
Revert "update main build to run on nightly build branch"
ezhang6811 ed8294e
fix branching logic and add metric
ezhang6811 edcdb15
add main build call and update metric
ezhang6811 3393cf7
add test trigger to workflow
ezhang6811 27155e2
fix bug and job title
ezhang6811 735e6af
fix credential for metric publishing
ezhang6811 f3abbd9
fix logic to find breaking changes
ezhang6811 60e1e8e
update script comments
ezhang6811 ede0ddb
Merge branch 'main' into zhaez/nightly-build
ezhang6811 aefcbbb
refactor workflow order
ezhang6811 28730e0
update workflow details
ezhang6811 de3d22a
parity with python nightly build
ezhang6811 65f7fde
add manual trigger
ezhang6811 6f3154c
add caller workflow
ezhang6811 842ff18
fix main build
ezhang6811 a31d4fd
fix update_dependencies
ezhang6811 e5f1103
minor fix
ezhang6811 2673a37
strip suffix from current veresion
ezhang6811 69ac6e9
update regex
ezhang6811 bd16c61
Merge branch 'main' into zhaez/nightly-build
ezhang6811 b4f6d7e
minor fixes
ezhang6811 73df7fb
fix credentials for metric
ezhang6811 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| name: Nightly Upstream Snapshot Build | ||
| description: This workflow checks for new upstream versions of OpenTelemetry dependencies, creates a PR to update them, and builds and tests the new changes. | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "21 3 * * *" | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - zhaez/nightly-build | ||
|
|
||
| env: | ||
| AWS_DEFAULT_REGION: us-east-1 | ||
| BRANCH_NAME: nightly-dependency-updates | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| update-dependencies: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| has_changes: ${{ steps.check_changes.outputs.has_changes }} | ||
| otel_java_instrumentation_version: ${{ steps.get_versions.outputs.otel_java_instrumentation_version }} | ||
| otel_java_contrib_version: ${{ steps.get_versions.outputs.otel_java_contrib_version }} | ||
| breaking_changes_info: ${{ steps.breaking_changes.outputs.breaking_changes_info }} | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c #v6.0.0 | ||
| with: | ||
| python-version: '3.x' | ||
|
|
||
| - name: Install build tools | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install requests packaging | ||
|
|
||
| - name: Get latest upstream versions | ||
| id: get_versions | ||
| run: python scripts/get_upstream_versions.py | ||
|
|
||
| - name: Check for breaking changes | ||
| id: breaking_changes | ||
| env: | ||
| OTEL_JAVA_INSTRUMENTATION_VERSION: ${{ steps.get_versions.outputs.otel_java_instrumentation_version }} | ||
| OTEL_JAVA_CONTRIB_VERSION: ${{ steps.get_versions.outputs.otel_java_contrib_version }} | ||
| run: python scripts/find_breaking_changes.py | ||
|
|
||
| - name: Setup Git | ||
| run: | | ||
| git config user.name "github-actions" | ||
| git config user.email "github-actions@github.com" | ||
|
|
||
| - name: Check out dependency update branch | ||
| run: | | ||
| if git ls-remote --exit-code --heads origin "$BRANCH_NAME"; then | ||
| echo "Branch $BRANCH_NAME already exists, checking out..." | ||
| git checkout "$BRANCH_NAME" | ||
| else | ||
| echo "Branch $BRANCH_NAME does not exist, creating new branch..." | ||
| git checkout -b "$BRANCH_NAME" | ||
| fi | ||
|
|
||
| - name: Update dependencies | ||
| env: | ||
| OTEL_JAVA_INSTRUMENTATION_VERSION: ${{ steps.get_versions.outputs.otel_java_instrumentation_version }} | ||
| OTEL_JAVA_CONTRIB_VERSION: ${{ steps.get_versions.outputs.otel_java_contrib_version }} | ||
| run: python scripts/update_dependencies.py | ||
|
|
||
| - name: Check for changes and commit | ||
| id: check_changes | ||
| run: | | ||
| if git diff --quiet; then | ||
| echo "No dependency updates needed" | ||
| echo "has_changes=false" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Dependencies were updated" | ||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||
|
|
||
| git add . | ||
| git commit -m "chore: update OpenTelemetry dependencies to ${{ steps.get_versions.outputs.otel_java_instrumentation_version }}/${{ steps.get_versions.outputs.otel_java_contrib_version }}" | ||
| git push origin "$BRANCH_NAME" | ||
| fi | ||
|
|
||
| build-and-test: | ||
| needs: update-dependencies | ||
| if: needs.update-dependencies.outputs.has_changes == 'true' | ||
| uses: ./.github/workflows/main-build.yml | ||
| secrets: inherit | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| with: | ||
| ref: nightly-dependency-updates | ||
|
|
||
| create-pr: | ||
| needs: [update-dependencies, build-and-test] | ||
| if: always() && needs.update-dependencies.outputs.has_changes == 'true' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Create or update PR | ||
| run: | | ||
| BUILD_STATUS="${{ needs.build-and-test.result }}" | ||
| BUILD_EMOJI="${{ needs.build-and-test.result == 'success' && '✅' || '❌' }}" | ||
| BUILD_LINK="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
|
|
||
| PR_BODY="Automated update of OpenTelemetry dependencies. | ||
|
|
||
| **Build Status:** ${BUILD_EMOJI} [${BUILD_STATUS}](${BUILD_LINK}) | ||
|
|
||
| **Updated versions:** | ||
| - [OpenTelemetry Java Instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/tag/v${{ needs.update-dependencies.outputs.otel_java_instrumentation_version }}): ${{ needs.update-dependencies.outputs.otel_java_instrumentation_version }} | ||
| - [OpenTelemetry Java Contrib](https://github.com/open-telemetry/opentelemetry-java-contrib/releases/tag/v${{ needs.update-dependencies.outputs.otel_java_contrib_version }}): ${{ needs.update-dependencies.outputs.otel_java_contrib_version }} | ||
|
|
||
| **Upstream releases with breaking changes:** | ||
| Note: the mechanism to detect upstream breaking changes is not perfect. Be sure to check all new releases and understand if any additional changes need to be addressed. | ||
|
|
||
| ${{ needs.update-dependencies.outputs.breaking_changes_info }}" | ||
|
|
||
| if gh pr view "$BRANCH_NAME" --json state --jq '.state' 2>/dev/null | grep -q "OPEN"; then | ||
| echo "Open PR already exists, updating description..." | ||
| gh pr edit "$BRANCH_NAME" --body "$PR_BODY" | ||
| else | ||
| echo "Creating new PR..." | ||
| gh pr create \ | ||
| --title "Nightly dependency update: OpenTelemetry ${{ needs.update-dependencies.outputs.otel_java_instrumentation_version }}/${{ needs.update-dependencies.outputs.otel_java_contrib_version }}" \ | ||
| --body "$PR_BODY" \ | ||
| --base main \ | ||
| --head "$BRANCH_NAME" | ||
| fi | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| publish-nightly-build-status: | ||
| name: "Publish Nightly Build Status" | ||
| needs: [update-dependencies, build-and-test, create-pr] | ||
| runs-on: ubuntu-latest | ||
| if: always() | ||
| steps: | ||
| - name: Configure AWS Credentials for emitting metrics | ||
| uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 #v5.0.0 | ||
| with: | ||
| role-to-assume: ${{ secrets.METRICS_ROLE_ARN }} | ||
| aws-region: ${{ env.AWS_DEFAULT_REGION }} | ||
|
|
||
| - name: Publish nightly build status | ||
| run: | | ||
| if [[ "${{ needs.build-and-test.result }}" == "skipped" ]]; then | ||
| echo "Build was skipped (no changes)" | ||
| value="0.0" | ||
| else | ||
| value="${{ (needs.build-and-test.result == 'success' && needs.create-pr.result == 'success') && '0.0' || '1.0'}}" | ||
| fi | ||
|
|
||
| aws cloudwatch put-metric-data --namespace 'ADOT/GitHubActions' \ | ||
| --metric-name Failure \ | ||
| --dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=nightly_build \ | ||
| --value $value | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| import re | ||
| import sys | ||
|
|
||
| import requests | ||
| from packaging import version | ||
|
|
||
|
|
||
| def get_current_version_from_gradle(): | ||
| """Extract current OpenTelemetry versions from build.gradle.kts.""" | ||
| try: | ||
| with open("dependencyManagement/build.gradle.kts", "r", encoding="utf-8") as file: | ||
| content = file.read() | ||
|
|
||
| # Extract otelVersion (instrumentation version) and strip -adot1 suffix | ||
| otel_version_match = re.search(r'val otelVersion = "([^"]*)"', content) | ||
| current_instrumentation_version = otel_version_match.group(1) if otel_version_match else None | ||
| if current_instrumentation_version and current_instrumentation_version.endswith("-adot1"): | ||
| current_instrumentation_version = current_instrumentation_version[:-6] # Remove -adot1 | ||
|
|
||
| # Extract contrib version from dependency line and strip -adot1 suffix | ||
| contrib_match = re.search(r'"io\.opentelemetry\.contrib:opentelemetry-aws-xray:([^"]*)",', content) | ||
| current_contrib_version = contrib_match.group(1) if contrib_match else None | ||
| if current_contrib_version and current_contrib_version.endswith("-adot1"): | ||
| current_contrib_version = current_contrib_version[:-6] # Remove -adot1 | ||
|
|
||
| return current_instrumentation_version, current_contrib_version | ||
|
|
||
| except (OSError, IOError) as error: | ||
| print(f"Error reading current versions: {error}") | ||
| return None, None | ||
|
|
||
|
|
||
| def get_releases_with_breaking_changes(repo, current_version, new_version): | ||
| """Get releases between current and new version that mention breaking changes.""" | ||
| try: | ||
| response = requests.get(f"https://api.github.com/repos/open-telemetry/{repo}/releases", timeout=30) | ||
| response.raise_for_status() | ||
| releases = response.json() | ||
|
|
||
| breaking_releases = [] | ||
|
|
||
| for release in releases: | ||
| try: | ||
| tag_name = release["tag_name"] | ||
| release_version = tag_name.lstrip("v") | ||
|
|
||
| # Check if this release is between current and new version | ||
| if ( | ||
| version.parse(current_version) | ||
| < version.parse(release_version) | ||
| <= version.parse(new_version) | ||
| ): | ||
|
|
||
| # Check if release notes have breaking changes header or bold text | ||
| body = release.get("body", "") | ||
| if re.search(r"^\s*(#+|\*\*).*breaking changes", body, re.MULTILINE | re.IGNORECASE): | ||
| breaking_releases.append( | ||
| { | ||
| "version": release_version, | ||
| "name": release["name"], | ||
| "url": release["html_url"], | ||
| "body": release.get("body", ""), | ||
| } | ||
| ) | ||
| except (ValueError, KeyError) as parse_error: | ||
| print(f"Warning: Skipping release {release.get('name', 'unknown')} due to error: {parse_error}") | ||
| continue | ||
|
|
||
| return breaking_releases | ||
|
|
||
| except requests.RequestException as request_error: | ||
| print(f"Warning: Could not get releases for {repo}: {request_error}") | ||
| return [] | ||
|
|
||
|
|
||
| def main(): | ||
| new_instrumentation_version = os.environ.get("OTEL_JAVA_INSTRUMENTATION_VERSION") | ||
| new_contrib_version = os.environ.get("OTEL_JAVA_CONTRIB_VERSION") | ||
|
|
||
| if not new_instrumentation_version or not new_contrib_version: | ||
| print("Error: OTEL_JAVA_INSTRUMENTATION_VERSION and OTEL_JAVA_CONTRIB_VERSION environment variables required") | ||
| sys.exit(1) | ||
|
|
||
| current_instrumentation_version, current_contrib_version = get_current_version_from_gradle() | ||
|
|
||
| if not current_instrumentation_version: | ||
| print("Could not determine current versions") | ||
| sys.exit(1) | ||
|
|
||
| print("Checking for breaking changes:") | ||
| print(f"Instrumentation: {current_instrumentation_version} → {new_instrumentation_version}") | ||
| print(f"Contrib: {current_contrib_version or 'unknown'} → {new_contrib_version}") | ||
|
|
||
| # Check both repos for breaking changes | ||
| instrumentation_breaking = get_releases_with_breaking_changes( | ||
| "opentelemetry-java-instrumentation", current_instrumentation_version, new_instrumentation_version | ||
| ) | ||
| contrib_breaking = [] | ||
| if current_contrib_version: | ||
| contrib_breaking = get_releases_with_breaking_changes( | ||
| "opentelemetry-java-contrib", current_contrib_version, new_contrib_version | ||
| ) | ||
|
|
||
| # Output for GitHub Actions | ||
| breaking_info = "" | ||
|
|
||
| if instrumentation_breaking: | ||
| breaking_info += "**opentelemetry-java-instrumentation:**\n" | ||
| for release in instrumentation_breaking: | ||
| breaking_info += f"- [{release['name']}]({release['url']})\n" | ||
|
|
||
| if contrib_breaking: | ||
| breaking_info += "\n**opentelemetry-java-contrib:**\n" | ||
| for release in contrib_breaking: | ||
| breaking_info += f"- [{release['name']}]({release['url']})\n" | ||
|
|
||
| # Set GitHub output | ||
| if os.environ.get("GITHUB_OUTPUT"): | ||
| with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output_file: | ||
| output_file.write(f"breaking_changes_info<<EOF\n{breaking_info}EOF\n") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove