Skip to content

Commit

Permalink
chore(ci): move canary publishing script to file (#8877)
Browse files Browse the repository at this point in the history
Co-authored-by: Tobbe Lundberg <[email protected]>
  • Loading branch information
jtoar and Tobbe authored Jul 11, 2023
1 parent b99e523 commit d706d6b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 68 deletions.
69 changes: 69 additions & 0 deletions .github/scripts/publish_canary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
#
# Used in the publish-canary.yml GitHub Action workflow.

echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc

TAG='canary' && [[ "$GITHUB_REF_NAME" = 'next' ]] && TAG='next'
echo "Publishing $TAG"

args=()

if [[ "$GITHUB_REF_NAME" = 'main' ]]; then
args+=(premajor)
fi

args+=(
--include-merged-tags
--canary
--exact
--preid "$TAG"
--dist-tag "$TAG"
--force-publish
--loglevel verbose
--no-git-reset
)

# `echo 'n'` to answer "no" to the "Are you sure you want to publish these
# packages?" prompt.
# `|&` to pipe both stdout and stderr to grep. Mostly do this keep the github
# action output clean.
# At the end we use awk to increase the commit count by 1, because we'll commit
# updated package.jsons in the next step, which will increase increase the
# final number that lerna will use when publishing the canary packages.
echo 'n' \
| yarn lerna publish "${args[@]}" \
|& grep '\-canary\.' \
| tail -n 1 \
| sed 's/.*=> //' \
| sed 's/\+.*//' \
| awk -F. '{ $NF = $NF + 1 } 1' OFS=. \
> canary_version

sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
packages/create-redwood-app/templates/js/package.json > tmpfile \
&& mv tmpfile packages/create-redwood-app/templates/js/package.json
sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
packages/create-redwood-app/templates/js/api/package.json > tmpfile \
&& mv tmpfile packages/create-redwood-app/templates/js/api/package.json
sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
packages/create-redwood-app/templates/js/web/package.json > tmpfile \
&& mv tmpfile packages/create-redwood-app/templates/js/web/package.json

sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
packages/create-redwood-app/templates/ts/package.json > tmpfile \
&& mv tmpfile packages/create-redwood-app/templates/ts/package.json
sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
packages/create-redwood-app/templates/ts/api/package.json > tmpfile \
&& mv tmpfile packages/create-redwood-app/templates/ts/api/package.json
sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
packages/create-redwood-app/templates/ts/web/package.json > tmpfile \
&& mv tmpfile packages/create-redwood-app/templates/ts/web/package.json

git config user.name "GitHub Actions"
git config user.email "<>"

git commit -am "Update create-redwood-app templates to use canary packages"

args+=(--yes)
yarn lerna publish "${args[@]}"
69 changes: 1 addition & 68 deletions .github/workflows/publish-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,74 +54,7 @@ jobs:
run: yarn test

- name: 🚢 Publish
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
TAG='canary' && [[ "$GITHUB_REF_NAME" = 'next' ]] && TAG='next'
echo "Publishing $TAG"
args=()
if [[ "$GITHUB_REF_NAME" = 'main' ]]; then
args+=(premajor)
fi
args+=(
--include-merged-tags
--canary
--exact
--preid "$TAG"
--dist-tag "$TAG"
--force-publish
--loglevel verbose
--no-git-reset
)
# `echo 'n'` to answer "no" to the "Are you sure you want to publish
# these packages?" prompt.
# `|&` to pipe both stdout and stderr to grep. Mostly do this keep
# the github action output clean.
# At the end we use awk to increase the commit count by 1, because
# we'll commit updated package.jsons in the next step, which will
# increase increase the final number that lerna will use when
# publishing the canary packages.
echo 'n' \
| yarn lerna publish "${args[@]}" \
|& grep '\-canary\.' \
| tail -n 1 \
| sed 's/.*=> //' \
| sed 's/\+.*//' \
| awk -F. '{ $NF = $NF + 1 } 1' OFS=. \
> canary_version
cat packages/create-redwood-app/templates/js/package.json \
| sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
> packages/create-redwood-app/templates/js/package.json
cat packages/create-redwood-app/templates/js/api/package.json \
| sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
> packages/create-redwood-app/templates/js/api/package.json
cat packages/create-redwood-app/templates/js/web/package.json \
| sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
> packages/create-redwood-app/templates/js/web/package.json
cat packages/create-redwood-app/templates/ts/package.json \
| sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
> packages/create-redwood-app/templates/ts/package.json
cat packages/create-redwood-app/templates/ts/api/package.json \
| sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
> packages/create-redwood-app/templates/ts/api/package.json
cat packages/create-redwood-app/templates/ts/web/package.json \
| sed "s/\"@redwoodjs\/\(.*\)\": \".*\"/\"@redwoodjs\/\1\": \"$(cat canary_version)\"/" \
> packages/create-redwood-app/templates/ts/web/package.json
git config user.name "GitHub Actions"
git config user.email "<>"
git commit -am "Update create-redwood-app templates to use canary packages"
args+=(--yes)
yarn lerna publish "${args[@]}"
run: ./.github/scripts/publish_canary.sh
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

Expand Down

0 comments on commit d706d6b

Please sign in to comment.