Skip to content

Commit

Permalink
rework to handle dynamic filename output (#11)
Browse files Browse the repository at this point in the history
* rework to handle dynamic filename output

* add output verifier and bump to setup-node@v4

* fixed output verifier and added filename test

* update docs

* added target output to output verification
  • Loading branch information
pirog authored Nov 14, 2024
1 parent ce6ce84 commit e58618c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/pr-func-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ 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` |
| `pkg` | The `pkg` package` to use. | `@yao-pkg/[email protected]` | `[email protected]` |
| `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
Expand Down Expand Up @@ -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
Expand All @@ -87,7 +90,7 @@ strategy:
- x64
- arm64
node-version:
- 16
- 20
os:
- linux
- macos
Expand All @@ -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 }}
Expand Down
47 changes: 36 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand All @@ -168,15 +193,15 @@ 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 }}
else
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
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e58618c

Please sign in to comment.