[go: nahoru, domu]

Skip to content

Commit

Permalink
Decouple publishing packages from publishing CLIs (#1778)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Bouchenoire <bouchenoire.marc@gmail.com>
  • Loading branch information
nvie and marcbouchenoire committed Jun 28, 2024
1 parent f227fbe commit 608ffc1
Show file tree
Hide file tree
Showing 193 changed files with 1,582 additions and 1,427 deletions.
7 changes: 2 additions & 5 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Public packages
/packages/ @nvie
/packages/liveblocks-devtools/ @nvie @marcbouchenoire
/packages/create-liveblocks-app/ @CTNicholas
/packages/liveblocks-node/ @nvie @ofoucherot @FlowFlorent
/packages/liveblocks-react-ui/ @marcbouchenoire
/tools/create-liveblocks-app/ @CTNicholas
/tools/liveblocks-devtools/ @nvie @marcbouchenoire
/shared/ @nvie
/e2e/ @nvie

Expand All @@ -17,6 +17,3 @@

# Scripts
/scripts/ @nvie

# Vercel deployments
/scripts/should-example-rebuild-on-vercel.sh @nvie @marcbouchenoire
52 changes: 25 additions & 27 deletions .github/scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
set -eu

GITHUB_URL="https://github.com/liveblocks/liveblocks"
PACKAGE_DIRS=(
"packages/liveblocks-core"
"packages/liveblocks-client"
"packages/liveblocks-node"
"packages/liveblocks-react"
"packages/liveblocks-redux"
"packages/liveblocks-zustand"
"packages/liveblocks-yjs"
"packages/liveblocks-react-lexical"
"packages/liveblocks-node-lexical"
"packages/liveblocks-react-ui"
"packages/create-liveblocks-app"
"packages/liveblocks-codemod"
)
PRIMARY_PKG=${PACKAGE_DIRS[0]}

usage () {
err "publish.sh [-V <version>] [-t <tag>] <pkgdir> [<pkgdir>...]"
err ""
err " -V the version to publish to NPM"
err " -t the NPM tag to use"
err ""
}

err () {
echo "$@" >&2
Expand All @@ -33,12 +26,18 @@ while getopts V:t:h flag; do
done
shift $(($OPTIND - 1))

if [ "$#" -ne 0 ]; then
err "Unknown arguments: $@"
if [ "$#" -eq 0 ]; then
usage
exit 2
fi

for pkgdir in "$@"; do
if [ ! -d "$pkgdir" ]; then
err "Directory not found: $pkgdir"
exit 2
fi
done

check_is_valid_version () {
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?$ ]]; then
err "Invalid version: $VERSION"
Expand All @@ -50,7 +49,7 @@ check_is_valid_version () {
check_is_valid_tag () {
if ! [[ "$TAG" =~ ^[a-z0-9]+$ ]]; then
err "Invalid tag: $TAG"
err "Tag must be in the form of <tag>"
err "Tag must only contain alphanumeric chars"
exit 2
fi
}
Expand Down Expand Up @@ -78,7 +77,6 @@ publish_to_npm () {
fi

echo "I'm ready to publish $PKGNAME to NPM, under $VERSION!"
# TODO: remove dry-run
npm publish --tag private
}

Expand All @@ -91,23 +89,23 @@ check_is_valid_version "$VERSION"
check_is_valid_tag "$TAG"

# Publish to NPM
for pkgdir in ${PACKAGE_DIRS[@]}; do
for pkgdir in "$@"; do
pkgname="$(npm_pkgname "$pkgdir")"
echo "==> Publishing ${pkgname} to NPM"
( cd "$pkgdir" && publish_to_npm "$pkgname")
echo "==> Publishing $pkgname to NPM"
( cd "$pkgdir" && publish_to_npm "$pkgname" )
done

# By now, all packages should be published under a "private" tag.
# We'll verify that now, and if indeed correct, we'll "assign" the intended tag
# instead. Afterwards, we'll remove the "private" tags again.
echo ""
echo "Assigning definitive NPM tags"
for pkgdir in ${PACKAGE_DIRS[@]}; do
for pkgdir in "$@"; do
pkgname="$(npm_pkgname "$pkgdir")"
while true; do
if npm dist-tag ls "$pkgname" | grep -qEe ": $VERSION\$"; then
echo "==> Adding tag ${TAG:-latest} to $pkgname@$VERSION"
npm dist-tag add "$pkgname@$VERSION" "${TAG:-latest}"
echo "==> Adding tag $TAG to $pkgname@$VERSION"
npm dist-tag add "$pkgname@$VERSION" "$TAG"
break
else
err "I can't find $pkgname@$VERSION on NPM yet..."
Expand All @@ -117,7 +115,7 @@ for pkgdir in ${PACKAGE_DIRS[@]}; do
done

# Clean up those temporary "private" tags
for pkgdir in ${PACKAGE_DIRS[@]}; do
for pkgdir in "$@"; do
pkgname="$(npm_pkgname "$pkgdir")"
npm dist-tag rm "$pkgname@$VERSION" private || echo "Continuing despite error..."
done
Expand All @@ -126,7 +124,7 @@ echo ""
echo "All published!"
echo ""
echo "You can double-check the NPM releases here:"
for pkgdir in ${PACKAGE_DIRS[@]}; do
for pkgdir in "$@"; do
pkgname="$(npm_pkgname "$pkgdir")"
echo " - https://www.npmjs.com/package/$pkgname"
done
Expand Down
51 changes: 19 additions & 32 deletions .github/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,37 @@
set -eu

echo "Running release scripts..."
PACKAGE_DIRS=(
"packages/liveblocks-core"
"packages/liveblocks-client"
"packages/liveblocks-node"
"packages/liveblocks-react"
"packages/liveblocks-redux"
"packages/liveblocks-zustand"
"packages/liveblocks-yjs"
"packages/liveblocks-react-ui"
"packages/liveblocks-react-lexical"
"packages/liveblocks-node-lexical"
"packages/create-liveblocks-app"
"packages/liveblocks-codemod"
)

err () {
echo "$@" >&2
}


usage () {
err "usage: release.sh [-V <version>] [-h]"
err "usage: release.sh [-h] [-V <version>] <pkgdir> [<pkgdir>...]"
err
err "Prepare a release by updating files in this repo."
err "Run this prior to publishing to NPM."
err ""
err " -V the new NPM version"
err ""
err "Create a release for the CI to publish."
err
err "Options:"
err "-V <version> Set version to publish (default: prompt)"
err "Example: 1.0.0 or 1.0.1-beta1"
}

VERSION=
while getopts V:t:h flag; do
while getopts V:h flag; do
case "$flag" in
V) VERSION=$OPTARG;;
*) usage; exit 2;;
esac
done
shift "$(($OPTIND - 1))"

