diff --git a/.github/workflows/component-release.yml b/.github/workflows/package-release.yml similarity index 52% rename from .github/workflows/component-release.yml rename to .github/workflows/package-release.yml index cfe0dfc282..3018f3403e 100644 --- a/.github/workflows/component-release.yml +++ b/.github/workflows/package-release.yml @@ -1,4 +1,4 @@ -name: Release individual component +name: Release individual package on: workflow_dispatch: inputs: @@ -6,15 +6,15 @@ on: type: choice options: - opentelemetry-instrumentation-openai - description: 'Release component' + description: 'Package to be released' required: true jobs: release: runs-on: ubuntu-latest steps: - run: | - if [[ $GITHUB_REF_NAME != component-release/* ]]; then - echo this workflow should only be run against component-release branches + if [[ $GITHUB_REF_NAME != package-release/* ]]; then + echo this workflow should only be run against package-release branches exit 1 fi @@ -27,22 +27,26 @@ jobs: major="${BASH_REMATCH[1]}" minor="${BASH_REMATCH[2]}" patch="${BASH_REMATCH[3]}" - elif [[ $version =~ ^0\.([0-9]+)b([0-9]+)$ ]]; then - minor="${BASH_REMATCH[1]}" - patch="${BASH_REMATCH[2]}" + if [[ $patch != 0 ]]; then + prior_version_when_patch="${major}.${minor}.$((patch - 1))" + fi + elif [[ $version =~ ^([0-9]+)\.([0-9]+)b([0-9]+)$ ]]; then + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" + patch="${BASH_REMATCH[3]}" if [[ $patch != 0 ]]; then - prior_version_when_patch="0.${minor}b$((patch - 1))" + prior_version_when_patch="${major}.${minor}b$((patch - 1))" fi else echo "unexpected version: $version" exit 1 fi - # TODO - don't hardcode path - echo "PACKAGE_CHANGELOG=./instrumentation/${{ inputs.package }}/CHANGELOG.md" >> $GITHUB_ENV + path=$(./scripts/eachdist.py find-package --package ${{ inputs.package }}) + echo "CHANGELOG=./$path/CHANGELOG.md" >> $GITHUB_ENV echo "PACKAGE_NAME=${{ inputs.package }}" >> $GITHUB_ENV - echo "PACKAGE_VERSION=$version" >> $GITHUB_ENV + echo "VERSION=$version" >> $GITHUB_ENV echo "RELEASE_TAG=${{ inputs.package }}==$version" >> $GITHUB_ENV echo "PRIOR_VERSION_WHEN_PATCH=$prior_version_when_patch" >> $GITHUB_ENV @@ -56,7 +60,7 @@ jobs: run: | if [[ -z $PRIOR_VERSION_WHEN_PATCH ]]; then # not making a patch release - if ! grep --quiet "^## Version ${PACKAGE_VERSION}" ${PACKAGE_CHANGELOG}; then + if ! grep --quiet "^## Version ${VERSION}" ${CHANGELOG}; then echo the pull request generated by prepare-release-branch.yml needs to be merged first exit 1 fi @@ -103,31 +107,14 @@ jobs: - name: Generate release notes env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # conditional block not indented because of the heredoc - if [[ ! -z $PRIOR_VERSION_WHEN_PATCH ]]; then - cat > /tmp/release-notes.txt << EOF - This is a patch release on the previous $PRIOR_VERSION_WHEN_PATCH release, fixing the issue(s) below. - - EOF - fi - - # CHANGELOG_SECTION.md is also used at the end of the release workflow - # for copying the change log updates to main - sed -n "0,/^## Version ${PACKAGE_VERSION}/d;/^## Version /q;p" ${PACKAGE_CHANGELOG} \ - > /tmp/CHANGELOG_SECTION.md - - # the complex perl regex is needed because markdown docs render newlines as soft wraps - # while release notes render them as line breaks - perl -0pe 's/(?> /tmp/release-notes.txt + run: ./scripts/generate_release_notes.sh - name: Create GitHub release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release create --target $GITHUB_REF_NAME \ - --title "${PACKAGE_NAME} ${PACKAGE_VERSION}" \ + --title "${PACKAGE_NAME} ${VERSION}" \ --notes-file /tmp/release-notes.txt \ --discussion-category announcements \ $RELEASE_TAG @@ -139,62 +126,7 @@ jobs: - name: Copy change log updates to main env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - if [[ -z $PRIOR_VERSION_WHEN_PATCH ]]; then - # this was not a patch release, so the version exists already in the CHANGELOG.md - - # update the release date - date=$(gh release view $RELEASE_TAG --json publishedAt --jq .publishedAt | sed 's/T.*//') - sed -Ei "s/## Version ${PACKAGE_VERSION}.*/## Version ${PACKAGE_VERSION} ($date)/" ${PACKAGE_CHANGELOG} - - # the entries are copied over from the release branch to support workflows - # where change log entries may be updated after preparing the release branch - - # copy the portion above the release, up to and including the heading - sed -n "0,/^## Version ${PACKAGE_VERSION} ($date)/p" ${PACKAGE_CHANGELOG} > /tmp/CHANGELOG.md - - echo "!!!!!!!!!!!!!!!!!!!!!!!!!! 1" - - cat /tmp/CHANGELOG.md - - # copy the release notes - cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md - - echo "!!!!!!!!!!!!!!!!!!!!!!!!!! 2" - - cat /tmp/CHANGELOG.md - - # copy the portion below the release - sed -n "0,/^## Version ${PACKAGE_VERSION} /d;0,/^## Version /{/^## Version/!d};p" ${PACKAGE_CHANGELOG} \ - >> /tmp/CHANGELOG.md - - echo "!!!!!!!!!!!!!!!!!!!!!!!!!! 3" - - cat /tmp/CHANGELOG_SECTION.md - - # update the real CHANGELOG.md - cp /tmp/CHANGELOG.md ${PACKAGE_CHANGELOG} - - echo "!!!!!!!!!!!!!!!!!!!!!!!!!! end" - else - # this was a patch release, so the version does not exist already in the CHANGELOG.md - - # copy the portion above the top-most release, not including the heading - sed -n "0,/^## Version /{ /^## Version /!p }" ${PACKAGE_CHANGELOG} > /tmp/CHANGELOG.md - - # add the heading - date=$(gh release view $RELEASE_TAG --json publishedAt --jq .publishedAt | sed 's/T.*//') - echo "## Version ${PACKAGE_VERSION} ($date)" >> /tmp/CHANGELOG.md - - # copy the release notes - cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md - - # copy the portion starting from the top-most release - sed -n "/^## Version /,\$p" ${PACKAGE_CHANGELOG} >> /tmp/CHANGELOG.md - - # update the real CHANGELOG.md - cp /tmp/CHANGELOG.md ${PACKAGE_CHANGELOG} - fi + run: ./scripts/merge_changelog_to_main.sh - name: Use CLA approved github bot run: .github/scripts/use-cla-approved-github-bot.sh @@ -202,7 +134,7 @@ jobs: - name: Create pull request against main env: # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} run: | message="Copy change log updates from $GITHUB_REF_NAME" body="Copy log updates from \`$GITHUB_REF_NAME\`." diff --git a/.github/workflows/prepare-package-release.yml b/.github/workflows/prepare-package-release.yml new file mode 100644 index 0000000000..a193cfb1b1 --- /dev/null +++ b/.github/workflows/prepare-package-release.yml @@ -0,0 +1,176 @@ +name: Prepare package release branch +on: + workflow_dispatch: + inputs: + package: + type: choice + options: + - opentelemetry-instrumentation-openai + description: 'Package to be released' + required: true + +jobs: + prereqs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Verify prerequisites + run: | + if [[ $GITHUB_REF_NAME != main ]]; then + echo this workflow should only be run against main + exit 1 + fi + + path=./$(./scripts/eachdist.py find-package --package ${PACKAGE_NAME}) + changelog=$path/CHANGELOG.md + + if ! grep --quiet "^## Unreleased$" $changelog; then + echo the change log is missing an \"Unreleased\" section + exit 1 + fi + + version_dev=$(./scripts/eachdist.py version --package ${{ inputs.package }}) + + if [[ ! $version_dev =~ ^([0-9]+)\.([0-9]+)[\.|b]{1}([0-9]+).*.dev$ ]]; then + echo "unexpected version: $version" + exit 1 + fi + + version=${version_dev%.dev} + + version_file=$(find $path -type f -name "version.py") + file_count=$(echo "$version_file" | wc -l + + if [ "$file_count" -ne 1 ]; then + echo "Error: expected one version.py file, found $file_count" + echo "$version_file" + exit 1 + + echo "version=$version" >> $GITHUB_OUTPUT + echo "changelog=$changelog" >> $GITHUB_OUTPUT + echo "version_file=$version_file" >> $GITHUB_OUTPUT + + create-pull-request-against-release-branch: + runs-on: ubuntu-latest + needs: prereqs + steps: + - uses: actions/checkout@v4 + + - name: Create package release branch + env: + PACKAGE_NAME: ${{ github.event.inputs.package }} + VERSION: ${{ needs.prereqs.outputs.version }} + CHANGELOG: ${{ needs.prereqs.outputs.changelog }} + VERSION_FILE: ${{ needs.prereqs.outputs.version_file }} + run: | + release_branch_name="package-release/$PACKAGE_NAME/v$VERSION" + + git push origin HEAD:$release_branch_name + + echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV + + - name: Update package version + run: | + # replace the version in the version.py file (1.2.3dev -> 1.2.3) + sed -i -E "s/__version__\s*=\s*\"${VERSION}\.dev\"/__version__ = \"${VERSION}\"/g" $VERSION_FILE + + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: 3.9 + - name: Install tox + run: pip install tox + - name: run tox + run: tox -e generate + + - name: Update the change log with the approximate release date + run: | + date=$(date "+%Y-%m-%d") + sed -Ei "s/^## Unreleased$/## Version ${VERSION} ($date)/" ${CHANGELOG} + + - name: Use CLA approved github bot + run: .github/scripts/use-cla-approved-github-bot.sh + + - name: Create pull request against the release branch + env: + # TODO not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + message="Prepare release ${PACKAGE_NAME} ${VERSION}" + branch="opentelemetrybot/${RELEASE_BRANCH_NAME}" + + git commit -a -m "$message" + git push origin HEAD:$branch + gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \ + --body "$message." \ + --head $branch \ + --base $RELEASE_BRANCH_NAME + + create-pull-request-against-main: + runs-on: ubuntu-latest + needs: prereqs + steps: + - uses: actions/checkout@v4 + + - name: Set environment variables + run: | + version=${{ needs.prereqs.outputs.version }} + if [[ version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then + # 1.2.3 or 1.2.3rc1 + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" + next_version="$major.$((minor + 1)).0" + elif [[ version =~ ^([0-9]+)\.([0-9]+)b([0-9]+)$ ]]; then + # 0.1b1 + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" + next_version="$major.$((minor + 1))b0" + else + echo "unexpected version: $version" + exit 1 + fi + + echo "VERSION=$version" >> $GITHUB_ENV + echo "NEXT_VERSION=$next_version.dev" >> $GITHUB_ENV + echo "PACKAGE_NAME=${{ github.event.inputs.package }}" >> $GITHUB_ENV + echo "VERSION_FILE=${{ needs.prereqs.outputs.version_file }}" >> $GITHUB_ENV + + - name: Update version + run: | + # replace the version in the version.py file (1.2.3dev -> 1.2.3) + sed -i -E "s/__version__\s*=\s*\"${VERSION}\.dev\"/__version__ = \"${VERSION}\"/g" $VERSION_FILE + + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: 3.9 + - name: Install tox + run: pip install tox + - name: run tox + run: tox -e generate + + - name: Update the change log on main + run: | + # the actual release date on main will be updated at the end of the release workflow + date=$(date "+%Y-%m-%d") + sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version ${VERSION} ($date)/" ${CHANGELOG} + + - name: Use CLA approved github bot + run: .github/scripts/use-cla-approved-github-bot.sh + + - name: Create pull request against main + env: + # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows TODO + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + message="Update ${PACKAGE_NAME} version to ${NEXT_VERSION}" + body="Update `${PACKAGE_NAME}`version to \`${NEXT_VERSION}\`." + branch="opentelemetrybot/update-version-to-${PACKAGE_NAME}-${NEXT_VERSION}" + + git commit -a -m "$message" + git push origin HEAD:$branch + gh pr create --title "$message" \ + --body "$body" \ + --head $branch \ + --base main diff --git a/.github/workflows/publish-a-package-from-tag.yml b/.github/workflows/publish-a-package-from-tag.yml deleted file mode 100644 index a64f5fcf15..0000000000 --- a/.github/workflows/publish-a-package-from-tag.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Publish a Package from Tag - -on: - push: - tags: - - 'opentelemetry-*==[1-9]*.*' - -jobs: - publish-a-package: - name: Publish package from tag - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.9' - - name: Log tag that triggered publish workflow - run: echo "Attempting to publish package from tag $GITHUB_REF" - - name: Build wheel for tag - run: ./scripts/build_a_package.sh - - name: Install twine - run: | - pip install twine - # We don't need to publish to TestPyPI because we only publish 1 package. - # If it fails no other work needs to be reversed. - - name: Publish to PyPI - env: - TWINE_USERNAME: '__token__' - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - twine upload --skip-existing --verbose dist/* diff --git a/instrumentation/opentelemetry-instrumentation-openai/CHANGELOG.md b/instrumentation/opentelemetry-instrumentation-openai/CHANGELOG.md index d382395136..cfd07be623 100644 --- a/instrumentation/opentelemetry-instrumentation-openai/CHANGELOG.md +++ b/instrumentation/opentelemetry-instrumentation-openai/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this component will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + ## Version 0.3b0 (2024-09-16) - Another release diff --git a/instrumentation/opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/version.py b/instrumentation/opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/version.py index eab5f8a649..ea90d66107 100644 --- a/instrumentation/opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/version.py +++ b/instrumentation/opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.3b0" +__version__ = "0.4b0.dev" diff --git a/scripts/eachdist.py b/scripts/eachdist.py index dbb44bbc9d..57d98206b7 100755 --- a/scripts/eachdist.py +++ b/scripts/eachdist.py @@ -266,6 +266,17 @@ def setup_instparser(instparser): required=False, help="Name of a specific package to get the version for", ) + + findparser = subparsers.add_parser( + "find-package", help="Find package path.", + ) + findparser.set_defaults(func=find_package_args) + findparser.add_argument( + "--package", + "-p", + required=True, + help="Name of the package to find", + ) return parser.parse_args(args) @@ -749,6 +760,20 @@ def version_args(args): print(line.split('"')[1]) return + print("package not found") + sys.exit(1) + +def find_package_args(args): + root = find_projectroot() + for package in find_targets_unordered(root): + if args.package == package.name: + relative_path = package.relative_to(root) + print(relative_path) + return + + print("package not found") + sys.exit(1) + def main(): args = parse_args() args.func(args) diff --git a/scripts/generate_release_notes.sh b/scripts/generate_release_notes.sh new file mode 100644 index 0000000000..e5a02ff6f3 --- /dev/null +++ b/scripts/generate_release_notes.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# This script copies release notes for the current version from CHANGELOG.md file +# and stores them in /tmp/release-notes.txt. +# It also stores them in a /tmp/CHANGELOG_SECTION.md which is used later to copy them over to the +# CHANGELOG in main branch which is done by merge_changelog_to_main script. + +set -ev + +# conditional block not indented because of the heredoc +if [[ ! -z $PRIOR_VERSION_WHEN_PATCH ]]; then +cat > /tmp/release-notes.txt << EOF +This is a patch release on the previous $PRIOR_VERSION_WHEN_PATCH release, fixing the issue(s) below. + +EOF +fi + +# CHANGELOG_SECTION.md is also used at the end of the release workflow +# for copying the change log updates to main +sed -n "0,/^## Version ${VERSION}/d;/^## Version /q;p" ${CHANGELOG} \ +> /tmp/CHANGELOG_SECTION.md + +# the complex perl regex is needed because markdown docs render newlines as soft wraps +# while release notes render them as line breaks +perl -0pe 's/(?> /tmp/release-notes.txt \ No newline at end of file diff --git a/scripts/merge_changelog_to_main.sh b/scripts/merge_changelog_to_main.sh new file mode 100644 index 0000000000..efaba72904 --- /dev/null +++ b/scripts/merge_changelog_to_main.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# This script copies release notes for the current version from CHANGELOG.md file +# and stores them in a temporary file for later use in the release workflow + +set -ev + +if [[ -z $PRIOR_VERSION_WHEN_PATCH ]]; then + # this was not a patch release, so the version exists already in the CHANGELOG.md + + # update the release date + date=$(gh release view $RELEASE_TAG --json publishedAt --jq .publishedAt | sed 's/T.*//') + sed -Ei "s/## Version ${VERSION}.*/## Version ${VERSION} ($date)/" ${CHANGELOG} + + # the entries are copied over from the release branch to support workflows + # where change log entries may be updated after preparing the release branch + + # copy the portion above the release, up to and including the heading + sed -n "0,/^## Version ${VERSION} ($date)/p" ${CHANGELOG} > /tmp/CHANGELOG.md + + # copy the release notes + cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md + + # copy the portion below the release + sed -n "0,/^## Version ${VERSION} /d;0,/^## Version /{/^## Version/!d};p" ${CHANGELOG} \ + >> /tmp/CHANGELOG.md + + # update the real CHANGELOG.md + cp /tmp/CHANGELOG.md ${CHANGELOG} +else + # this was a patch release, so the version does not exist already in the CHANGELOG.md + + # copy the portion above the top-most release, not including the heading + sed -n "0,/^## Version /{ /^## Version /!p }" ${CHANGELOG} > /tmp/CHANGELOG.md + + # add the heading + date=$(gh release view $RELEASE_TAG --json publishedAt --jq .publishedAt | sed 's/T.*//') + echo "## Version ${VERSION} ($date)" >> /tmp/CHANGELOG.md + + # copy the release notes + cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md + + # copy the portion starting from the top-most release + sed -n "/^## Version /,\$p" ${CHANGELOG} >> /tmp/CHANGELOG.md + + # update the real CHANGELOG.md + cp /tmp/CHANGELOG.md ${CHANGELOG} +fi \ No newline at end of file