Skip to content

Publish npm package

Publish npm package #6

Workflow file for this run

name: Publish npm package
on:
workflow_dispatch:
inputs:
dry-run:
description: 'Dry run'
required: true
type: boolean
default: 'true'
schedule:
- cron: '48 3 * * 1' # 3:48 AM UTC every Monday
jobs:
preflight:
name: Preflight
runs-on: ubuntu-20.04
outputs:
dry-run: ${{ steps.get-dry-run.outputs.dry-run }}
steps:
- name: Get dry run
id: get-dry-run
shell: pwsh
run: |
$IsDryRun = '${{ github.event.inputs.dry-run }}' -Eq 'true' -Or '${{ github.event_name }}' -Eq 'schedule'
if ($IsDryRun) {
echo "dry-run=true" >> $Env:GITHUB_OUTPUT
} else {
echo "dry-run=false" >> $Env:GITHUB_OUTPUT
}
build:
name: Build package
runs-on: ubuntu-20.04
needs:
- preflight
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup wasm-pack
shell: bash
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Install dependencies
shell: pwsh
run: |
Set-Location -Path ./web-client/iron-remote-gui/
npm install
- name: Build package
shell: pwsh
run: |
Set-PSDebug -Trace 1
Set-Location -Path ./web-client/iron-remote-gui/
npm run build
Set-Location -Path ./dist
npm pack
- name: Harvest package
shell: pwsh
run: |
Set-PSDebug -Trace 1
New-Item -ItemType "directory" -Path . -Name "npm-packages"
Get-ChildItem -Path ./web-client/ -Recurse *.tgz | ForEach { Copy-Item $_ "./npm-packages" }
- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: npm
path: npm-packages/*.tgz
publish:
name: Publish package
runs-on: ubuntu-20.04
if: github.event_name == 'workflow_dispatch'
environment: publish
needs:
- preflight
- build
steps:
- name: Download NPM packages artifact
uses: actions/download-artifact@v3
with:
name: npm
path: npm-packages
- name: Prepare npm
shell: pwsh
run: npm config set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
- name: Publish
shell: pwsh
run: |
Set-PSDebug -Trace 1
$isDryRun = '${{ needs.preflight.outputs.dry-run }}' -Eq 'true'
$files = Get-ChildItem -Recurse npm-packages/*.tgz
foreach ($file in $files) {
Write-Host "Publishing $($File.Name)..."
$publishCmd = @(
'npm',
'publish',
"$File",
'--access=public'
)
if ($isDryRun) {
$publishCmd += '--dry-run'
}
$publishCmd = $publishCmd -Join ' '
Invoke-Expression $publishCmd
}