diff --git a/.github/workflows/pr-func-tests.yml b/.github/workflows/pr-func-tests.yml index d19d0c6..e8948cf 100644 --- a/.github/workflows/pr-func-tests.yml +++ b/.github/workflows/pr-func-tests.yml @@ -26,6 +26,17 @@ jobs: entrypoint: bin/test upload-key: something-else-${{ github.sha }} + basic-func-filename-test: + runs-on: ubuntu-24.04 + steps: + - name: Checkout action code + uses: actions/checkout@v4 + - name: Run Pkg Action + uses: ./ + with: + entrypoint: bin/test + filename: bob + basic-cross-platform-test: runs-on: ${{ matrix.os }} strategy: diff --git a/CHANGELOG.md b/CHANGELOG.md index 067dca9..1681fe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }}) +* Added `inputs.filename` to customize the name of the output binary ## v5.1.0 - [October 26, 2024](https://github.com/lando/pkg-action/releases/tag/v5.1.0) diff --git a/README.md b/README.md index c6945e1..203b000 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ These keys are set to sane defaults but can be modified as needed. |---|---|---|---| | `arch` | The architecture to build for. | `${{ runner.arch }}` | `x64` \| `amd64` \| `aarch64` \| `arm64` | | `config` | The config file to use. | `package.json` | `config.json` | +| `filename` | The name of the resulting binary. | `${{ package.name }}` | `mycli` | | `node-version` | The node version to package with. | `20` | `8` \| `10` \| `12` \| `14` \| `16` \| `18` \| `20` | | `options` | Additional options and flags to pass into pkg. | `null` | Additional [pkg options](https://github.com/vercel/pkg#usage) | | `os` | The operating system to build for. | `${{ runner.os }}` | `linux` \| `macos` \| `win` | @@ -38,6 +39,8 @@ These keys are set to sane defaults but can be modified as needed. | `upload` | Upload the artifacts. Useful if you need to grab them for downstream for things like code signing. | `true` | `false` \| `true` | | `upload-key` | Upload key for the artifact. Useful if want to override outputs.artifact-key with a specific value. | `${{ github.event.repository.name }}-${{ inputs.node-version }}-${{ inputs.os }}-${{ inputs.arch }}-${{ github.sha }}` | `"my-pkg"` | +Note that `.exe` will _automatically_ be appended to _all_ resulting binaries on `win`. Also note that _all_ binaries will end up in the `dist` folder. + ## Outputs ```yaml @@ -71,7 +74,7 @@ with: entrypoint: bin/cli arch: arm64 config: package.json - node-version: 14 + node-version: 16 options: -C os: win upload: false @@ -87,7 +90,7 @@ strategy: - x64 - arm64 node-version: - - 16 + - 20 os: - linux - macos @@ -97,6 +100,7 @@ steps: uses: lando/pkg-action@v2 with: entrypoint: bin/cli + filename: mycli arch: ${{ matrix.arch }} node-version: ${{ matrix.node-version }} os: ${{ matrix.os }} diff --git a/action.yml b/action.yml index aa9ec8c..6dac8e9 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,10 @@ inputs: description: "The config file to use" required: false default: package.json + filename: + description: "The filename of the resulting binary" + required: false + default: "" node-version: description: "The node version to package with" required: false @@ -110,9 +114,14 @@ runs: echo "target-arch=${{ inputs.arch }}" >> $GITHUB_OUTPUT fi + if [[ -n "${{ inputs.filename }}" ]]; then + echo "target-output=--output=dist/${{ inputs.filename }}" >> $GITHUB_OUTPUT + else + echo "target-output=--out-path=dist" >> $GITHUB_OUTPUT + fi + echo "target-node=node${{ inputs.node-version }}" >> $GITHUB_OUTPUT echo "::endgroup::" - - name: Validate arch emulation requirements shell: bash run: | @@ -122,13 +131,11 @@ runs: exit 48 fi fi - - name: Install node ${{ inputs.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ inputs.node-version }} cache: npm - - name: Install ${{ inputs.pkg }} shell: bash run: | @@ -138,17 +145,22 @@ runs: else echo "::error title=Cannot run pkg::Cannot seem to find the pkg binary" fi - - name: Set outputs shell: bash id: pkg-action run: | echo "::group::Setting outputs" - if [ "${{ steps.pkg-action-internal.outputs.target-os }}" == "win" ]; then - echo "file=dist/$(node -p "require('./package.json').name").exe" >> $GITHUB_OUTPUT + + if [[ -n "${{ inputs.filename }}" ]]; then + file="dist/${{ inputs.filename }}" else - echo "file=dist/$(node -p "require('./package.json').name")" >> $GITHUB_OUTPUT + file="dist/$(node -p "require('./package.json').name")" fi + if [ "${{ steps.pkg-action-internal.outputs.target-os }}" == "win" ]; then + file="${file}.exe" + fi + + echo "file=$file" >> $GITHUB_OUTPUT if [[ -n "${{ inputs.upload-key }}" ]]; then echo "artifact-key=${{ inputs.upload-key }}" >> $GITHUB_OUTPUT @@ -157,7 +169,20 @@ runs: fi echo "::endgroup::" + - name: Verify Outputs + shell: bash + run: | + echo "::group::Internal output information" + echo "arch=${{ steps.pkg-action-internal.outputs.target-arch }}" + echo "node=${{ steps.pkg-action-internal.outputs.target-node }}" + echo "os=${{ steps.pkg-action-internal.outputs.target-os }}" + echo "output=${{ steps.pkg-action-internal.outputs.target-output }}" + echo "::endgroup::" + echo "::group::Output information" + echo "artifact-key=${{ steps.pkg-action.outputs.artifact-key }}" + echo "file=${{ steps.pkg-action.outputs.file }}" + echo "::endgroup::" - name: Run native ${{ steps.pkg-action-internal.outputs.target-arch }} pkg command if: inputs.test != 'true' && steps.pkg-action-internal.outputs.target-arch == steps.pkg-action-internal.outputs.runner-arch shell: bash @@ -168,7 +193,7 @@ runs: pkg \ --config ${{ inputs.config }} \ --target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \ - --out-path dist \ + ${{ steps.pkg-action-internal.outputs.target-output }} \ --debug \ ${{ inputs.options }} \ ${{ inputs.entrypoint }} @@ -176,7 +201,7 @@ runs: pkg \ --config ${{ inputs.config }} \ --target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \ - --out-path dist \ + ${{ steps.pkg-action-internal.outputs.target-output }} \ ${{ inputs.options }} \ ${{ inputs.entrypoint }} fi @@ -205,7 +230,7 @@ runs: pkg \ --config ${{ inputs.config }} \ --target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \ - --out-path dist \ + ${{ steps.pkg-action-internal.outputs.target-output }} \ ${{ inputs.options }} \ ${{ inputs.entrypoint }} stat ${{ steps.pkg-action.outputs.file }} diff --git a/package-lock.json b/package-lock.json index f2f62f0..fcf47e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@lando/pkg-action", - "version": "5.0.0", + "version": "5.1.0", "license": "GPL-3.0", "engines": { "node": ">=18.0.0"