Skip to content

Commit

Permalink
Improve github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Jashepp committed Aug 30, 2023
1 parent cd52489 commit e0068ff
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 51 deletions.
47 changes: 0 additions & 47 deletions .github/workflows/npm-publish-github-packages.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/publish-gpr-dryrun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Dry Run - Publish to GitHub Package Registry
on:
push:
paths:
- '.github/workflows/publish-gpr**.yml'
pull_request:
paths:
- '.github/workflows/publish-gpr**.yml'

jobs:

publish-gpr:
name: Dry Run - Publish to GitHub Package Registry
if: ${{ github.event_name != 'release' }}
uses: ./.github/workflows/publish-gpr.yml
19 changes: 19 additions & 0 deletions .github/workflows/publish-gpr-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: On Release - Publish to GitHub Package Registry
on:
release:
types: [created]

jobs:

run-tests:
name: Run Tests
if: ${{ github.event_name == 'release' }}
uses: ./.github/workflows/run-tests.yml

publish-gpr:
name: Publish to GitHub Package Registry
if: ${{ github.event_name == 'release' }}
needs: run-tests
uses: ./.github/workflows/publish-gpr.yml
70 changes: 70 additions & 0 deletions .github/workflows/publish-gpr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Callee - publish-gpr
on:
workflow_call:

jobs:

publish-gpr:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:

# https://github.com/actions/cache/blob/main/examples.md#node---npm
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

# https://github.com/actions/cache/releases
- name: Use cache for npm
uses: actions/[email protected]
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: npm-${{ hashFiles('package.json') }}
restore-keys: npm-

# https://github.com/actions/checkout/releases
- name: Checkout
uses: actions/[email protected]

- name: Build package-lock
run: npm i --package-lock-only

# https://github.com/actions/setup-node/releases
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: latest
registry-url: https://npm.pkg.github.com/
scope: '@Jashepp'

- name: Clean & Install Deps
run: npm ci

- name: Run Final Tests
run: npm test

- name: Publish to GitHub Package Registry - Dry Run
if: ${{ github.event_name != 'release' }}
run: |
npm config set scope "@Jashepp"
npm config set @Jashepp:registry https://npm.pkg.github.com/
npm pkg set name=@Jashepp/eventemitter-wrapper
npm publish --dry-run
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Publish to GitHub Package Registry
if: ${{ github.event_name == 'release' }}
run: |
npm config set scope "@Jashepp"
npm config set @Jashepp:registry https://npm.pkg.github.com/
npm pkg set name=@Jashepp/eventemitter-wrapper
npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
name: Tests

on: [push]
name: Run Tests
on:
workflow_call:
push:
paths:
- '**.js'
- '**.json'
- '.github/workflows/run-tests.yml'
pull_request:
paths:
- '**.js'
- '**.json'
- '.github/workflows/run-tests.yml'

jobs:

tests-node-:
tests:
name: Run Tests with Node.js ${{ matrix.node }}
runs-on: ubuntu-latest
strategy:
matrix:
node: [ lts/*, latest, 16, 18, 20 ]
name: Tests with Node.js ${{ matrix.node }}
steps:

# https://github.com/actions/cache/blob/main/examples.md#node---npm
Expand Down

0 comments on commit e0068ff

Please sign in to comment.