|
| 1 | +name: Publish NPM package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v2 |
| 13 | + with: |
| 14 | + fetch-depth: 0 |
| 15 | + |
| 16 | + - name: Setup Node.js |
| 17 | + uses: actions/setup-node@v2 |
| 18 | + with: |
| 19 | + node-version: "20" |
| 20 | + registry-url: "https://registry.npmjs.org" |
| 21 | + |
| 22 | + - name: Install dependencies |
| 23 | + run: npm install |
| 24 | + |
| 25 | + # - name: Test |
| 26 | + # run: npm test |
| 27 | + |
| 28 | + - name: Check the version |
| 29 | + id: check |
| 30 | + run: | |
| 31 | + CURRENT_VERSION=$(jq -r .version package.json) |
| 32 | + echo "Current version: $CURRENT_VERSION" |
| 33 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 34 | + echo "Latest tag: $LATEST_TAG" |
| 35 | +
|
| 36 | + LATEST_VERSION=${LATEST_TAG#v} |
| 37 | +
|
| 38 | + if [ "$LATEST_VERSION" = "$CURRENT_VERSION" ]; |
| 39 | + then |
| 40 | + echo "Version is equal" |
| 41 | + echo "version_equal=true" >> $GITHUB_OUTPUT |
| 42 | + echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + echo "Version is not equal" |
| 45 | + echo "version_equal=false" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Build |
| 49 | + run: npm run build |
| 50 | + if: steps.check.outputs.version_equal == 'true' |
| 51 | + |
| 52 | + - name: Publish |
| 53 | + if: steps.check.outputs.version_equal == 'true' |
| 54 | + run: npm publish --access public --no-git-checks |
| 55 | + env: |
| 56 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 57 | + |
| 58 | + # - name: Git Info Update |
| 59 | + # if: steps.check.outputs.version_equal == 'true' |
| 60 | + # run: | |
| 61 | + # git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 62 | + # git config --local user.name "github-actions[bot]" |
| 63 | + - name: Create GitHub release |
| 64 | + if: steps.check.outputs.version_equal == 'true' |
| 65 | + run: | |
| 66 | + gh release create "v${{ steps.check.outputs.new_version }}" --title "v${{ steps.check.outputs.new_version }}" |
| 67 | + env: |
| 68 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments