diff --git a/npm/npm-diff/action.yaml b/npm/npm-diff/action.yaml index 0f1c61a..6b4633f 100644 --- a/npm/npm-diff/action.yaml +++ b/npm/npm-diff/action.yaml @@ -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 diff --git a/npm/npm-get-next-branched-version/action.yaml b/npm/npm-get-next-branched-version/action.yaml index 8579953..db58147 100644 --- a/npm/npm-get-next-branched-version/action.yaml +++ b/npm/npm-get-next-branched-version/action.yaml @@ -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 diff --git a/npm/npm-install/action.yaml b/npm/npm-install/action.yaml index eb3455b..72339a2 100644 --- a/npm/npm-install/action.yaml +++ b/npm/npm-install/action.yaml @@ -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 diff --git a/npm/npm-pack-and-compare/action.yaml b/npm/npm-pack-and-compare/action.yaml new file mode 100644 index 0000000..b8768d5 --- /dev/null +++ b/npm/npm-pack-and-compare/action.yaml @@ -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 diff --git a/npm/npm-pack/action.yaml b/npm/npm-pack/action.yaml new file mode 100644 index 0000000..b81bc7d --- /dev/null +++ b/npm/npm-pack/action.yaml @@ -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 diff --git a/npm/npm-push/action.yaml b/npm/npm-push/action.yaml index ae72484..faf72e9 100644 --- a/npm/npm-push/action.yaml +++ b/npm/npm-push/action.yaml @@ -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 diff --git a/npm/npm-query-versions-latest/action.yaml b/npm/npm-query-versions-latest/action.yaml index d752809..e4f3d43 100644 --- a/npm/npm-query-versions-latest/action.yaml +++ b/npm/npm-query-versions-latest/action.yaml @@ -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 diff --git a/npm/npm-query-versions/action.yaml b/npm/npm-query-versions/action.yaml index 9ab90ba..cce64e3 100644 --- a/npm/npm-query-versions/action.yaml +++ b/npm/npm-query-versions/action.yaml @@ -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 diff --git a/npm/npm-query-versions/query_versions.sh b/npm/npm-query-versions/query_versions.sh index 75fa5fa..3deee4f 100644 --- a/npm/npm-query-versions/query_versions.sh +++ b/npm/npm-query-versions/query_versions.sh @@ -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 diff --git a/utils/compare-tgz/action.yaml b/utils/compare-tgz/action.yaml new file mode 100644 index 0000000..5e8113a --- /dev/null +++ b/utils/compare-tgz/action.yaml @@ -0,0 +1,82 @@ +name: compare-tgz +description: "Compare the contents of two .tgz files." +inputs: + lhs: + description: "Left hand side .tgz file." + required: true + rhs: + description: "Right hand side .tgz file." + required: true + comparePackageJson: + description: "Whether or not to compare the package.json file." + required: true + default: "false" + exitOnFail: + description: "Should the program exit on a failure." + required: true + default: "false" + tmpDir: + description: "Temporary directory. Default: _tmp" + required: true + default: _tmp +outputs: + success: + description: "The result of the comparison." + value: ${{ steps.compare.outputs.success == 'true' && ( inputs.comparePackageJson == 'false' || steps.compare-package-json.outputs.success == 'true' ) }} +runs: + using: "composite" + steps: + - name: "Make temporary directory for lhs extraction" + id: mktemp-lhs + uses: act/common/utils/mktemp@master + with: + outputType: dir + tmpDir: ${{ inputs.tmpDir }} + - name: "Make temporary directory for rhs extraction" + id: mktemp-rhs + uses: act/common/utils/mktemp@master + with: + outputType: dir + tmpDir: ${{ inputs.tmpDir }} + - name: "Extract lhs." + uses: act/common/utils/extract@master + with: + file: ${{ inputs.lhs }} + outputDir: ${{ steps.mktemp-lhs.outputs.tmp }} + - name: "Extract rhs." + uses: act/common/utils/extract@master + with: + file: ${{ inputs.rhs }} + outputDir: ${{ steps.mktemp-rhs.outputs.tmp }} + - name: "Get shasum for lhs." + id: lhs-shasum + uses: act/common/utils/shasum-files@master + with: + directory: ${{ steps.mktemp-lhs.outputs.tmp }} + pattern: "*" + - name: "Get shasum for rhs." + id: rhs-shasum + uses: act/common/utils/shasum-files@master + with: + directory: ${{ steps.mktemp-rhs.outputs.tmp }} + pattern: "*" + - name: "Compare lhs and rhs." + id: compare + uses: act/common/utils/compare@master + with: + expected: ${{ steps.lhs-shasum.outputs.sums }} + actual: ${{ steps.rhs-shasum.outputs.sums }} + exitOnFail: ${{ inputs.exitOnFail }} + - name: "Compare package.json files." + id: compare-package-json + if: ${{ inputs.comparePackageJson == 'true' }} + uses: act/common/utils/compare-files@master + with: + expected: ${{ steps.mktemp-lhs.outputs.tmp }} + expectedPattern: /*/package.json + actual: ${{ steps.mktemp-rhs.outputs.tmp }} + actualPattern: /*/package.json + exitOnFail: ${{ inputs.exitOnFail }} + - name: "Remove temporary files." + run: rm -rf "${{ inputs.tmpDir }}" + shell: bash