Install package dependencies before local updates, and update local u… #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish packages to npm | |
on: | |
push: | |
branches: | |
- main | |
- 0.6.0 | |
concurrency: | |
group: "publish" | |
cancel-in-progress: false | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
publish: | |
strategy: | |
max-parallel: 1 # has to be 1 (one) as there are dependencies between the published packages | |
matrix: | |
package: [base, server] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '22.x' | |
registry-url: 'https://registry.npmjs.org' | |
scope: '@krmx' | |
- name: Publish Packages | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
cd ${{ matrix.package }} | |
echo "-- @krmx/${{ matrix.package }} --" | |
LOCAL_VERSION=$(node -e "console.log(require('./package.json').version);") | |
echo "Local version: $LOCAL_VERSION" | |
REMOTE_VERSION=$(npm show "@krmx/${{ matrix.package }}" version) | |
echo "Remote version: $REMOTE_VERSION" | |
if [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]; then | |
echo "[!!] Publishing skipped as the version is already published." | |
else | |
echo "[!!] Publishing is required." | |
# Install the package dependencies | |
npm install | |
# Check if there are local dependencies in the package.json | |
if jq -e '.dependencies | to_entries[] | select(.value | startswith("file:")) | length > 0' package.json &> /dev/null; then | |
echo "Found local dependencies in package.json, updating them now." | |
jq -r '.dependencies | to_entries[] | select(.value | startswith("file:")) | .key + "|" + .value' package.json | | |
while IFS="|" read -r pkg path; do | |
version=$(jq -r .version ${path#file:}/package.json) | |
echo "- Updating dependencies $pkg to ^$version (found in ${path#file:}/package.json)" | |
npm install $pkg@^$version | |
cat package-lock.json | jq .packages.'"node_modules/@krmx/$pkg"' | |
done | |
fi | |
# Print information about the package | |
cat package.json | |
cat package-lock.json | |
# Run tests and build the package | |
npm run precommit | |
# Publish the package | |
# npm publish --access public | |
fi |