Skip to content

Configure git and npm for CI/CD pipeline #3

Configure git and npm for CI/CD pipeline

Configure git and npm for CI/CD pipeline #3

Workflow file for this run

name: Release
on:
pull_request:
branches:
- main
types: [closed]
env:
CI: true
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
jobs:
publish:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
steps:
- name: Pull Request Merged
if: github.event.pull_request.merged == false
run: |
echo 'The pull request has not been merged'
exit 1
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set git config
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Setup .npmrc
shell: bash
run: |
npm set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Ensure access
shell: bash
run: npm whoami --registry https://registry.npmjs.org/
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
- name: Run lint
run: npm run lint
- name: Run tests with coverage
run: npm run coverage
- name: Upload coverage
uses: coverallsapp/github-action@v2
- name: Build the project
run: npm run build
- name: Get Prev Version
shell: bash -ex {0}
run: |
PREV_VERSION=$(node -p 'require("./lerna.json").version')
echo "::set-env name=PREV_VERSION::${PREV_VERSION}"
- name: Bump versions and publish packages
run: |
npx lerna version --yes --conventional-commits --message 'chore(release): publish'
npx lerna publish from-package --yes
- name: Get Current Version
shell: bash -ex {0}
run: |
CURRENT_VERSION=$(node -p 'require("./lerna.json").version')
echo "::set-env name=CURRENT_VERSION::${CURRENT_VERSION}"
- name: Create comment
uses: actions/github-script@v7
if: env.PREV_VERSION != env.CURRENT_VERSION
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'NPM package v${{ env.CURRENT_VERSION }} has been published 🎉'
})