Skip to content

Commit

Permalink
support using git hashes/main specifier for cross
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Sep 11, 2023
1 parent 005ae7a commit 1d365e8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,45 @@ jobs:
run: |
[[ -d "test/hello_world/target/aarch64-unknown-linux-gnu/debug" ]] || (echo "debug is missing" && exit 1);
[[ -d "test/hello_world/target/aarch64-unknown-linux-gnu/release" ]] || (echo "release is missing" && exit 1);
test-git-cross:
name: "Test using git versions of cross"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: aarch64-unknown-linux-gnu

- name: Enable Rust cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # 2.2.1
with:
cache-on-failure: true
workspaces: "./test/hello_world -> target"

- name: Test main branch
uses: ./
with:
command: build
args: --target aarch64-unknown-linux-gnu
use-cross: true
cross-version: main
directory: test/hello_world

- name: Uninstall cargo cross
shell: bash
run: |
cargo uninstall cross || true
- name: Test git hash
uses: ./
with:
command: build
args: --target aarch64-unknown-linux-gnu
use-cross: true
cross-version: "git:d6511b7b166c18640f81b8f6a74d9eef380f7ded"
directory: test/hello_world
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Note - this action does not install Rust for you, you will want to install a too

**Note: Inputs aren't necessarily checked to be valid by this action!**

| Name | Description |
| --------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `command` | The `cargo` command to run (e.g. `build`, `test`). Required. |
| `toolchain` | The toolchain to use. Do not include the `+` sign (e.g. `nightly`, `beta`). Defaults to stable. |
| `args` | What arguments to pass to the cargo/cross command. |
| `use-cross` | Whether to use cross instead of using cargo. If enabled, cross will automatically be installed if needed. |
| `cross-version` | The cross version to use. Only used if `use-cross` is enabled. If not set, defaults to the newest stable version of cross. |
| `directory` | Change to the specified directory prior to execution. Useful if your repo's base folder does not contain your Rust project. |
| Name | Description |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `command` | The `cargo` command to run (e.g. `build`, `test`). Required. |
| `toolchain` | The toolchain to use. Do not include the `+` sign (e.g. `nightly`, `beta`). Defaults to stable. |
| `args` | What arguments to pass to the cargo/cross command. |
| `use-cross` | Whether to use cross instead of using cargo. If enabled, cross will automatically be installed if needed. |
| `cross-version` | The cross version to use. Only used if `use-cross` is enabled. If this is not set, it will default to the newest stable version of cross. `main` or `git:XYZ` are also valid options. |
| `directory` | Change to the specified directory prior to execution. Useful if your repo's base folder does not contain your Rust project. |

## Example

Expand Down
19 changes: 15 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ inputs:

cross-version:
description: >
The cross version to use. Only used if `use-cross` is enabled. If not set, defaults to the newest stable
version of cross.
The cross version to use. This is only used if `use-cross` is enabled. If it is not set, defaults to the newest
stable version of cross.
You can also set the special versions of "main" or "git:xyz" to specify a specific git hash or the current main
branch head of cross.
required: false
default: ""

Expand Down Expand Up @@ -63,9 +66,17 @@ runs:
run: |
# Install cross
if [[ -n "${{inputs.cross-version}}" ]]; then
CROSS_VERSION_ARG="--version=${{inputs.cross-version}}";
if [[ "${{inputs.cross-version}}" == "main" ]]; then
cargo install cross --git https://github.com/cross-rs/cross
elif [[ "${{inputs.cross-version}}" == "git:"* ]]; then
CROSS_VERSION_ARG="${{inputs.cross-version}}"
CROSS_HASH="${CROSS_HASH:4}"
cargo install cross --git https://github.com/cross-rs/cross/tree/${CROSS_HASH}
else
CROSS_VERSION_ARG="--version=${{inputs.cross-version}}";
cargo install cross --locked ${CROSS_VERSION_ARG};
fi
fi
cargo install cross --locked ${CROSS_VERSION_ARG};
- name: Execute the cargo/cross command.
shell: bash
Expand Down

0 comments on commit 1d365e8

Please sign in to comment.