|
| 1 | +name: Common NPM module CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + timeout-minutes: 5 |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Setup Node.js |
| 15 | + uses: actions/setup-node@master |
| 16 | + with: |
| 17 | + node-version: '18.12' |
| 18 | + |
| 19 | + - uses: actions/checkout@v2 |
| 20 | + with: |
| 21 | + persist-credentials: false |
| 22 | + |
| 23 | + - name: NPM install |
| 24 | + run: npm ci --audit=false --ignore-scripts |
| 25 | + |
| 26 | + - name: Lint JavaScript with ESLint |
| 27 | + uses: a-b-r-o-w-n/[email protected] |
| 28 | + with: |
| 29 | + repo-token: '${{ secrets.GITHUB_TOKEN }}' |
| 30 | + |
| 31 | + release: |
| 32 | + timeout-minutes: 10 |
| 33 | + if: github.ref == 'refs/heads/main' |
| 34 | + runs-on: ubuntu-latest |
| 35 | + needs: [test] |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v2 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: 'Automated version bump' |
| 42 | + uses: 'phips28/gh-action-bump-version@master' |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + with: |
| 46 | + default: patch |
| 47 | + commit-message: 'Version bump to {{version}} [skip ci]' |
| 48 | + tag-prefix: 'v' |
| 49 | + |
| 50 | + - name: Export package version |
| 51 | + id: package |
| 52 | + run: | |
| 53 | + echo ::set-output name=package_version::`cat package.json | jq -r .version` |
| 54 | + shell: bash |
| 55 | + |
| 56 | + - run: echo ${{ steps.package.outputs.package_version }} |
| 57 | + |
| 58 | + - name: Find and Replace |
| 59 | + uses: jacobtomlinson/gha-find-replace@v2 |
| 60 | + with: |
| 61 | + find: "[0-9]+\\.[0-9]+\\.[0-9]+" |
| 62 | + replace: ${{ steps.package.outputs.package_version }} |
| 63 | + regex: true |
| 64 | + include: 'README.md' |
| 65 | + |
| 66 | + - name: 'Version bump in README.md to {{version}} [skip ci]' |
| 67 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 68 | + with: |
| 69 | + commit_message: 'Version bump in README.md to ${{ steps.package.outputs.package_version }} [skip ci]' |
| 70 | + file_pattern: README.md |
| 71 | + |
| 72 | + - uses: JS-DevTools/npm-publish@v1 |
| 73 | + id: publish |
| 74 | + with: |
| 75 | + token: ${{ secrets.NPM_TOKEN }} |
| 76 | + check-version: true |
| 77 | + dry-run: false |
| 78 | + access: 'public' |
| 79 | + |
| 80 | + - if: steps.publish.outputs.type != 'none' |
| 81 | + run: | |
| 82 | + echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}" |
| 83 | + - name: Create new release |
| 84 | + if: steps.publish.outputs.type != 'none' |
| 85 | + id: create_release |
| 86 | + uses: actions/create-release@v1 |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 89 | + with: |
| 90 | + tag_name: 'v${{ steps.publish.outputs.version }}' |
| 91 | + release_name: 'v${{ steps.publish.outputs.version }}' |
| 92 | + draft: false |
| 93 | + prerelease: false |
0 commit comments