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

support using git hashes/main specifier for cross #9

Merged
merged 1 commit into from
Sep 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 --branch main
elif [[ "${{inputs.cross-version}}" == "git:"* ]]; then
CROSS_VERSION_ARG="${{inputs.cross-version}}"
CROSS_HASH="${CROSS_VERSION_ARG:4}"
cargo install cross --git https://github.com/cross-rs/cross --rev ${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