|
| 1 | +name: Publish to NPM |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Setup Node.js |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '20' |
| 24 | + cache: 'npm' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: npm i |
| 28 | + |
| 29 | + - name: Prepare Nuxt environment |
| 30 | + run: npm run dev:prepare |
| 31 | + |
| 32 | + # - name: Run linting |
| 33 | + # run: npm run lint |
| 34 | + |
| 35 | + publish: |
| 36 | + needs: test |
| 37 | + runs-on: ubuntu-latest |
| 38 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
| 39 | + steps: |
| 40 | + - name: Checkout code |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Setup Node.js |
| 47 | + uses: actions/setup-node@v4 |
| 48 | + with: |
| 49 | + node-version: '20' |
| 50 | + cache: 'npm' |
| 51 | + registry-url: 'https://registry.npmjs.org' |
| 52 | + |
| 53 | + - name: Install dependencies |
| 54 | + run: npm i |
| 55 | + |
| 56 | + - name: Prepare Nuxt environment |
| 57 | + run: npm run dev:prepare |
| 58 | + |
| 59 | + - name: Build module |
| 60 | + run: npm run prepack |
| 61 | + |
| 62 | + - name: Configure Git |
| 63 | + run: | |
| 64 | + git config --global user.name "github-actions[bot]" |
| 65 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 66 | +
|
| 67 | + - name: Check if version changed |
| 68 | + id: version-check |
| 69 | + run: | |
| 70 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 71 | + echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + # Check if this version exists on npm |
| 74 | + if npm view @atmoner/nuxt-electron@$CURRENT_VERSION version >/dev/null 2>&1; then |
| 75 | + echo "version-exists=true" >> $GITHUB_OUTPUT |
| 76 | + echo "Version $CURRENT_VERSION already exists on npm" |
| 77 | + else |
| 78 | + echo "version-exists=false" >> $GITHUB_OUTPUT |
| 79 | + echo "Version $CURRENT_VERSION is new" |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Bump version |
| 83 | + if: steps.version-check.outputs.version-exists == 'true' |
| 84 | + run: | |
| 85 | + npm version patch --no-git-tag-version |
| 86 | + NEW_VERSION=$(node -p "require('./package.json').version") |
| 87 | + echo "New version: $NEW_VERSION" |
| 88 | +
|
| 89 | + - name: Commit version bump |
| 90 | + if: steps.version-check.outputs.version-exists == 'true' |
| 91 | + run: | |
| 92 | + git add package.json |
| 93 | + git commit -m "chore: bump version to $(node -p "require('./package.json').version") [skip ci]" |
| 94 | + git push |
| 95 | +
|
| 96 | + - name: Create Git tag |
| 97 | + run: | |
| 98 | + VERSION=$(node -p "require('./package.json').version") |
| 99 | + git tag -a "v$VERSION" -m "Release v$VERSION" |
| 100 | + git push origin "v$VERSION" |
| 101 | +
|
| 102 | + - name: Publish to NPM |
| 103 | + run: npm publish --access public |
| 104 | + env: |
| 105 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 106 | + |
| 107 | + - name: Create GitHub Release |
| 108 | + uses: actions/create-release@v1 |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + with: |
| 112 | + tag_name: v${{ steps.version-check.outputs.current-version }} |
| 113 | + release_name: Release v${{ steps.version-check.outputs.current-version }} |
| 114 | + body: | |
| 115 | + Automated release of @atmoner/nuxt-electron v${{ steps.version-check.outputs.current-version }} |
| 116 | +
|
| 117 | + ## Changes |
| 118 | + See the [changelog](https://github.com/${{ github.repository }}/compare/v${{ steps.version-check.outputs.current-version }}...HEAD) for details. |
| 119 | + draft: false |
| 120 | + prerelease: false |
0 commit comments