|
| 1 | +name: NPM Package Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - next |
| 8 | + - alpha |
| 9 | + - v2 |
| 10 | + |
| 11 | +jobs: |
| 12 | + publish-npm: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v2 |
| 17 | + |
| 18 | + - name: Check if version has been updated |
| 19 | + id: check |
| 20 | + uses: EndBug/version-check@v1 |
| 21 | + |
| 22 | + - name: Setup Node 10 |
| 23 | + if: steps.check.outputs.changed == 'true' |
| 24 | + uses: actions/setup-node@v1 |
| 25 | + with: |
| 26 | + node-version: 10 |
| 27 | + registry-url: https://registry.npmjs.org/ |
| 28 | + |
| 29 | + # Setup dependency caching |
| 30 | + - uses: actions/cache@v1 |
| 31 | + if: steps.check.outputs.changed == 'true' |
| 32 | + with: |
| 33 | + path: ~/.npm |
| 34 | + key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} |
| 35 | + |
| 36 | + - name: Install Dependencies |
| 37 | + if: steps.check.outputs.changed == 'true' |
| 38 | + run: npm ci |
| 39 | + |
| 40 | + - name: Check For Lint |
| 41 | + if: steps.check.outputs.changed == 'true' |
| 42 | + run: npm run lint |
| 43 | + |
| 44 | + - name: Run Unit Tests + Coverage |
| 45 | + if: steps.check.outputs.changed == 'true' |
| 46 | + env: |
| 47 | + CODE_CLIMATE: ${{ secrets.CODE_CLIMATE }} |
| 48 | + run: npm run test:cov |
| 49 | + |
| 50 | + - name: Publish |
| 51 | + if: steps.check.outputs.changed == 'true' |
| 52 | + env: |
| 53 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 54 | + GITHUB_REF: ${{ github.ref }} |
| 55 | + run: | |
| 56 | + gitBranch=${GITHUB_REF##*/} |
| 57 | + publishFlag=$(if [ "$GITHUB_REF" != 'refs/heads/master' ]; then eval echo '--tag $gitBranch'; else echo ''; fi;) |
| 58 | + echo "::set-env name=PACKAGE_VERSION::$(cat package.json | jq -r '.version')" |
| 59 | + npm publish $publishFlag |
| 60 | +
|
| 61 | + - name: Upload Coverage |
| 62 | + if: steps.check.outputs.changed == 'true' |
| 63 | + env: |
| 64 | + CODE_COV: ${{ secrets.CODE_COV }} |
| 65 | + # Upload to Code Cover. Curl used in place of codecov/codecov-action |
| 66 | + # due to long build time. See https://github.com/codecov/codecov-action/issues/21 |
| 67 | + run: curl -s https://codecov.io/bash | bash -s -- -t $CODE_COV |
| 68 | + |
| 69 | + - name: Create Release |
| 70 | + if: github.ref == 'refs/heads/master' && steps.check.outputs.changed == 'true' |
| 71 | + id: create_release |
| 72 | + uses: actions/create-release@latest |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ github.token }} |
| 75 | + with: |
| 76 | + tag_name: v${{ env.PACKAGE_VERSION }} |
| 77 | + release_name: v${{ env.PACKAGE_VERSION }} |
| 78 | + draft: false |
| 79 | + prerelease: false |
0 commit comments