react-timeago
Version:
A simple Time-Ago component for ReactJs
105 lines (83 loc) • 2.65 kB
YAML
name: Build and Deploy
on:
push:
branches: [ master ]
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]
pull_request:
branches: [ master ]
jobs:
pr-test:
# Only run on pull requests
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 22
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm test
build:
# Only run on pushes to master or tags
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 22
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm test
deploy:
needs: build
# Only run on master branch and not on pull requests
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm test
- name: Build
run: pnpm run build
- name: Check if version exists
id: version-check
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
PKG_NAME=$(node -p "require('./package.json').name")
if npm view "$PKG_NAME@$PKG_VERSION" version &> /dev/null; then
echo "Version $PKG_VERSION already exists. Skipping publish."
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Version $PKG_VERSION does not exist. Proceeding with publish."
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
if: steps.version-check.outputs.exists == 'false'
run: pnpm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}