|
| 1 | +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created |
| 2 | +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages |
| 3 | + |
| 4 | +name: Publish NPM |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + paths: |
| 11 | + - 'credentials/**' |
| 12 | + - 'nodes/**' |
| 13 | + - 'package.json' |
| 14 | + - 'tsconfig.json' |
| 15 | + - 'gulpfile.js' |
| 16 | + - 'README.md' |
| 17 | + - 'LICENSE.md' |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + packages: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + |
| 32 | + - name: Install Node.js |
| 33 | + uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version: 20 |
| 36 | + registry-url: 'https://registry.npmjs.org' |
| 37 | + |
| 38 | + - uses: pnpm/action-setup@v4 |
| 39 | + name: Install pnpm |
| 40 | + with: |
| 41 | + version: 10 |
| 42 | + - name: Get pnpm store directory |
| 43 | + id: pnpm-cache |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - uses: actions/cache@v4 |
| 49 | + name: Setup pnpm cache |
| 50 | + with: |
| 51 | + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} |
| 52 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 53 | + restore-keys: | |
| 54 | + ${{ runner.os }}-pnpm-store- |
| 55 | +
|
| 56 | + - name: Install dependencies |
| 57 | + run: pnpm install |
| 58 | + |
| 59 | + - name: Build package |
| 60 | + run: pnpm build |
| 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 for releasable commits |
| 68 | + id: check-commits |
| 69 | + run: | |
| 70 | + # Get the last release tag |
| 71 | + LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 72 | +
|
| 73 | + if [ -z "$LAST_TAG" ]; then |
| 74 | + echo "No previous tags found, will create initial release" |
| 75 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 76 | + echo "version_type=minor" >> $GITHUB_OUTPUT |
| 77 | + else |
| 78 | + # Check for release prefix commits (force major version update) |
| 79 | + RELEASE_COMMITS=$(git log $LAST_TAG..HEAD --oneline --grep="^release" || echo "") |
| 80 | + if [ -n "$RELEASE_COMMITS" ]; then |
| 81 | + echo "Found release commits, triggering major version update" |
| 82 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 83 | + echo "version_type=major" >> $GITHUB_OUTPUT |
| 84 | + exit 0 |
| 85 | + fi |
| 86 | +
|
| 87 | + # Check for breaking changes |
| 88 | + BREAKING_COMMITS=$(git log $LAST_TAG..HEAD --grep="BREAKING CHANGE:" -i || echo "") |
| 89 | + if [ -n "$BREAKING_COMMITS" ]; then |
| 90 | + echo "Found breaking changes, triggering major version update" |
| 91 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 92 | + echo "version_type=major" >> $GITHUB_OUTPUT |
| 93 | + exit 0 |
| 94 | + fi |
| 95 | +
|
| 96 | + # Check for new features or performance improvements |
| 97 | + FEAT_COMMITS=$(git log $LAST_TAG..HEAD --oneline --grep="^feat\|^perf" || echo "") |
| 98 | + if [ -n "$FEAT_COMMITS" ]; then |
| 99 | + echo "Found new features, triggering minor version update" |
| 100 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 101 | + echo "version_type=minor" >> $GITHUB_OUTPUT |
| 102 | + exit 0 |
| 103 | + fi |
| 104 | +
|
| 105 | + # Check other normal commits |
| 106 | + COMMITS=$(git log $LAST_TAG..HEAD --oneline --grep="^fix\|^refactor\|^docs\|^style\|^test\|^build\|^ci\|^chore\|^revert" || echo "") |
| 107 | + if [ -n "$COMMITS" ]; then |
| 108 | + echo "Found releasable commits since $LAST_TAG" |
| 109 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 110 | + echo "version_type=patch" >> $GITHUB_OUTPUT |
| 111 | + else |
| 112 | + echo "No releasable commits found since $LAST_TAG" |
| 113 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 114 | + fi |
| 115 | + fi |
| 116 | +
|
| 117 | + - name: Generate release |
| 118 | + if: steps.check-commits.outputs.should_release == 'true' |
| 119 | + run: | |
| 120 | + if [ "${{ steps.check-commits.outputs.version_type }}" == "major" ]; then |
| 121 | + echo "Running major release" |
| 122 | + pnpm release:major |
| 123 | + elif [ "${{ steps.check-commits.outputs.version_type }}" == "minor" ]; then |
| 124 | + echo "Running minor release" |
| 125 | + pnpm release:minor |
| 126 | + else |
| 127 | + echo "Running patch release" |
| 128 | + pnpm release:patch |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: Push changes and tags |
| 132 | + if: steps.check-commits.outputs.should_release == 'true' |
| 133 | + run: | |
| 134 | + git push --follow-tags origin main |
| 135 | + env: |
| 136 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 137 | + |
| 138 | + - name: Publish package |
| 139 | + if: steps.check-commits.outputs.should_release == 'true' |
| 140 | + run: npm publish --access public |
| 141 | + env: |
| 142 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments