Skip to content

Commit

Permalink
✨ feat: Add basic monorepo support
Browse files Browse the repository at this point in the history
  • Loading branch information
honzabubenik committed May 28, 2024
1 parent 11fde12 commit 92b6c53
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
23 changes: 22 additions & 1 deletion prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ inputs:
default: >
npm run test:coverage
monorepo-bump:
description: Monorepo paths.
required: false
default: 'false'

runs:
using: composite
steps:
Expand All @@ -83,11 +88,27 @@ runs:
- id: bump
run: |
BUMP_TYPE=$(npx conventional-recommended-bump -p @localazy/conventional-changelog-preset)
npm version $BUMP_TYPE --git-tag-version false
echo "bump-type=$BUMP_TYPE" >> "$GITHUB_OUTPUT"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "package-version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
shell: bash

- if: monorepo-bump == 'false'
run: |
npm version ${{ steps.bump.outputs.bump-type }} --git-tag-version false
shell: bash

- if: monorepo-bump != 'false'
run: |
PROJECT_ROOT=$(pwd)
declare -a BUMP_LIST=(${{ inputs.monorepo-bump }})
for item in "${BUMP_LIST[@]}"; do
cd $PROJECT_ROOT
cd "$item"
npm version ${{ steps.bump.outputs.bump-type }} --git-tag-version false
done
shell: bash

- run: echo -e "\n${{env.blue}}=== Generate changelog preview for PR ===\n"
shell: bash

Expand Down
63 changes: 59 additions & 4 deletions publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ inputs:
required: false
default: '16'

monorepo-public-npm-token:
description: NPM auth token.
required: false
default: ''

monorepo-public-npm-publish:
description: Monorepo public npm packages.
required: false
default: 'false'

monorepo-private-npm-token:
description: NPM auth token.
required: false
default: ''

monorepo-private-npm-publish:
description: Monorepo private npm packages.
required: false
default: 'false'

outputs:
tag:
description: Package tag.
Expand Down Expand Up @@ -113,6 +133,8 @@ runs:
NPMRC_AUTH_EXISTS=$(grep -c _auth .npmrc)
if [ ${NPMRC_AUTH_EXISTS:-0} == 0 ] && [ $NPM_TOKEN != '' ]; then npm config set _auth=$NPM_TOKEN --location=project; fi
npm publish --registry=${{ inputs.npm-private-registry }}
rm .npmrc
git checkout .npmrc || true
shell: bash

- if: inputs.npm-publish == 'public'
Expand All @@ -125,9 +147,42 @@ runs:
npm config set "//registry.npmjs.org/:_authToken=${{ inputs.npm-token }}" --location=project
npm config set "always-auth=true" --location=project
npm publish --access=public
npm config delete "registry" --location=project
npm config delete "//registry.npmjs.org/:_authToken" --location=project
npm config delete "always-auth" --location=project
rm .npmrc
git checkout .npmrc || true
shell: bash

- if: inputs.monorepo-private-npm-publish != 'false' && inputs.monorepo-private-npm-token != ''
run: |
PROJECT_ROOT=$(pwd)
declare -a PUBLIC_NPM_LIST=(${{ inputs.monorepo-private-npm-publish }})
for item in "${PUBLIC_NPM_LIST[@]}"; do
cd $PROJECT_ROOT
cd "$item"
npm run build
NPM_TOKEN=${{ inputs.monorepo-private-npm-token }}
NPMRC_AUTH_EXISTS=$(grep -c _auth .npmrc)
if [ ${NPMRC_AUTH_EXISTS:-0} == 0 ] && [ $NPM_TOKEN != '' ]; then npm config set _auth=$NPM_TOKEN --location=project; fi
npm publish --registry=${{ inputs.npm-private-registry }}
rm .npmrc
git checkout .npmrc || true
done
shell: bash

- if: inputs.monorepo-public-npm-publish != 'false' && inputs.monorepo-public-npm-token != ''
run: |
PROJECT_ROOT=$(pwd)
declare -a PUBLIC_NPM_LIST=(${{ inputs.monorepo-public-npm-publish }})
for item in "${PUBLIC_NPM_LIST[@]}"; do
cd $PROJECT_ROOT
cd "$item"
npm run build
npm config set "registry=https://registry.npmjs.org" --location=project
npm config set "//registry.npmjs.org/:_authToken=${{ inputs.monorepo-public-npm-token }}" --location=project
npm config set "always-auth=true" --location=project
npm publish --access=public
rm .npmrc
git checkout .npmrc || true
done
shell: bash

- run: echo -e "\n${{env.blue}}=== Add Git tag and publish GitHub release ===\n"
Expand All @@ -148,7 +203,7 @@ runs:
- if: inputs.major-bump == 'true'
uses: thejeff77/[email protected]
with:
tag: ${{ inputs.major-bump-tag-prefix }}${{ steps.version.outputs.major }}
tag: '${{ inputs.major-bump-tag-prefix }}${{ steps.version.outputs.major }}'
force: true

- run: echo -e "\n${{env.blue}}=== Delete release branch ===\n"
Expand Down
2 changes: 1 addition & 1 deletion setup-npm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ runs:
shell: bash

- run: |
npm ci --ignore-scripts
npm ci
npm config set registry https://registry.npmjs.org/ --location=project
npm i -D conventional-changelog@5 conventional-changelog-cli@4 conventional-recommended-bump@9 @localazy/conventional-changelog-preset https://github.com/localazy/conventional-changelog-writer.git
rm .npmrc
Expand Down

0 comments on commit 92b6c53

Please sign in to comment.