Skip to content

Commit 1fe2538

Browse files
authored
Add publishing conventions and release workflow (#11)
1 parent 6738564 commit 1fe2538

File tree

9 files changed

+432
-2
lines changed

9 files changed

+432
-2
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash -e
2+
3+
# shellcheck disable=SC2016
4+
# shellcheck disable=SC2086
5+
6+
# this should be run on the release branch
7+
8+
# NOTE if you need to run this script locally, you will need to first:
9+
# git fetch upstream main
10+
# git push origin upstream/main:main
11+
# export GITHUB_REPOSITORY=open-telemetry/semantic-conventions-java
12+
13+
from_version=$1
14+
15+
# get the date of the first commit that was not in the from_version
16+
from=$(git log --reverse --pretty=format:"%cI" $from_version..HEAD | head -1)
17+
18+
# get the last commit on main that was included in the release
19+
to=$(git merge-base origin/main HEAD | xargs git log -1 --pretty=format:"%cI")
20+
21+
contributors1=$(gh api graphql --paginate -F q="repo:$GITHUB_REPOSITORY is:pr base:main is:merged merged:$from..$to" -f query='
22+
query($q: String!, $endCursor: String) {
23+
search(query: $q, type: ISSUE, first: 100, after: $endCursor) {
24+
edges {
25+
node {
26+
... on PullRequest {
27+
author { login }
28+
reviews(first: 100) {
29+
nodes {
30+
author { login }
31+
}
32+
}
33+
comments(first: 100) {
34+
nodes {
35+
author { login }
36+
}
37+
}
38+
closingIssuesReferences(first: 100) {
39+
nodes {
40+
author { login }
41+
}
42+
}
43+
}
44+
}
45+
}
46+
pageInfo {
47+
hasNextPage
48+
endCursor
49+
}
50+
}
51+
}' --jq '.data.search.edges.[].node.author.login,
52+
.data.search.edges.[].node.reviews.nodes.[].author.login,
53+
.data.search.edges.[].node.comments.nodes.[].author.login,
54+
.data.search.edges.[].node.closingIssuesReferences.nodes.[].author.login')
55+
56+
# this query captures authors of issues which have had PRs in the current range reference the issue
57+
# but not necessarily through closingIssuesReferences (e.g. addressing just a part of an issue)
58+
contributors2=$(gh api graphql --paginate -F q="repo:$GITHUB_REPOSITORY is:pr base:main is:merged merged:$from..$to" -f query='
59+
query($q: String!, $endCursor: String) {
60+
search(query: $q, type: ISSUE, first: 100, after: $endCursor) {
61+
edges {
62+
node {
63+
... on PullRequest {
64+
body
65+
}
66+
}
67+
}
68+
pageInfo {
69+
hasNextPage
70+
endCursor
71+
}
72+
}
73+
}
74+
' --jq '.data.search.edges.[].node.body' \
75+
| grep -oE "#[0-9]{4,}$|#[0-9]{4,}[^0-9<]|$GITHUB_REPOSITORY/issues/[0-9]{4,}" \
76+
| grep -oE "[0-9]{4,}" \
77+
| xargs -I{} gh issue view {} --json 'author,url' --jq '[.author.login,.url]' \
78+
| grep -v '/pull/' \
79+
| sed 's/^\["//' \
80+
| sed 's/".*//')
81+
82+
echo $contributors1 $contributors2 \
83+
| sed 's/ /\n/g' \
84+
| sort -uf \
85+
| grep -v linux-foundation-easycla \
86+
| grep -v github-actions \
87+
| grep -v dependabot \
88+
| grep -v codecov \
89+
| grep -v opentelemetrybot \
90+
| sed 's/^/@/'

.github/scripts/get-version.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash -e
2+
3+
grep -Eo "var semanticConventionsVersion = \".*\"" build.gradle.kts | grep -Eo "[0-9]+.[0-9]+.[0-9]+"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash -e
2+
3+
git config user.name opentelemetrybot
4+
git config user.email [email protected]
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Prepare release branch
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
prereqs:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- name: Verify prerequisites
12+
run: |
13+
if [[ $GITHUB_REF_NAME != main ]]; then
14+
echo this workflow should only be run against main
15+
exit 1
16+
fi
17+
18+
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
19+
echo the change log is missing an \"Unreleased\" section
20+
exit 1
21+
fi
22+
23+
create-pull-request-against-release-branch:
24+
runs-on: ubuntu-latest
25+
needs:
26+
- prereqs
27+
steps:
28+
- uses: actions/checkout@v3
29+
30+
- name: Create release branch
31+
run: |
32+
version=$(.github/scripts/get-version.sh)
33+
if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
34+
release_branch_name="release/v${version}"
35+
git ls-remote --exit-code --heads origin refs/heads/$release_branch_name
36+
if [ "$?" == "0" ] ; then
37+
echo "release branch $release_branch_name already exists"
38+
exit 1
39+
fi
40+
else
41+
echo "unexpected version: $version"
42+
exit 1
43+
fi
44+
45+
git push origin HEAD:$release_branch_name
46+
47+
echo "VERSION=$version" >> $GITHUB_ENV
48+
echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV
49+
50+
- name: Update version
51+
run: sed -Ei "s/val snapshot = true/val snapshot = false/" build.gradle.kts
52+
53+
- name: Update the change log with the approximate release date
54+
run: |
55+
date=$(date "+%Y-%m-%d")
56+
sed -Ei "s/^## Unreleased$/## Version $VERSION ($date)/" CHANGELOG.md
57+
58+
- name: Use CLA approved github bot
59+
run: .github/scripts/use-cla-approved-github-bot.sh
60+
61+
- name: Create pull request against the release branch
62+
env:
63+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
64+
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
65+
run: |
66+
message="Prepare release $VERSION"
67+
branch="opentelemetrybot/prepare-release-${VERSION}"
68+
69+
git checkout -b $branch
70+
git commit -a -m "$message"
71+
git push --set-upstream origin $branch
72+
gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \
73+
--body "$message." \
74+
--base $RELEASE_BRANCH_NAME
75+
76+
create-pull-request-against-main:
77+
runs-on: ubuntu-latest
78+
needs:
79+
- prereqs
80+
steps:
81+
- uses: actions/checkout@v3
82+
83+
- name: Set environment variables
84+
run: |
85+
version=$(.github/scripts/get-version.sh)
86+
if [[ ! $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
87+
echo "unexpected version: $version"
88+
exit 1
89+
fi
90+
echo "VERSION=$version" >> $GITHUB_ENV
91+
92+
- name: Update the change log on main
93+
run: |
94+
# the actual release date on main will be updated at the end of the release workflow
95+
date=$(date "+%Y-%m-%d")
96+
sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version $VERSION ($date)/" CHANGELOG.md
97+
98+
- name: Use CLA approved github bot
99+
run: .github/scripts/use-cla-approved-github-bot.sh
100+
101+
- name: Create pull request against main
102+
env:
103+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
104+
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
105+
run: |
106+
message="Update changelog for $VERSION release"
107+
body="Update changelog for \`$VERSION\` release."
108+
branch="opentelemetrybot/update-version-to-${VERSION}"
109+
110+
git checkout -b $branch
111+
git commit -a -m "$message"
112+
git push --set-upstream origin $branch
113+
gh pr create --title "$message" \
114+
--body "$body" \
115+
--base main

.github/workflows/release.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Release
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
release:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
version: ${{ steps.create-github-release.outputs.version }}
10+
steps:
11+
- run: |
12+
if [[ $GITHUB_REF_NAME != release/* ]]; then
13+
echo this workflow should only be run against release branches
14+
exit 1
15+
fi
16+
17+
- uses: actions/checkout@v3
18+
19+
- uses: actions/setup-java@v3
20+
with:
21+
distribution: temurin
22+
java-version: 17
23+
24+
- name: Build and publish artifacts
25+
uses: gradle/gradle-build-action@v2
26+
with:
27+
# TODO(jack-berg): add following arguments when confident in release process: closeAndReleaseSonatypeStagingRepository
28+
arguments: assemble publishToSonatype
29+
env:
30+
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
31+
SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
32+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
33+
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
34+
35+
- name: Set environment variables
36+
run: |
37+
version=$(.github/scripts/get-version.sh)
38+
if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
39+
major="${BASH_REMATCH[1]}"
40+
minor="${BASH_REMATCH[2]}"
41+
patch="${BASH_REMATCH[3]}"
42+
else
43+
echo "unexpected version: $version"
44+
exit 1
45+
fi
46+
if [[ $patch == 0 ]]; then
47+
if [[ $minor == 0 ]]; then
48+
prior_major=$((major - 1))
49+
prior_minor=$(grep -Po "^## Version $prior_major.\K[0-9]+" CHANGELOG.md | head -1)
50+
prior_version="$prior_major.$prior_minor"
51+
else
52+
prior_version="$major.$((minor - 1)).0"
53+
fi
54+
else
55+
prior_version="$major.$minor.$((patch - 1))"
56+
fi
57+
echo "VERSION=$version" >> $GITHUB_ENV
58+
echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
59+
60+
# check out main branch to verify there won't be problems with merging the change log
61+
# at the end of this workflow
62+
- uses: actions/checkout@v3
63+
with:
64+
ref: main
65+
66+
- name: Check that change log update was merged to main
67+
run: |
68+
if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then
69+
echo the pull request generated by prepare-release-branch.yml needs to be merged first
70+
exit 1
71+
fi
72+
73+
# back to the release branch
74+
- uses: actions/checkout@v3
75+
with:
76+
# tags are needed for the generate-release-contributors.sh script
77+
fetch-depth: 0
78+
79+
- name: Generate release notes
80+
env:
81+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
run: |
83+
# CHANGELOG_SECTION.md is also used at the end of the release workflow
84+
# for copying the change log updates to main
85+
sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \
86+
> /tmp/CHANGELOG_SECTION.md
87+
88+
# the complex perl regex is needed because markdown docs render newlines as soft wraps
89+
# while release notes render them as line breaks
90+
perl -0pe 's/(?<!\n)\n *(?!\n)(?![-*] )(?![1-9]+\. )/ /g' /tmp/CHANGELOG_SECTION.md \
91+
>> /tmp/release-notes.txt
92+
93+
# conditional block not indented because of the heredoc
94+
cat >> /tmp/release-notes.txt << EOF
95+
96+
### 🙇 Thank you
97+
This release was possible thanks to the following contributors who shared their brilliant ideas and awesome pull requests:
98+
99+
EOF
100+
101+
.github/scripts/generate-release-contributors.sh v$PRIOR_VERSION >> /tmp/release-notes.txt
102+
103+
- id: create-github-release
104+
name: Create GitHub release
105+
env:
106+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
run: |
108+
gh release create --target $GITHUB_REF_NAME \
109+
--title "Version $VERSION" \
110+
--notes-file /tmp/release-notes.txt \
111+
--discussion-category announcements \
112+
v$VERSION
113+
114+
echo "version=$VERSION" >> $GITHUB_OUTPUT

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
## Unreleased

0 commit comments

Comments
 (0)