Skip to content

Publishing to GitHub Packages #10

Publishing to GitHub Packages

Publishing to GitHub Packages #10

name: Publishing to GitHub Packages
on:
workflow_dispatch:
inputs:
pattern:
type: string
description: Package file pattern
required: false
jobs:
build:
name: Build packages
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.filter.outputs.packages }}
steps:
- name: Get sources
uses: actions/checkout@v4
- name: Set up nodejs
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
always-auth: true
- name: Install dependencies
run: npm install --no-audit --no-fund
- name: Build npm packages
env:
BUILD_INTERNAL_PACKAGE: true
run: npm run all:build
- name: Build artifacts package
run: npm run ts-script build/make-artifacts-package
- uses: actions/upload-artifact@v3
with:
name: packages
path: |
.npmrc
artifacts/npm/*.tgz
- name: Filter packages
id: filter
working-directory: artifacts/npm
run: ls *.tgz | grep -E -i '${{ inputs.pattern }}' | sed -r 's/^(.*)$/"\1"/g' | paste -sd "," - | sed -r 's/(.*)/packages=[\1]/' >> "$GITHUB_OUTPUT"
publish:
name: Publish package
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
package: ${{ fromJSON(needs.build.outputs.packages) }}
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: packages
- name: Publish to npm.pkg.github.com
env:
PACKAGE: ${{ matrix.package }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tar -xzf $PACKAGE;
cd package;
npm init -y --scope ${{ github.repository_owner }};
npm pkg delete repository
npm publish --quiet --registry https://npm.pkg.github.com;