Update pack and compare npm actions.
This commit is contained in:
@@ -23,7 +23,7 @@ inputs:
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: "https://npm.pkg.github.com"
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
authToken:
|
||||
description: "Authentication token for the registry."
|
||||
required: true
|
||||
|
||||
@@ -11,7 +11,7 @@ inputs:
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: "https://npm.pkg.github.com"
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
authToken:
|
||||
description: "Authentication token for the registry."
|
||||
required: true
|
||||
|
||||
@@ -19,7 +19,7 @@ inputs:
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: "https://npm.pkg.github.com"
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
authToken:
|
||||
description: "Authentication token for the registry."
|
||||
required: true
|
||||
|
||||
101
npm/npm-pack-and-compare/action.yaml
Normal file
101
npm/npm-pack-and-compare/action.yaml
Normal file
@@ -0,0 +1,101 @@
|
||||
name: npm-pack-and-compare
|
||||
description: "Build and pack an NPM package into a .tgz file."
|
||||
inputs:
|
||||
name:
|
||||
description: "The name of the package."
|
||||
required: true
|
||||
workingDirectory:
|
||||
description: "Working directory containing package.json."
|
||||
required: false
|
||||
default: "."
|
||||
nodeVersion:
|
||||
description: "Node.js version to use."
|
||||
required: false
|
||||
default: "20"
|
||||
buildScript:
|
||||
description: "Build script to run before packing (e.g., 'build' for 'npm run build'). Set to empty string to skip build step."
|
||||
required: false
|
||||
default: "build"
|
||||
defaultVersion:
|
||||
description: "Version of the package."
|
||||
required: true
|
||||
default: "1.0.0"
|
||||
outputDirectory:
|
||||
description: "Directory for the output .tgz."
|
||||
required: true
|
||||
default: "out"
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
authToken:
|
||||
description: "Authentication token for the registry."
|
||||
required: true
|
||||
skipCompare:
|
||||
description: "Skip in-depth comparison."
|
||||
required: true
|
||||
default: "false"
|
||||
outputs:
|
||||
tgz:
|
||||
description: "The generated output .tgz file."
|
||||
value: ${{ steps.package.outputs.tgz }}
|
||||
tgzName:
|
||||
description: "The generated output .tgz file's name."
|
||||
value: ${{ steps.package.outputs.tgzName }}
|
||||
hasChanged:
|
||||
description: "Whether or not the package files match."
|
||||
value: ${{ !steps.npm.outputs.latestVersion || inputs.skipCompare == 'true' || steps.compare.outputs.hasDifferences == 'true' }}
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: "Get the next version of the package."
|
||||
uses: act/common/npm/npm-get-next-branched-version@master
|
||||
id: npm
|
||||
with:
|
||||
name: ${{ inputs.name }}
|
||||
defaultVersion: ${{ inputs.defaultVersion }}
|
||||
registry: ${{ inputs.registry }}
|
||||
authToken: ${{ inputs.authToken }}
|
||||
- name: "Pack with latest version for comparison"
|
||||
if: ${{ steps.npm.outputs.latestVersion && inputs.skipCompare == 'false' }}
|
||||
id: pack_comparison
|
||||
uses: act/common/npm/npm-pack@master
|
||||
with:
|
||||
version: ${{ steps.npm.outputs.latestVersion }}
|
||||
workingDirectory: ${{ inputs.workingDirectory }}
|
||||
nodeVersion: ${{ inputs.nodeVersion }}
|
||||
buildScript: ${{ inputs.buildScript }}
|
||||
outputDirectory: ${{ inputs.outputDirectory }}/comparison
|
||||
registry: ${{ inputs.registry }}
|
||||
- name: "Compare to remote package"
|
||||
if: ${{ steps.npm.outputs.latestVersion && inputs.skipCompare == 'false' }}
|
||||
id: compare
|
||||
uses: act/common/npm/npm-diff@master
|
||||
with:
|
||||
name: ${{ inputs.name }}
|
||||
lhsVersion: ${{ steps.npm.outputs.latestVersion }}
|
||||
rhsVersion: ${{ steps.npm.outputs.latestVersion }}
|
||||
workingDirectory: ${{ inputs.workingDirectory }}
|
||||
registry: ${{ inputs.registry }}
|
||||
authToken: ${{ inputs.authToken }}
|
||||
failOnDifferences: "false"
|
||||
- name: "Pack with next version"
|
||||
if: ${{ !steps.npm.outputs.latestVersion || inputs.skipCompare == 'true' || steps.compare.outputs.hasDifferences == 'true' }}
|
||||
id: pack_final
|
||||
uses: act/common/npm/npm-pack@master
|
||||
with:
|
||||
version: ${{ steps.npm.outputs.nextVersion }}
|
||||
workingDirectory: ${{ inputs.workingDirectory }}
|
||||
nodeVersion: ${{ inputs.nodeVersion }}
|
||||
buildScript: ${{ inputs.buildScript }}
|
||||
outputDirectory: ${{ inputs.outputDirectory }}
|
||||
registry: ${{ inputs.registry }}
|
||||
skipInstall: ${{ steps.pack_comparison.conclusion != '' }}
|
||||
- name: "Generate package outputs"
|
||||
id: package
|
||||
run: |
|
||||
TGZ_NAME="${{ inputs.name }}-${{ steps.npm.outputs.nextVersion }}.tgz"
|
||||
TGZ_PATH="${{ inputs.outputDirectory }}/$TGZ_NAME"
|
||||
echo "tgz=$TGZ_PATH" >> "$GITHUB_OUTPUT"
|
||||
echo "tgzName=$TGZ_NAME" >> "$GITHUB_OUTPUT"
|
||||
shell: bash
|
||||
79
npm/npm-pack/action.yaml
Normal file
79
npm/npm-pack/action.yaml
Normal file
@@ -0,0 +1,79 @@
|
||||
name: npm-pack
|
||||
description: "Build and pack an NPM package into a .tgz file."
|
||||
inputs:
|
||||
version:
|
||||
description: "Version to set in package.json before packing."
|
||||
required: true
|
||||
workingDirectory:
|
||||
description: "Working directory containing package.json."
|
||||
required: false
|
||||
default: "."
|
||||
nodeVersion:
|
||||
description: "Node.js version to use."
|
||||
required: false
|
||||
default: "20"
|
||||
buildScript:
|
||||
description: "Build script to run before packing (e.g., 'build' for 'npm run build'). Set to empty string to skip build step."
|
||||
required: false
|
||||
default: "build"
|
||||
outputDirectory:
|
||||
description: "Directory for the output .tgz."
|
||||
required: true
|
||||
default: "out"
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
skipInstall:
|
||||
description: "Skip npm ci step (dependencies already installed)."
|
||||
required: false
|
||||
default: "false"
|
||||
outputs:
|
||||
tgz:
|
||||
description: "The generated output .tgz file."
|
||||
value: ${{ steps.package.outputs.tgz }}
|
||||
tgzName:
|
||||
description: "The generated output .tgz file's name."
|
||||
value: ${{ steps.package.outputs.tgzName }}
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: "Setup Node.js"
|
||||
uses: https://github.com/actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ inputs.nodeVersion }}
|
||||
cache: npm
|
||||
cache-dependency-path: ${{ inputs.workingDirectory }}/package-lock.json
|
||||
registry-url: ${{ inputs.registry }}
|
||||
- name: "Install dependencies"
|
||||
if: ${{ inputs.skipInstall != 'true' }}
|
||||
run: npm ci
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
- name: "Update package version"
|
||||
run: npm version ${{ inputs.version }} --no-git-tag-version
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
- name: "Build package"
|
||||
if: ${{ inputs.buildScript != '' }}
|
||||
run: npm run ${{ inputs.buildScript }}
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
- name: "Create output directory"
|
||||
run: mkdir -p "${{ inputs.outputDirectory }}"
|
||||
shell: bash
|
||||
- name: "Pack package"
|
||||
run: npm pack --pack-destination "${{ github.workspace }}/${{ inputs.outputDirectory }}"
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
- name: "Generate package outputs"
|
||||
id: package
|
||||
run: |
|
||||
# Extract package name from package.json
|
||||
PACKAGE_NAME=$(node -p "require('./package.json').name")
|
||||
TGZ_NAME="$PACKAGE_NAME-${{ inputs.version }}.tgz"
|
||||
TGZ_PATH="${{ inputs.outputDirectory }}/$TGZ_NAME"
|
||||
echo "tgz=$TGZ_PATH" >> "$GITHUB_OUTPUT"
|
||||
echo "tgzName=$TGZ_NAME" >> "$GITHUB_OUTPUT"
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
@@ -7,7 +7,7 @@ inputs:
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: "https://npm.pkg.github.com"
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
apiKey:
|
||||
description: "NPM authentication token."
|
||||
required: true
|
||||
|
||||
@@ -7,7 +7,7 @@ inputs:
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: "https://npm.pkg.github.com"
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
authToken:
|
||||
description: "Authentication token for the registry."
|
||||
required: true
|
||||
|
||||
@@ -7,7 +7,7 @@ inputs:
|
||||
registry:
|
||||
description: "NPM registry URL."
|
||||
required: false
|
||||
default: "https://npm.pkg.github.com"
|
||||
default: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json
|
||||
authToken:
|
||||
description: "Authentication token for the registry."
|
||||
required: true
|
||||
|
||||
@@ -12,7 +12,7 @@ fi
|
||||
|
||||
# Construct the registry URL
|
||||
REGISTRY_URL="$REGISTRY"
|
||||
if [[ "$REGISTRY" == "https://npm.pkg.github.com" ]]; then
|
||||
if [[ "$REGISTRY" == ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/nuget/index.json ]]; then
|
||||
# GitHub Packages uses a specific URL format
|
||||
REGISTRY_URL="$REGISTRY"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user