diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml index 68505732..248c4adf 100644 --- a/.github/workflows/npm.yml +++ b/.github/workflows/npm.yml @@ -7,9 +7,15 @@ on: push: tags: - "v*.*.*" + pull_request: + paths: + - 'solidity/**.sol' + - 'solidity/package.json' + - 'solidity/release.sh' + - '.github/workflows/npm.yml' jobs: - build: + release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -17,8 +23,15 @@ jobs: with: node-version: 18 registry-url: https://registry.npmjs.org/ - - run: | + + - name: Set ENV + id: env + if: github.event_name != 'pull_request' + run: echo "NODE_AUTH_TOKEN=${{secrets.NPM_TOKEN}}" >> $GITHUB_ENV + + - name: Release + run: | chmod +x ./solidity/release.sh ./solidity/release.sh env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} \ No newline at end of file + NODE_AUTH_TOKEN: ${{ steps.env.outputs.NODE_AUTH_TOKEN }} \ No newline at end of file diff --git a/solidity/release.sh b/solidity/release.sh index dc4c2566..814d4638 100755 --- a/solidity/release.sh +++ b/solidity/release.sh @@ -15,6 +15,13 @@ if [ -d "$project_dir/solidity" ]; then solidity_dir="$project_dir/solidity" fi +package_name=$(jq -r '.name' "$solidity_dir/package.json") +last_version=$(npm info "$package_name" version) +latest_version=$(jq -r '.version' "$solidity_dir/package.json") +if [ "$last_version" == "$latest_version" ]; then + echo "The latest version of $package_name is already published." && exit 0 +fi + if [ ! -f "$solidity_dir/hardhat.config.ts" ]; then echo "This script must be run from the root of the repository." && exit 1 fi @@ -42,5 +49,9 @@ done # publish contracts package ( cd "$solidity_dir/contracts" - npm publish --access public + if [ -z "$NODE_AUTH_TOKEN" ]; then + npm publish --dry-run + else + npm publish --access public + fi )