|
| 1 | +name: Test and Release |
| 2 | + |
| 3 | +# Run this job on all pushes and pull requests |
| 4 | +# as well as tags with a semantic version |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - "*" |
| 9 | + tags: |
| 10 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 11 | + pull_request: {} |
| 12 | + |
| 13 | +jobs: |
| 14 | + # Runs tests on all supported node versions and OSes |
| 15 | + tests: |
| 16 | + if: contains(github.event.head_commit.message, '[skip ci]') == false |
| 17 | + |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + node-version: [8.x, 10.x, 12.x] |
| 22 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 23 | + exclude: |
| 24 | + # Don't test Node.js 8 on Windows. npm is weird here |
| 25 | + - os: windows-latest |
| 26 | + node-version: 8.x |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v1 |
| 29 | + - name: Use Node.js ${{ matrix.node-version }} |
| 30 | + uses: actions/setup-node@v1 |
| 31 | + with: |
| 32 | + node-version: ${{ matrix.node-version }} |
| 33 | + |
| 34 | + - name: Install package |
| 35 | + run: npm i |
| 36 | + |
| 37 | + - name: Run unit tests |
| 38 | + run: npm run test |
| 39 | + |
| 40 | + # Deploys the final package to NPM |
| 41 | + deploy: |
| 42 | + needs: [tests] |
| 43 | + |
| 44 | + # Trigger this step only when a commit on master is tagged with a version number |
| 45 | + if: | |
| 46 | + contains(github.event.head_commit.message, '[skip ci]') == false && |
| 47 | + github.event_name == 'push' && |
| 48 | + github.event.base_ref == 'refs/heads/master' && |
| 49 | + startsWith(github.ref, 'refs/tags/v') |
| 50 | +
|
| 51 | + runs-on: ubuntu-latest |
| 52 | + strategy: |
| 53 | + matrix: |
| 54 | + node-version: [12.x] |
| 55 | + |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v1 |
| 58 | + - name: Use Node.js ${{ matrix.node-version }} |
| 59 | + uses: actions/setup-node@v1 |
| 60 | + with: |
| 61 | + node-version: ${{ matrix.node-version }} |
| 62 | + |
| 63 | + - name: Install package |
| 64 | + run: npm i |
| 65 | + |
| 66 | + - name: Publish package to npm |
| 67 | + run: | |
| 68 | + npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} |
| 69 | + npm whoami |
| 70 | + npm publish |
| 71 | +
|
| 72 | + # Dummy job for skipped builds - without this, github reports the build as failed |
| 73 | + skip-ci: |
| 74 | + if: contains(github.event.head_commit.message, '[skip ci]') |
| 75 | + runs-on: ubuntu-latest |
| 76 | + steps: |
| 77 | + - name: Skip build |
| 78 | + run: echo "Build skipped!" |
0 commit comments