if [ "$#" -ne 0 ]; then
err "Unknown arguments: $@"
if [ "$#" -eq 0 ]; then
usage
exit 2
fi

PKGS_TO_RELEASE=("$@")

check_is_valid_version () {
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?$ ]]; then
err "Invalid version: $VERSION"
Expand All @@ -59,16 +44,16 @@ check_is_valid_version () {
ROOT="$(git rev-parse --show-toplevel)"

all_published_pkgnames () {
for pkgdir in ${PACKAGE_DIRS[@]}; do
for pkgdir in "${PKGS_TO_RELEASE[@]}"; do
jq -r .name "$ROOT/$pkgdir/package.json"
done
}

get_package_name_from_dir(){
get_package_name_from_dir () {
( cd "$1" && jq -r .name package.json )
}

update_dependencies_to_new_package_versions(){
update_dependencies_to_new_package_versions () {
for pkgname in $( all_published_pkgnames ); do
for key in dependencies devDependencies peerDependencies; do
currversion="$(jq -r ".${key}.\"${pkgname}\"" package.json)"
Expand All @@ -80,11 +65,13 @@ update_dependencies_to_new_package_versions(){
}

update_package_version () {
PACKAGE_DIR="$1"
PKGNAME="$(get_package_name_from_dir "$PACKAGE_DIR")"
PKGDIR="$1"
VERSION="$2"

PKGNAME="$( get_package_name_from_dir "$PKGDIR" )"

echo "==> Updating package.json version for $PKGNAME"
( cd "$PKGDIR" && npm version "$2" --no-git-tag-version && update_dependencies_to_new_package_versions "$2" )
( cd "$PKGDIR" && npm version "$VERSION" --no-git-tag-version && update_dependencies_to_new_package_versions "$2" )
}

commit_to_git () {
Expand All @@ -104,10 +91,10 @@ check_is_valid_version "$VERSION"
# Set up turbo
npm install

for PKGDIR in "${PACKAGE_DIRS[@]}"; do
for PKGDIR in "${PKGS_TO_RELEASE[@]}"; do
update_package_version "$PKGDIR" "$VERSION"
done

# Update package-lock.json with newly bumped versions
npm install
commit_to_git "Bump to $VERSION" "package-lock.json" "packages/"
commit_to_git "Bump to $VERSION" "package-lock.json" "packages/" "tools/"
38 changes: 13 additions & 25 deletions .github/workflows/publish-cli-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
type: string
required: true
description:
"Git tag to create (e.g. v1.2.3-test4). See also
"NPM version to publish (use format v2.YYYYMMDD.0). See also
https://github.com/liveblocks/liveblocks/blob/main/CONTRIBUTING.MD#releasing"

jobs:
Expand All @@ -20,11 +20,11 @@ jobs:

- name: Install git-toolbelt
run: |
wget https://github.com/nvie/git-toolbelt/archive/v1.8.0.tar.gz
tar -xzf v1.8.0.tar.gz
wget https://github.com/nvie/git-toolbelt/archive/v1.9.2.tar.gz
tar -xzf v1.9.2.tar.gz
mkdir -p "$HOME/.local/bin"
cp git-toolbelt-1.8.0/git-* "$HOME/.local/bin"
rm -rf v1.8.0.tar.gz git-toolbelt-1.8.0
cp git-toolbelt-1.9.2/git-* "$HOME/.local/bin"
rm -rf v1.9.2.tar.gz git-toolbelt-1.9.2
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Checkout
Expand Down Expand Up @@ -75,11 +75,13 @@ jobs:
- name: Prepare release
env:
VERSION: ${{steps.version.outputs.value}}
run: ./.github/scripts/release.sh -V "$VERSION"
run:
./.github/scripts/release.sh -V "$VERSION"
"tools/create-liveblocks-app" "tools/liveblocks-codemod"

- name: Build all packages
- name: Build all CLI tools
run: |
npm run build -- --filter='./packages/*' --filter='!@liveblocks/devtools'
npm run build -- --filter='./tools/*' --filter='!@liveblocks/devtools'
- name: Publish packages
env:
Expand All @@ -88,20 +90,6 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ steps.version.outputs.value }}
NPM_TAG: ${{ steps.npm_tag.outputs.value }}
run: ./.github/scripts/publish.sh -V "$VERSION" -t "$NPM_TAG"

- name:
Creating release tag, don't forget to fill the changelog if necessary!
env:
VERSION: ${{ steps.version.outputs.value }}
GIT_TAG: ${{ inputs.tag }}
GITHUB_URL: "https://github.com/liveblocks/liveblocks"
run: |
git tag "$GIT_TAG" -m "Release $GIT_TAG"
git push origin "$GIT_TAG"
BRANCH="$(git current-branch)"
URL="${GITHUB_URL}/releases/new?tag=$GIT_TAG&target=${BRANCH}&title=$VERSION&body=%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%0A%0APlease%20replace%20this%20block%20with%20the%20contents%20of%20the%20top%20section%20of%3A%0A%0Ahttps%3A%2F%2Fgithub.com%2Fliveblocks%2Fliveblocks%2Fraw%2F${BRANCH}%2FCHANGELOG.md%0A%0A%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20%E2%9C%82%20"
echo "Done! Please finish it off by writing a nice release entry on GitHub."
echo "You can do so by opening this link:"
echo "$URL"
echo "Also, don't forget to update CHANGELOG.MD"
run:
./.github/scripts/publish.sh -V "$VERSION" -t "$NPM_TAG"
"tools/create-liveblocks-app" "tools/liveblocks-codemod"
46 changes: 45 additions & 1 deletion .github/workflows/publish-devtools.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
name: Publish Liveblocks DevTools extension

on: [workflow_dispatch]
on:
workflow_dispatch:
inputs:
tag:
type: string
required: true
description:
"Extension version to publish (use format vX.Y.Z, no '-test' or any
other tag). Can only be run from the 'main' branch."

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Install moreutils
run: sudo apt-get install -y moreutils

- name: Install git-toolbelt
run: |
wget https://github.com/nvie/git-toolbelt/archive/v1.9.2.tar.gz
tar -xzf v1.9.2.tar.gz
mkdir -p "$HOME/.local/bin"
cp git-toolbelt-1.9.2/git-* "$HOME/.local/bin"
rm -rf v1.9.2.tar.gz git-toolbelt-1.9.2
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.WRITE_ACCESS_TOKEN }}

- name: Validate version
env:
VERSION_TAG: ${{ inputs.tag }}
run: |
[[ "${VERSION_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]
- name: Validate branch
run: test "$(git rev-parse --abbrev-ref HEAD)" == "main"

- name: Use Node.js
uses: actions/setup-node@v4
Expand All @@ -28,6 +59,19 @@ jobs:
path: node_modules/.cache/turbo
restore-keys: turbo-cache-@liveblocks/devtools-bust

- name: Set release version
id: version
env:
VERSION_TAG: ${{ inputs.tag }}
run: echo "value=${VERSION_TAG#v}" >> $GITHUB_OUTPUT

- name: Prepare release
env:
STRIPPED_VERSION: ${{steps.version.outputs.value}}
run:
./.github/scripts/release.sh -V "$STRIPPED_VERSION"
"tools/liveblocks-devtools"

- name: Build for Chromium
run: npx --no turbo run build --filter=@liveblocks/devtools

Expand Down
Loading

0 comments on commit 608ffc1

Please sign in to comment.