Skip to content
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

Combine publish-docs.sh and release.sh #2196

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 0 additions & 135 deletions scripts/publish-docs.sh

This file was deleted.

104 changes: 82 additions & 22 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright © 2019, 2021 Apple Inc. and the ServiceTalk project authors
# Copyright © 2019, 2021-2022 Apple Inc. and the ServiceTalk project authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,29 +22,47 @@ set -eu

DEFAULT_BRANCH="main"
JAPICMP_SKIP_VERSION="skip"
DOCS_FOLDER="docs/generation/.out/remote"
JAVADOC_FOLDER="build/javadoc"
BRANCH_NAME=$(git symbolic-ref -q HEAD)
BRANCH_NAME=${BRANCH_NAME##refs/heads/}
GIT_AUTHOR=$(git --no-pager show -s --format='%an <%ae>' HEAD)

function usage() {
echo "Usage: $0 old_version next_version [branch_name]"
echo "Usage: $0 old_version next_version"
echo "old_version - the previous version to run japicmp against. \"${JAPICMP_SKIP_VERSION}\" to skip japicmp"
echo "next_version - the next version to update gradle.properties, \"-SNAPSHOT\" suffix expected"
echo "branch_name - the branch name to release from (default is \"${DEFAULT_BRANCH})]"
echo "Example to release 0.42.10: $0 0.42.9 0.42.11-SNAPSHOT"
}

if [ "$#" -lt "2" ]; then
function clean_up_gh_pages() {
if git worktree list | grep -q gh-pages; then
echo "Cleanup 'gh-pages' worktree"
git worktree remove -f gh-pages
fi
if git branch --list | grep -q "^\s*gh-pages$"; then
echo "Remove 'gh-pages' branch"
git branch -Df gh-pages
fi
# Just in case of the undefined initial state make sure there is no gh-pages folder
rm -rf gh-pages
}

if [ "$#" -ne "2" ]; then
usage
exit 1
fi

# Enforce JDK17 to get latest LTS javadoc format/features (search, etc.):
java_version=$(./gradlew --no-daemon -version | grep ^JVM: | awk -F\. '{gsub(/^JVM:[ \t]*/,"",$1); print $1"."$2}')
if [ "$java_version" != "17.0" ]; then
echo "Docs can be published only using Java 17, current version: $java_version"
exit 1
fi

oldVersion="$1"
nextVersion="$2"

if [ "$#" -gt "2" ]; then
branchName="$3"
else
branchName=DEFAULT_BRANCH
fi

if ( echo "$nextVersion" | grep -qv "SNAPSHOT" ); then
echo "Expected next version to be a SNAPSHOT version"
usage
Expand All @@ -67,6 +85,9 @@ if ( echo "$version" | grep -q "SNAPSHOT" ); then
exit 1
fi

# Clean up the state at the beginning in case the previous run did not finish successfully
clean_up_gh_pages

if [ -z "${DRYRUN:-}" ]; then
gradle_build_args="--no-build-cache --warning-mode all --refresh-dependencies clean build publishToMavenLocal"
Scottmitch marked this conversation as resolved.
Show resolved Hide resolved
else
Expand Down Expand Up @@ -100,17 +121,19 @@ else
fi

$git fetch -p
if $git rev-parse --quiet --verify ${branchName} > /dev/null; then
$git checkout ${branchName}
else
$git checkout --track ${remote_name}/${branchName}
fi
$git pull
$git log -n1

# No need to clean, it has been done above
echo "Generate javadoc..."
./gradlew --no-daemon javadocAll
echo "Javadoc generated, see ./$JAVADOC_FOLDER"

echo "Generate docs website..."
pushd docs/generation
./gradlew --no-daemon clean validateRemoteSite
popd
echo "Docs website generated, see ./$DOCS_FOLDER"

sed "s/^version=.*/version=$version/" gradle.properties > gradle.properties.tmp
mv gradle.properties.tmp gradle.properties
Expand Down Expand Up @@ -147,7 +170,7 @@ done
sed "s/^version=.*/version=$nextVersion/" gradle.properties > gradle.properties.tmp
mv gradle.properties.tmp gradle.properties

if [[ "$branchName" == "$DEFAULT_BRANCH" ]]; then
if [[ "$BRANCH_NAME" == "$DEFAULT_BRANCH" ]]; then
for file in docs/antora.yml */docs/antora.yml; do
sed "s/^version:.*/version: SNAPSHOT/" "$file" > "$file.tmp"
mv "$file.tmp" "$file"
Expand All @@ -159,14 +182,51 @@ if [[ "$branchName" == "$DEFAULT_BRANCH" ]]; then
fi

$git commit -a -m "Preparing for $nextVersion development"
$git push -u ${remote_name} "$branchName"
$git push -u ${remote_name} "$BRANCH_NAME"
# Push tag after branch otherwise, CodeQL GH Action will fail.
$git push ${remote_name} "$version"

# Antora docs are published as a single bundle which includes all versions from site-remote.yml. We only publish docs
# from main branch or else we may publish docs that are incomplete and missing newer versions.
if [[ "$branchName" == "$DEFAULT_BRANCH" ]]; then
./scripts/publish-docs.sh "$version_majorminor"
# Publish docs to gh-pages
if ( ! git remote get-url docs ); then
git remote add docs git@github.com:apple/servicetalk.git
fi
git fetch docs +gh-pages:gh-pages
git worktree add gh-pages gh-pages

touch gh-pages/.nojekyll

echo "Copy javadoc to gh-pages/servicetalk/$version_majorminor"
rm -rf gh-pages/servicetalk/$version_majorminor/javadoc
\cp -r $JAVADOC_FOLDER gh-pages/servicetalk/$version_majorminor

if [[ "$BRANCH_NAME" == "$DEFAULT_BRANCH" ]]; then
echo "Copy Antora docs to gh-pages"
\cp -r $DOCS_FOLDER/* gh-pages

# Avoid accumulating old javadocs for classes that have been moved, renamed or deleted.
echo "Copy javadoc to gh-pages/servicetalk/SNAPSHOT"
rm -rf gh-pages/servicetalk/SNAPSHOT/javadoc
\cp -r $JAVADOC_FOLDER gh-pages/servicetalk/SNAPSHOT
else
echo "Skipping publish-docs.sh. Cherry-pick site-remote.yml changes to $DEFAULT_BRANCH and run manually if desired."
# Antora docs are published as a single bundle which includes all versions from site-remote.yml. We only publish docs
# from main branch or else we may publish docs that are incomplete and missing newer versions.
echo "Skipping Antora unless on $DEFAULT_BRANCH branch. Cherry-pick site-remote.yml changes to $DEFAULT_BRANCH."
fi

pushd gh-pages
# Do not override older javadoc with Antora placeholder
files_to_revert=$(git diff --name-only | grep 'javadoc/index.html' | grep -v SNAPSHOT)
if [[ "$BRANCH_NAME" != "$DEFAULT_BRANCH" ]]; then
files_to_revert=$(echo ${files_to_revert} | grep -v ${version_majorminor}) || echo "empty files_to_revert"
fi
echo $files_to_revert | xargs git checkout --

$git add * .nojekyll
$git commit --author="$GIT_AUTHOR" -m "Publish docs website $version_majorminor"
$git push docs gh-pages
popd

# Clean up the state (worktree and temporary branch) after publication of the docs
clean_up_gh_pages

echo "Docs website for the release version $version_majorminor successfully published"