diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml deleted file mode 100644 index 3f42d32c..00000000 --- a/.github/workflows/actions.yml +++ /dev/null @@ -1,38 +0,0 @@ -on: [push] - -jobs: - test: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [14.x] - - steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: npm install, build, and test - run: | - npm install - npm run test - npm run build - - name: Upload coverage to Codecov - if: runner.os == 'Linux' - uses: codecov/codecov-action@v1.0.3 - with: - token: ${{secrets.CODECOV_TOKEN}} - file: ./coverage.lcov - # take this to a new action on release or tagging - - name: npm publish - uses: actions/setup-node@v1 - - name: Publish - if: startsWith(github.ref, 'refs/tags/') - run: | - cd lib - echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc - npm publish --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/deploy-npm.yml b/.github/workflows/deploy-npm.yml new file mode 100644 index 00000000..f0443b37 --- /dev/null +++ b/.github/workflows/deploy-npm.yml @@ -0,0 +1,82 @@ +name: Deploy to NPM + +on: + workflow_dispatch: + pull_request: + branches: + - master + types: + - closed + +permissions: + id-token: write # allows the JWT to be requested from GitHub's OIDC provider + contents: read # This is required for actions/checkout + +jobs: + deploy-tag: + name: Deploy to NPM + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/master') || github.event.pull_request.merged == true + steps: + - name: Checkout source branch + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Build files + env: + HUSKY: 0 + run: | + npm ci + npm run build + + - name: Publish package to NPM + env: + HUSKY: 0 + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + npm set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} + cd lib + npm publish + + - name: Get new version number + run: | + current_version=$(jq -r .version package.json) + echo "CURRENT_VERSION_VALUE=$current_version" >> $GITHUB_ENV + echo "DATE=$(date)" >> $GITHUB_ENV + + - name: Send message to Slack channel + id: slack + uses: slackapi/slack-github-action@v1.23.0 + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + PROJECT_NAME: 'Node SDK' + NPM_PACKAGE_URL: 'https://www.npmjs.com/package/@rudderstack/rudder-sdk-node' + with: + channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }} + payload: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "New release: ${{ env.PROJECT_NAME }}" + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Release: <${{ env.NPM_PACKAGE_URL }}|${{ env.CURRENT_VERSION_VALUE }}>*\n${{ env.DATE }}" + } + } + ] + }