Skip to content

Commit 37e7404

Browse files
ci(examples): update version in examples on release (#9823)
### Description Updates the `turbo` version in examples whenever we make a release. This ignores canaries so we don't ship those to unexpecting users. I'm not sure that this is a sustainable solution as the community continues to add more examples since the many `pnpm update` calls might take awhile. However, I feel like this isn't a performance-critical path for us, so going to go with it until someone tells me not to/thinks of a more clever way. Note that whatever we go with needs to 1) bump the version in package.json and 2) update the lockfile. --------- Co-authored-by: Thomas Knickman <[email protected]>
1 parent 1be88c6 commit 37e7404

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

.github/turbo-orchestrator.yml

+2
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,5 @@ events:
8585
turbo:
8686
- runWorkflow: bench-turborepo.yml
8787
when: any
88+
- runWorkflow: update-examples-on-release.yml
89+
when: latest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Update examples to latest
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
update-examples-pr:
8+
name: "Update examples PR"
9+
needs: [stage, npm-publish]
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Run upgrade script
13+
run: bash ./scripts/update-examples-dep.sh
14+
- name: Create pull request
15+
uses: thomaseizinger/create-pull-request@master
16+
with:
17+
github_token: ${{ secrets.GITHUB_TOKEN }}
18+
head: ${{ needs.stage.outputs.stage-branch }}
19+
base: main
20+
title: "release(turborepo): update examples to latest(${{ steps.getVersion.outputs.version }})"

scripts/update-examples-dep.sh

+26-18
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
#!/bin/bash
22

3-
# This script updates a dependency in all examples that are using pnpm.
3+
# This script updates the turbo dependency in all examples that are using any package manager.
44

5-
# Usage: ./scripts/update-examples-dep.sh <package> <version>
6-
# Example: ./scripts/update-examples-dep.sh typescript
5+
# Usage: ./scripts/update-examples-dep.sh
6+
# Example: ./scripts/update-examples-dep.sh
77

88
set -e
99

1010
# Change directory to the script's directory
1111
cd "$(dirname "$0")"
1212

13-
package="$1"
14-
version=${2:-latest}
13+
package="turbo"
1514

16-
echo "Upgrading $package to $version in all examples..."
15+
# Fetch the latest version of the package from npm
16+
latest_version=$(npm show $package version)
1717

18-
# Get the list of top-level directories
19-
examples=$(find ../examples -depth 1 -type d)
20-
lock="pnpm-lock.yaml"
18+
echo "Upgrading $package to version $latest_version in all examples..."
2119

22-
for dir in $examples; do
23-
if [ "$dir" != "." ]; then
20+
# Get the list of example directories
21+
examples="../examples"
22+
23+
for dir in "$examples"/*; do
24+
if [ -d "$dir" ]; then
2425
cd "$dir"
2526
example=$(basename "$(pwd)")
2627
echo $example
27-
if [ -e "$lock" ]; then
28-
echo "• Updating all workspaces to $package@$version"
29-
# pnpm upgrade $package@latest -r
30-
pnpm install
28+
if [ -e "pnpm-lock.yaml" ]; then
29+
echo "• Updating to $package@$latest_version using pnpm"
30+
pnpm up $package@$latest_version 2>&1 >/dev/null
31+
elif [ -e ".yarn" ]; then
32+
echo "• Updating to $package@$latest_version using yarn"
33+
yarn add $package@$latest_version 2>&1 >/dev/null
34+
elif [ -e "yarn.lock" ]; then
35+
echo "• Updating to $package@$latest_version using yarn"
36+
yarn upgrade $package@$latest_version --ignore-workspace-root-check 2>&1 >/dev/null
37+
elif [ -e "package-lock.json" ]; then
38+
echo "• Updating to $package@$latest_version using npm"
39+
npm install $package@$latest_version 2>&1 >/dev/null
3140
else
32-
# yarn doesn't have a nice recursive upgrade command, so we do those manually for now
33-
echo "• Not using pnpm - skipping."
41+
echo "• No recognized package manager - skipping."
3442
fi
35-
cd - > /dev/null
43+
cd - >/dev/null
3644
echo ""
3745
fi
3846
done

0 commit comments

Comments
 (0)