Skip to content

Deploy to NPM

Deploy to NPM #72

Workflow file for this run

name: Deploy to NPM
on:
workflow_dispatch:
workflow_run:
workflows: ['Publish new github release']
types:
- completed
jobs:
deploy-npm:
name: Deploy to NPM
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/master') || github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout source branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout to master
if: github.event.workflow_run.conclusion == 'success'
run: git checkout master
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Setup npm login
run: |
npm set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
- name: Install node_modules
env:
HUSKY: 0
run: |
rm -rf node_modules
npm run setup:ci
- name: Get the two latest versions
run: |
CURRENT_VERSION=$(git tag -l "v*" --sort=-version:refname | head -n 1)
LAST_VERSION=$(git tag -l "v*" --sort=-version:refname | head -n 2 | awk 'NR == 2 { print $1 }')
echo "Current version: $CURRENT_VERSION"
echo "Previous version: $LAST_VERSION"
echo "current_version=$(echo $CURRENT_VERSION)" >> $GITHUB_ENV
echo "last_version=$(echo $LAST_VERSION)" >> $GITHUB_ENV
echo "DATE=$(date)" >> $GITHUB_ENV
- name: Build & Publish affected packages
run: |
npm run deploy:npm -- --base=$last_version --head=$current_version
- name: Send message to Slack channel
id: slack
uses: slackapi/slack-github-action@v2.0.0
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
PROJECT_NAME: 'React Native SDK npm packages'
NPM_PACKAGE_URL: 'https://www.npmjs.com/search?q=%40rudderstack'
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 }}|Latest Packages>*\n${{ env.DATE }}"
}
}
]
}