Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework to handle dynamic filename output #11

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading