Skip to content

Commit

Permalink
Add bin-leading-dir option (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 authored Apr 10, 2024
1 parent 2c45dad commit 7de3db9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Currently, this action is basically intended to be used in combination with an a
| include | false | Comma-separated list of additional files to be included to the archive | String | |
| asset | false | Comma-separated list of additional files to be uploaded separately | String | |
| leading-dir | false | Whether to create the leading directory in the archive or not | Boolean | `false` |
| bin-leading-dir | false | Create extra leading directory(s) for `bin` (i.e., the binary file(s)) in the archive | String | |
| build-tool | false | Tool to build binaries (cargo, cross, or cargo-zigbuild, see [cross-compilation example](#example-workflow-cross-compilation) for more) | String | |
| ref | false | Fully-formed tag ref for this release (see [action.yml](action.yml) for more) | String | |
| manifest-path | false | Path to Cargo.toml | String | `Cargo.toml` |
Expand Down Expand Up @@ -561,6 +562,34 @@ In the above example, the directory structure of the archive would be as follows
/<archive>/README.md
```

You can use the `bin-leading-dir` option to create extra leading directory(s) for binary file(s) specified by `bin` option.

```yaml
- uses: taiki-e/upload-rust-binary-action@v1
with:
# (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
# Note that glob pattern is not supported yet.
bin: ...
# (optional) Comma-separated list of additional files to be included to archive.
# Note that glob pattern is not supported yet.
include: LICENSE,README.md
# (optional) Whether to create the leading directory in the archive or not. default to false.
leading-dir: true
# (optional) Create extra leading directory(s) for `bin`. default to empty.
bin-leading-dir: opt/leading
# (required) GitHub token for uploading assets to GitHub Releases.
token: ${{ secrets.GITHUB_TOKEN }}
```
In the above example, the directory structure of the archive would be as follows:
```text
/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md
```

If you want upload additional file *separately*, you can use the `asset` option.

```yaml
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ inputs:
description: Alias for 'leading-dir'
required: false
default: 'false'
bin-leading-dir:
description: Create extra leading directory(s) for `bin` (e.g. the binary file) in the archive
required: false
build-tool:
description: Tool to build binaries (cargo, cross, or cargo-zigbuild)
required: false
Expand Down Expand Up @@ -114,6 +117,7 @@ runs:
INPUT_INCLUDE: ${{ inputs.include }}
INPUT_ASSET: ${{ inputs.asset }}
INPUT_LEADING_DIR: ${{ inputs.leading-dir || inputs.leading_dir }}
INPUT_BIN_LEADING_DIR: ${{ inputs.bin-leading-dir }}
INPUT_BUILD_TOOL: ${{ inputs.build-tool || inputs.build_tool }}
INPUT_CHECKSUM: ${{ inputs.checksum }}
INPUT_TOKEN: ${{ inputs.token }}
Expand Down
15 changes: 13 additions & 2 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ case "${leading_dir}" in
*) bail "'leading-dir' input option must be 'true' or 'false': '${leading_dir}'" ;;
esac

bin_leading_dir="${INPUT_BIN_LEADING_DIR:-}"

no_default_features="${INPUT_NO_DEFAULT_FEATURES:-}"
case "${no_default_features}" in
true) no_default_features="1" ;;
Expand Down Expand Up @@ -342,9 +344,18 @@ if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]] || [[ "${INPUT_ZIP/all/
cwd=$(pwd)
tmpdir=$(mktemp -d)
mkdir "${tmpdir:?}/${archive}"
filenames=("${bins[@]}")
if [[ -n "${bin_leading_dir}" ]]; then
x mkdir -p "${tmpdir}/${archive}/${bin_leading_dir}"/
filenames=("${bin_leading_dir%%/*}")
else
filenames=("${bins[@]}")
fi
for bin_exe in "${bins[@]}"; do
cp "${target_dir}/${bin_exe}" "${tmpdir}/${archive}"/
if [[ -n "${bin_leading_dir}" ]]; then
x cp "${target_dir}/${bin_exe}" "${tmpdir}/${archive}/${bin_leading_dir}"/
else
x cp "${target_dir}/${bin_exe}" "${tmpdir}/${archive}"/
fi
done
for include in ${includes[@]+"${includes[@]}"}; do
cp -r "${include}" "${tmpdir}/${archive}"/
Expand Down

0 comments on commit 7de3db9

Please sign in to comment.