Merge pull request #52 from orochi-network/misc/update_package_version #22
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 Orochi Smart Contracts | |
on: | |
push: | |
branches: ['main'] | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} | |
jobs: | |
publish: | |
name: Build & Publish package | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [18.x] | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Publish smart contracts | |
env: | |
NPM_TOKEN: ${{ env.NPM_TOKEN }} | |
run: | | |
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > ~/.npmrc | |
cd ./package | |
PACKAGE_NAME=$(node -p "require('./package.json').name") | |
NPM_VERSION=$(npm show "$PACKAGE_NAME" version 2>/dev/null || echo 0.0.0) | |
PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
NPM_NUMBER=$(echo $NPM_VERSION | sed 's/[^0-9]//g') | |
PACKAGE_NUMBER=$(echo $PACKAGE_VERSION | sed 's/[^0-9]//g') | |
max_length=$((${#NPM_NUMBER} > ${#PACKAGE_NUMBER} ? ${#NPM_NUMBER} : ${#PACKAGE_NUMBER})) | |
FIXED_NPM_VERSION=$(echo $NPM_NUMBER$(printf -- 0%.s $(seq -s ' ' $((max_length-${#NPM_NUMBER}))))) | |
FIXED_PACKAGE_NUMBER=$(echo $PACKAGE_NUMBER$(printf -- 0%.s $(seq -s ' ' $((max_length-${#PACKAGE_NUMBER}))))) | |
if [ ${FIXED_NPM_VERSION} -ge ${FIXED_PACKAGE_NUMBER} ]; then | |
echo "Ignore ${PACKAGE_NAME} since no changes" | |
else | |
cd ../ | |
yarn | |
yarn run build:all | |
cd ./package | |
npm run release | |
fi |