Skip to content

Package publishing

Package publishing #29

Workflow file for this run

# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
name: "Package publishing"
on:
workflow_dispatch:
release:
types: [created, edited]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
services:
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: jest_mysql_test
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Clean install dependencies and build
run: |
npm i --package-lock-only
npm ci
npm run build --if-present
- name: Run tests
run: npm test
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm i --package-lock-only
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
publish-gpr:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
scope: '@daniel-yonkov'
- run: echo registry=https://npm.pkg.github.com/daniel-yonkov >> .npmrc
- name: Insert repository owner as scope into package name
run: |
node <<EOF
const fs = require('fs').promises;
fs.readFile('package.json', 'utf8').then((data) => JSON.parse(data)).then((json) => {
json.name = '@$(echo "$GITHUB_REPOSITORY" | sed 's/\/.\+//')/' + json.name;
console.info('Package name changed to %s', json.name);
return fs.writeFile('package.json', JSON.stringify(json), 'utf8');
}).catch(error => {
console.error(error);
process.exit(1);
});
EOF
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}