Skip to content

Commit

Permalink
chore: add conditions to optimze workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tribiec committed Jan 24, 2024
1 parent d72d052 commit a75f355
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ name: Node.js CI

on:
push:
branches: [master]
branches:
- '**'
tags:
- '*'
pull_request:
branches: [master]
branches:
- '**'

jobs:
build:
test:
runs-on: ubuntu-18.04

strategy:
matrix:
node-version: [11.x, 12.x, 13.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -24,22 +24,32 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test

build-and-publish:
if: github.ref == 'refs/heads/master' && startsWith(github.ref, 'refs/tags/')
needs: test
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: '11.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
- name: npm publish
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

0 comments on commit a75f355

Please sign in to comment.