New features for version 0.6.0 of Krmx (#7) #13
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 | |
concurrency: | |
group: "publish" | |
cancel-in-progress: false | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
strategy: | |
max-parallel: 1 # has to be 1 (one) as there are dependencies between the published packages | |
matrix: | |
package: [ base, server, client, client-react ] | |
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 ! .github/tools/semver-greater.sh "$REMOTE_VERSION" "$LOCAL_VERSION"; then | |
echo "[!!] Skipped publish as the local version of @krmx/${{ matrix.package }} is not greater than what 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 | |
done | |
fi | |
# Check if there are local dev dependencies in the package.json | |
if jq -e '.devDependencies | to_entries[] | select(.value | startswith("file:")) | length > 0' package.json &> /dev/null; then | |
echo "Found local dev dependencies in package.json, updating them now." | |
jq -r '.devDependencies | 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 dev dependencies $pkg to ^$version (found in ${path#file:}/package.json)" | |
npm install $pkg@^$version --save-dev | |
done | |
fi | |
# Run tests and build the package | |
npm run validate | |
# Publish the package | |
npm publish --provenance --access public | |
fi |