Skip to content

Commit

Permalink
prepare package release
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Sep 14, 2024
1 parent f3ebe6c commit b13044a
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: Release individual component
name: Release individual package
on:
workflow_dispatch:
inputs:
package:
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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
>> /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
Expand All @@ -139,70 +126,15 @@ 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

- 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\`."
Expand Down
176 changes: 176 additions & 0 deletions .github/workflows/prepare-package-release.yml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 0 additions & 31 deletions .github/workflows/publish-a-package-from-tag.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading

0 comments on commit b13044a

Please sign in to comment.