From a11e7342e5200f8e19de13c848456bbe876013d2 Mon Sep 17 00:00:00 2001 From: Austin Ward Date: Tue, 7 Mar 2023 08:57:37 -0500 Subject: [PATCH 1/5] Add sections to contributing guide --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0c2b407..e14fc87 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,3 +8,9 @@ request](https://github.com/mpalmer/action-validator/pulls). * At all times, abide by the Code of Conduct (CODE_OF_CONDUCT.md). + +# Environment Setup + +# Running the Validator Locally + +# Writing Tests From 2928a74c98dbba4c744518977b2727989a51cff0 Mon Sep 17 00:00:00 2001 From: Austin Ward Date: Tue, 2 May 2023 21:30:53 -0400 Subject: [PATCH 2/5] Add testing and contrib changes --- CONTRIBUTING.md | 77 ++++++++++ Cargo.toml | 15 +- README.md | 2 +- bin/run-action-validator | 0 test/004_failing_globs/stdout | 1 - test/007_funky_syntax/stdout | 1 - test/008_job_dependencies/stdout | 1 - test/009_multi_file/stdout | 1 - {test => tests}/001_basic_workflow/test.yml | 0 .../validation_state.snap.json | 0 {test => tests}/002_basic_action/action.yml | 0 .../validation_state.snap.json | 0 {test => tests}/003_successful_globs/glob.yml | 2 +- .../validation_state.snap.json | 0 {test => tests}/004_failing_globs/exitcode | 0 {test => tests}/004_failing_globs/glob.yml | 2 +- {test => tests}/004_failing_globs/stderr | 4 +- tests/004_failing_globs/stdout | 1 + .../validation_state.snap.json | 0 .../005_conditional_step_in_action/action.yml | 0 .../validation_state.snap.json | 0 .../test.yml | 0 .../validation_state.snap.json | 0 {test => tests}/007_funky_syntax/exitcode | 0 .../007_funky_syntax/rust-check.yml | 0 {test => tests}/007_funky_syntax/stderr | 2 +- tests/007_funky_syntax/stdout | 1 + .../validation_state.snap.json | 0 {test => tests}/008_job_dependencies/exitcode | 0 {test => tests}/008_job_dependencies/stderr | 2 +- tests/008_job_dependencies/stdout | 1 + {test => tests}/008_job_dependencies/test.yml | 0 .../validation_state.snap.json | 0 {test => tests}/009_multi_file/exitcode | 0 {test => tests}/009_multi_file/stderr | 2 +- tests/009_multi_file/stdout | 1 + {test => tests}/009_multi_file/valid.yml | 0 .../009_multi_file/validation_state.snap.json | 0 {test => tests}/009_multi_file/xinvalid.yml | 0 tests/010_remote_checks_ok/test.yml | 78 ++++++++++ tests/011_remote_checks_failure/exitcode | 1 + tests/011_remote_checks_failure/stderr | 18 +++ tests/011_remote_checks_failure/stdout | 1 + tests/011_remote_checks_failure/test.yml | 78 ++++++++++ {test => tests}/run | 0 {test => tests}/run.mjs | 0 tests/snapshot_tests.rs | 140 ++++++++++++++++++ 47 files changed, 414 insertions(+), 18 deletions(-) mode change 100644 => 100755 bin/run-action-validator delete mode 100644 test/004_failing_globs/stdout delete mode 100644 test/007_funky_syntax/stdout delete mode 100644 test/008_job_dependencies/stdout delete mode 100644 test/009_multi_file/stdout rename {test => tests}/001_basic_workflow/test.yml (100%) rename {test => tests}/001_basic_workflow/validation_state.snap.json (100%) rename {test => tests}/002_basic_action/action.yml (100%) rename {test => tests}/002_basic_action/validation_state.snap.json (100%) rename {test => tests}/003_successful_globs/glob.yml (88%) rename {test => tests}/003_successful_globs/validation_state.snap.json (100%) rename {test => tests}/004_failing_globs/exitcode (100%) rename {test => tests}/004_failing_globs/glob.yml (89%) rename {test => tests}/004_failing_globs/stderr (70%) create mode 100644 tests/004_failing_globs/stdout rename {test => tests}/004_failing_globs/validation_state.snap.json (100%) rename {test => tests}/005_conditional_step_in_action/action.yml (100%) rename {test => tests}/005_conditional_step_in_action/validation_state.snap.json (100%) rename {test => tests}/006_workflow_dispatch_inputs_options/test.yml (100%) rename {test => tests}/006_workflow_dispatch_inputs_options/validation_state.snap.json (100%) rename {test => tests}/007_funky_syntax/exitcode (100%) rename {test => tests}/007_funky_syntax/rust-check.yml (100%) rename {test => tests}/007_funky_syntax/stderr (91%) create mode 100644 tests/007_funky_syntax/stdout rename {test => tests}/007_funky_syntax/validation_state.snap.json (100%) rename {test => tests}/008_job_dependencies/exitcode (100%) rename {test => tests}/008_job_dependencies/stderr (88%) create mode 100644 tests/008_job_dependencies/stdout rename {test => tests}/008_job_dependencies/test.yml (100%) rename {test => tests}/008_job_dependencies/validation_state.snap.json (100%) rename {test => tests}/009_multi_file/exitcode (100%) rename {test => tests}/009_multi_file/stderr (92%) create mode 100644 tests/009_multi_file/stdout rename {test => tests}/009_multi_file/valid.yml (100%) rename {test => tests}/009_multi_file/validation_state.snap.json (100%) rename {test => tests}/009_multi_file/xinvalid.yml (100%) create mode 100644 tests/010_remote_checks_ok/test.yml create mode 100644 tests/011_remote_checks_failure/exitcode create mode 100644 tests/011_remote_checks_failure/stderr create mode 100644 tests/011_remote_checks_failure/stdout create mode 100644 tests/011_remote_checks_failure/test.yml rename {test => tests}/run (100%) rename {test => tests}/run.mjs (100%) create mode 100644 tests/snapshot_tests.rs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e14fc87..1593235 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,5 @@ +# Overview + * If you have found a discrepancy in documented and observed behaviour, that is a bug. Feel free to [report it as an issue](https://github.com/mpalmer/action-validator/issues), providing @@ -9,8 +11,83 @@ * At all times, abide by the Code of Conduct (CODE_OF_CONDUCT.md). +--- + # Environment Setup +## Install Rust +Firstly, you'll need make any changes to the core functionality of this project. We recommend use `rustup`, on the recommendation of the rust team. You can find the installation instructions [here](https://www.rust-lang.org/tools/install). + +To confirm that rust is installed, run the `cargo` command. If you don't receive the help docs output, you may need to add rust to your shell rc file. + +## Git Submodule Setup +This repository uses [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). Specifically for the use of [schemastore](https://github.com/SchemaStore/schemastore). + +To setup the git submodule after cloning this repo to your local, you'll want to run the following commands: +1. `git submodule init` +2. `git submodule update` + +It should look similar to the output below. + +```bash +❯ git submodule init +Submodule 'src/schemastore' (https://github.com/SchemaStore/schemastore) registered for path 'src +/schemastore' +❯ git submodule update +Cloning into '/Users/someuser/action-validator/src/schemastore'... +Submodule path 'src/schemastore': checked out 'd3e6ab7727380b214acbab05570fb09a3e5d2dfc' +``` + +At this point, you should be all set to `cargo run`! If you run into any issues here, please [create an issue](https://github.com/mpalmer/action-validator/issues/new/choose). + # Running the Validator Locally +## `cargo run [FILE] -- [OPTIONS]` +`cargo run` will create a _debug_ executable and run the project. If this is your first time running the command, cargo will compile the development binary with `cargo build`. This will install all of the dependencies and create the debug binary `action-validator` in the `/target/debug/` directory. `cargo run` will then invoke this binary after creation. + +One caveat if you're running with `cargo run`: if you want to supply the program with options, you need to use the `--` operator between `cargo run` and your provided options. This let's cargo know which flags are meant for cargo, and which are meant for the executable. + +## `cargo build` && `./target/debug/action-validator [OPTIONS]` +As discussed in the prior section, `cargo build` install dependencies (if they're not cached) and build the development binary. This binary can then be invoked directly by running `./target/debug/action-validator`. This does **not** require the use of the `--` operator in between the binary and any provided options. + +## Try It Yourself! + +Run the command `cargo run -- --help`. You should see an output similar to the following. +```bash +❯ cargo run -- --help + Finished dev [unoptimized + debuginfo] target(s) in 0.05s + Running `target/debug/action-validator --help` +A validator for GitHub Action and Workflow YAML files + +Usage: action-validator [OPTIONS] [path_to_action_yaml]... + +Arguments: + [path_to_action_yaml]... Input file + +Options: + -v, --verbose Be more verbose + -h, --help Print help information + -V, --version Print version information +``` + # Writing Tests +All tests live in the `tests` directory. Currently, this project implements snapshot testing, +but that's not to say you couldn't write unit or integration tests with the current structure. +To run the tests, simply run `cargo test` from the root directory. If you want to test a specific +feature, you can add the `-F {feature}` flag (e.g. `cargo test -F remote-checks`). + +## Unit/Integration Tests +As of this writing, there are no unit or integration tests. If you are looking to write some, please +follow the directions in [this guide](https://doc.rust-lang.org/book/ch11-01-writing-tests.html). + +## Snapshot Tests +A snapshot test is performed when we execute the cli and capture `stdout`, `stderr`, and/or an exit code. +When the tests is run, the results of the test must exactly match those of the previous run. For this project, +the snapshot tests are named in the format `{next_id}_{whats_being_tested}` (e.g. `011_remote_checks_failure`). + +If you have made changes which will change the output of the program and cause snapshots to fail, you can run +`cargo test -F save-snapshots`. This feature causes the executed command to save the `stdout`, `stderr`, and/or +exit code to the specified testing directory. + +If you are writing a net new test, you will need to create the test directory with your workflow or action file. +Once you're done, you can save the results to that directy by running `cargo test -F save-snapshots`. diff --git a/Cargo.toml b/Cargo.toml index 8ad7c11..cdf264b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,11 @@ include = [ "/src/schemastore/src/schemas/json/github-action.json" ] version = "0.0.0-git" -authors = ["Matt Palmer "] +authors = [ + "Matt Palmer ", + "Ben Heidemann ", + "Austin Ward " +] edition = "2021" # If this is changed, .github/workflows/qa.yml build matrix needs updating as well rust-version = "1.60.0" @@ -20,7 +24,8 @@ rust-version = "1.60.0" crate-type = ["cdylib", "rlib"] [features] -js = ["console_error_panic_hook", "wee_alloc", "valico/js"] +js = ["console_error_panic_hook", "valico/js"] +save-snapshots = [] [dependencies] clap = { version = "4.0", features = ["derive"] } @@ -39,14 +44,12 @@ wasm-bindgen = "0.2.63" # code size when deploying. console_error_panic_hook = { version = "0.1.6", optional = true } -# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size -# compared to the default allocator's ~10K. It is slower than the default -# allocator, however. -wee_alloc = { version = "0.4.5", optional = true } serde-wasm-bindgen = "0.4.5" [dev-dependencies] wasm-bindgen-test = "0.3.13" +rstest = "0.16.0" +assert_cmd = "2.0.8" [profile.release] # Tell `rustc` to optimize for small code size. diff --git a/README.md b/README.md index e600dcc..933f0f0 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Update your .pre-commit-config.yaml: ``` repos: - repo: https://github.com/mpalmer/action-validator - rev: v0.4.0 + rev: v0.5.1 hooks: - id: action-validator ``` diff --git a/bin/run-action-validator b/bin/run-action-validator old mode 100644 new mode 100755 diff --git a/test/004_failing_globs/stdout b/test/004_failing_globs/stdout deleted file mode 100644 index 4179a2f..0000000 --- a/test/004_failing_globs/stdout +++ /dev/null @@ -1 +0,0 @@ -Fatal error validating 004_failing_globs/glob.yml diff --git a/test/007_funky_syntax/stdout b/test/007_funky_syntax/stdout deleted file mode 100644 index f57da30..0000000 --- a/test/007_funky_syntax/stdout +++ /dev/null @@ -1 +0,0 @@ -Fatal error validating 007_funky_syntax/rust-check.yml diff --git a/test/008_job_dependencies/stdout b/test/008_job_dependencies/stdout deleted file mode 100644 index 73dc3ee..0000000 --- a/test/008_job_dependencies/stdout +++ /dev/null @@ -1 +0,0 @@ -Fatal error validating 008_job_dependencies/test.yml diff --git a/test/009_multi_file/stdout b/test/009_multi_file/stdout deleted file mode 100644 index ec1a3fd..0000000 --- a/test/009_multi_file/stdout +++ /dev/null @@ -1 +0,0 @@ -Fatal error validating 009_multi_file/xinvalid.yml diff --git a/test/001_basic_workflow/test.yml b/tests/001_basic_workflow/test.yml similarity index 100% rename from test/001_basic_workflow/test.yml rename to tests/001_basic_workflow/test.yml diff --git a/test/001_basic_workflow/validation_state.snap.json b/tests/001_basic_workflow/validation_state.snap.json similarity index 100% rename from test/001_basic_workflow/validation_state.snap.json rename to tests/001_basic_workflow/validation_state.snap.json diff --git a/test/002_basic_action/action.yml b/tests/002_basic_action/action.yml similarity index 100% rename from test/002_basic_action/action.yml rename to tests/002_basic_action/action.yml diff --git a/test/002_basic_action/validation_state.snap.json b/tests/002_basic_action/validation_state.snap.json similarity index 100% rename from test/002_basic_action/validation_state.snap.json rename to tests/002_basic_action/validation_state.snap.json diff --git a/test/003_successful_globs/glob.yml b/tests/003_successful_globs/glob.yml similarity index 88% rename from test/003_successful_globs/glob.yml rename to tests/003_successful_globs/glob.yml index 6608e8b..2981f5b 100644 --- a/test/003_successful_globs/glob.yml +++ b/tests/003_successful_globs/glob.yml @@ -3,7 +3,7 @@ name: Test on: push: paths: - - 003_successful_globs/* + - ./tests/003_successful_globs/* defaults: run: diff --git a/test/003_successful_globs/validation_state.snap.json b/tests/003_successful_globs/validation_state.snap.json similarity index 100% rename from test/003_successful_globs/validation_state.snap.json rename to tests/003_successful_globs/validation_state.snap.json diff --git a/test/004_failing_globs/exitcode b/tests/004_failing_globs/exitcode similarity index 100% rename from test/004_failing_globs/exitcode rename to tests/004_failing_globs/exitcode diff --git a/test/004_failing_globs/glob.yml b/tests/004_failing_globs/glob.yml similarity index 89% rename from test/004_failing_globs/glob.yml rename to tests/004_failing_globs/glob.yml index 7c4d27e..fa2a7c8 100644 --- a/test/004_failing_globs/glob.yml +++ b/tests/004_failing_globs/glob.yml @@ -3,7 +3,7 @@ name: Bad globs, no biscuit on: push: paths: - - 004_bad_globs/*.txt + - ./tests/004_bad_globs/*.txt defaults: run: diff --git a/test/004_failing_globs/stderr b/tests/004_failing_globs/stderr similarity index 70% rename from test/004_failing_globs/stderr rename to tests/004_failing_globs/stderr index 2171874..f7e987a 100644 --- a/test/004_failing_globs/stderr +++ b/tests/004_failing_globs/stderr @@ -3,13 +3,13 @@ Validation failed: ValidationState { Workflow, ), file_path: Some( - "004_failing_globs/glob.yml", + "./tests/004_failing_globs/glob.yml", ), errors: [ NoFilesMatchingGlob { code: "glob_not_matched", detail: Some( - "Glob \"004_bad_globs/*.txt\" in /on/push/paths does not match any files", + "Glob \"./tests/004_bad_globs/*.txt\" in /on/push/paths does not match any files", ), path: "/on/push/paths", title: "Glob does not match any files", diff --git a/tests/004_failing_globs/stdout b/tests/004_failing_globs/stdout new file mode 100644 index 0000000..2455d96 --- /dev/null +++ b/tests/004_failing_globs/stdout @@ -0,0 +1 @@ +Fatal error validating ./tests/004_failing_globs/glob.yml diff --git a/test/004_failing_globs/validation_state.snap.json b/tests/004_failing_globs/validation_state.snap.json similarity index 100% rename from test/004_failing_globs/validation_state.snap.json rename to tests/004_failing_globs/validation_state.snap.json diff --git a/test/005_conditional_step_in_action/action.yml b/tests/005_conditional_step_in_action/action.yml similarity index 100% rename from test/005_conditional_step_in_action/action.yml rename to tests/005_conditional_step_in_action/action.yml diff --git a/test/005_conditional_step_in_action/validation_state.snap.json b/tests/005_conditional_step_in_action/validation_state.snap.json similarity index 100% rename from test/005_conditional_step_in_action/validation_state.snap.json rename to tests/005_conditional_step_in_action/validation_state.snap.json diff --git a/test/006_workflow_dispatch_inputs_options/test.yml b/tests/006_workflow_dispatch_inputs_options/test.yml similarity index 100% rename from test/006_workflow_dispatch_inputs_options/test.yml rename to tests/006_workflow_dispatch_inputs_options/test.yml diff --git a/test/006_workflow_dispatch_inputs_options/validation_state.snap.json b/tests/006_workflow_dispatch_inputs_options/validation_state.snap.json similarity index 100% rename from test/006_workflow_dispatch_inputs_options/validation_state.snap.json rename to tests/006_workflow_dispatch_inputs_options/validation_state.snap.json diff --git a/test/007_funky_syntax/exitcode b/tests/007_funky_syntax/exitcode similarity index 100% rename from test/007_funky_syntax/exitcode rename to tests/007_funky_syntax/exitcode diff --git a/test/007_funky_syntax/rust-check.yml b/tests/007_funky_syntax/rust-check.yml similarity index 100% rename from test/007_funky_syntax/rust-check.yml rename to tests/007_funky_syntax/rust-check.yml diff --git a/test/007_funky_syntax/stderr b/tests/007_funky_syntax/stderr similarity index 91% rename from test/007_funky_syntax/stderr rename to tests/007_funky_syntax/stderr index 17c1d62..fbafbf5 100644 --- a/test/007_funky_syntax/stderr +++ b/tests/007_funky_syntax/stderr @@ -3,7 +3,7 @@ Validation failed: ValidationState { Workflow, ), file_path: Some( - "007_funky_syntax/rust-check.yml", + "./tests/007_funky_syntax/rust-check.yml", ), errors: [ Parse { diff --git a/tests/007_funky_syntax/stdout b/tests/007_funky_syntax/stdout new file mode 100644 index 0000000..a8b577f --- /dev/null +++ b/tests/007_funky_syntax/stdout @@ -0,0 +1 @@ +Fatal error validating ./tests/007_funky_syntax/rust-check.yml diff --git a/test/007_funky_syntax/validation_state.snap.json b/tests/007_funky_syntax/validation_state.snap.json similarity index 100% rename from test/007_funky_syntax/validation_state.snap.json rename to tests/007_funky_syntax/validation_state.snap.json diff --git a/test/008_job_dependencies/exitcode b/tests/008_job_dependencies/exitcode similarity index 100% rename from test/008_job_dependencies/exitcode rename to tests/008_job_dependencies/exitcode diff --git a/test/008_job_dependencies/stderr b/tests/008_job_dependencies/stderr similarity index 88% rename from test/008_job_dependencies/stderr rename to tests/008_job_dependencies/stderr index a8d64bf..d859143 100644 --- a/test/008_job_dependencies/stderr +++ b/tests/008_job_dependencies/stderr @@ -3,7 +3,7 @@ Validation failed: ValidationState { Workflow, ), file_path: Some( - "008_job_dependencies/test.yml", + "./tests/008_job_dependencies/test.yml", ), errors: [ UnresolvedJob { diff --git a/tests/008_job_dependencies/stdout b/tests/008_job_dependencies/stdout new file mode 100644 index 0000000..3576abf --- /dev/null +++ b/tests/008_job_dependencies/stdout @@ -0,0 +1 @@ +Fatal error validating ./tests/008_job_dependencies/test.yml diff --git a/test/008_job_dependencies/test.yml b/tests/008_job_dependencies/test.yml similarity index 100% rename from test/008_job_dependencies/test.yml rename to tests/008_job_dependencies/test.yml diff --git a/test/008_job_dependencies/validation_state.snap.json b/tests/008_job_dependencies/validation_state.snap.json similarity index 100% rename from test/008_job_dependencies/validation_state.snap.json rename to tests/008_job_dependencies/validation_state.snap.json diff --git a/test/009_multi_file/exitcode b/tests/009_multi_file/exitcode similarity index 100% rename from test/009_multi_file/exitcode rename to tests/009_multi_file/exitcode diff --git a/test/009_multi_file/stderr b/tests/009_multi_file/stderr similarity index 92% rename from test/009_multi_file/stderr rename to tests/009_multi_file/stderr index b4fe130..6e52470 100644 --- a/test/009_multi_file/stderr +++ b/tests/009_multi_file/stderr @@ -3,7 +3,7 @@ Validation failed: ValidationState { Workflow, ), file_path: Some( - "009_multi_file/xinvalid.yml", + "./tests/009_multi_file/xinvalid.yml", ), errors: [ Parse { diff --git a/tests/009_multi_file/stdout b/tests/009_multi_file/stdout new file mode 100644 index 0000000..8e003c7 --- /dev/null +++ b/tests/009_multi_file/stdout @@ -0,0 +1 @@ +Fatal error validating ./tests/009_multi_file/xinvalid.yml diff --git a/test/009_multi_file/valid.yml b/tests/009_multi_file/valid.yml similarity index 100% rename from test/009_multi_file/valid.yml rename to tests/009_multi_file/valid.yml diff --git a/test/009_multi_file/validation_state.snap.json b/tests/009_multi_file/validation_state.snap.json similarity index 100% rename from test/009_multi_file/validation_state.snap.json rename to tests/009_multi_file/validation_state.snap.json diff --git a/test/009_multi_file/xinvalid.yml b/tests/009_multi_file/xinvalid.yml similarity index 100% rename from test/009_multi_file/xinvalid.yml rename to tests/009_multi_file/xinvalid.yml diff --git a/tests/010_remote_checks_ok/test.yml b/tests/010_remote_checks_ok/test.yml new file mode 100644 index 0000000..88adf73 --- /dev/null +++ b/tests/010_remote_checks_ok/test.yml @@ -0,0 +1,78 @@ +name: Test + +on: + push: + pull_request: + branches: + - main + +defaults: + run: + shell: bash + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + default: true + + - name: Check Formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + - name: Check with Clippy + uses: actions-rs/clippy-check@v1 + with: + args: -- -Dwarnings + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Shellcheck + uses: ludeeus/action-shellcheck@master + + - name: Install shfmt + uses: mfinelli/setup-shfmt@master + + - name: Run shfmt + run: shfmt -d bin/* + + + build: + strategy: + matrix: + rust-toolchain: + - stable + - nightly + os: + - ubuntu-latest + - macos-latest + - windows-latest + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust-toolchain }} + override: true + default: true + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --all-features diff --git a/tests/011_remote_checks_failure/exitcode b/tests/011_remote_checks_failure/exitcode new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/011_remote_checks_failure/exitcode @@ -0,0 +1 @@ +1 diff --git a/tests/011_remote_checks_failure/stderr b/tests/011_remote_checks_failure/stderr new file mode 100644 index 0000000..c9bc9dc --- /dev/null +++ b/tests/011_remote_checks_failure/stderr @@ -0,0 +1,18 @@ +Validation failed: ValidationState { + action_type: Some( + Workflow, + ), + file_path: Some( + "./tests/011_remote_checks_failure/test.yml", + ), + errors: [ + Unknown { + code: "action_not_found", + detail: Some( + "Could not find action: actions/checkouts@v2", + ), + path: "jobs/build/steps/uses/actions/checkouts@v2", + title: "Action Not Found", + }, + ], +} diff --git a/tests/011_remote_checks_failure/stdout b/tests/011_remote_checks_failure/stdout new file mode 100644 index 0000000..79ef8c0 --- /dev/null +++ b/tests/011_remote_checks_failure/stdout @@ -0,0 +1 @@ +Fatal error validating ./tests/011_remote_checks_failure/test.yml diff --git a/tests/011_remote_checks_failure/test.yml b/tests/011_remote_checks_failure/test.yml new file mode 100644 index 0000000..6a5105e --- /dev/null +++ b/tests/011_remote_checks_failure/test.yml @@ -0,0 +1,78 @@ +name: Test + +on: + push: + pull_request: + branches: + - main + +defaults: + run: + shell: bash + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + default: true + + - name: Check Formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + - name: Check with Clippy + uses: actions-rs/clippy-check@v1 + with: + args: -- -Dwarnings + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Shellcheck + uses: ludeeus/action-shellcheck@master + + - name: Install shfmt + uses: mfinelli/setup-shfmt@master + + - name: Run shfmt + run: shfmt -d bin/* + + + build: + strategy: + matrix: + rust-toolchain: + - stable + - nightly + os: + - ubuntu-latest + - macos-latest + - windows-latest + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkouts@v2 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust-toolchain }} + override: true + default: true + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --all-features diff --git a/test/run b/tests/run similarity index 100% rename from test/run rename to tests/run diff --git a/test/run.mjs b/tests/run.mjs similarity index 100% rename from test/run.mjs rename to tests/run.mjs diff --git a/tests/snapshot_tests.rs b/tests/snapshot_tests.rs new file mode 100644 index 0000000..9f56ff0 --- /dev/null +++ b/tests/snapshot_tests.rs @@ -0,0 +1,140 @@ +use std::{fs::{self, File}, ffi::{OsString, OsStr}}; +use std::io::prelude::*; + +use rstest::rstest; +use assert_cmd::Command; + + +#[derive(Debug)] +struct SnapshotTest { + test_dir: String, + exitcode: i32, + stderr: String, + stdout: String, + test_files: Vec, +} + +impl SnapshotTest { + fn new(test_dir: String) -> Self { + let stderr = fs::read_to_string( + format!("./tests/{test_dir}/stderr"), + ).unwrap_or(String::from("")); + + let stdout = fs::read_to_string( + format!("./tests/{test_dir}/stdout"), + ).unwrap_or(String::from("")); + + let exitcode: i32 = fs::read_to_string( + format!("./tests/{test_dir}/exitcode"), + ).map(|s| { + s + .strip_suffix("\n") + .unwrap_or(s.as_str()) + .parse::() + .unwrap_or(0) + }).unwrap_or(0); + + let test_files = Self::_get_files(&test_dir); + + SnapshotTest { + test_dir, + exitcode, + stderr, + stdout, + test_files, + } + } + + #[cfg(not(feature = "save-snapshots"))] + fn execute(self) { + Command::cargo_bin( + env!("CARGO_PKG_NAME"), + ) + .expect("binary to execute") + .args(self.test_files) + .assert() + .stdout(self.stdout) + .stderr(self.stderr) + .code(self.exitcode); + } + + #[cfg(feature = "save-snapshots")] + fn execute(&self) { + let test_dir = self.test_dir.to_owned(); + let test_files = self.test_files.to_owned(); + let result = Command::cargo_bin( + env!("CARGO_PKG_NAME"), + ) + .expect("binary to execute") + .args(test_files).ok().unwrap_or_else(|e| e.as_output().unwrap().to_owned()); + + if !result.stdout.is_empty() { + self._save_contents( + format!("./tests/{test_dir}/stdout"), + result.stdout, + ); + } + if !result.stderr.is_empty() { + self._save_contents( + format!("./tests/{test_dir}/stderr"), + result.stderr, + ); + } + if let Some(exitcode) = result.status.code() { + if exitcode > 0 { + self._save_contents( + format!("./tests/{test_dir}/exitcode"), + format!("{exitcode}\n").into(), + ); + } + } + } + + fn _save_contents( + &self, + file_name: String, + contents: Vec, + ) { + println!("Saving {}", file_name); + let res = File::create(file_name).unwrap().write_all( + &contents, + ); + assert!(res.is_ok(), "{:?}", res); + } + + fn _get_files(test_dir: &String) -> Vec { + let yml = Some(OsStr::new("yml")); + fs::read_dir( + format!("./tests/{test_dir}"), + ) + .unwrap() + .filter_map(Result::ok) + .filter(|f| f.path().extension() == yml) + .map(|f| f.path().into_os_string()) + .collect::>() + } +} + + +#[rstest] +#[case("001_basic_workflow")] +#[case("002_basic_action")] +#[case("003_successful_globs")] +#[case("004_failing_globs")] +#[case("005_conditional_step_in_action")] +#[case("006_workflow_dispatch_inputs_options")] +#[case("007_funky_syntax")] +#[case("008_job_dependencies")] +#[case("009_multi_file")] +#[cfg(not(feature = "remote-checks"))] +fn snapshot(#[case] dir_name: String) { + SnapshotTest::new(dir_name).execute(); +} + +#[rstest] +#[case("010_remote_checks_ok")] +#[case("011_remote_checks_failure")] +#[cfg(feature = "remote-checks")] +fn snapshot_remote_checks(#[case] dir_name: String) { + SnapshotTest::new(dir_name).execute(); +} From a04ef569a5411179e9296945cd5e4bb4cdc34315 Mon Sep 17 00:00:00 2001 From: Austin Ward Date: Tue, 2 May 2023 21:33:42 -0400 Subject: [PATCH 3/5] Remove remote checks tests --- Cargo.lock | 303 ++++++++++++++++++++--- tests/010_remote_checks_ok/test.yml | 78 ------ tests/011_remote_checks_failure/exitcode | 1 - tests/011_remote_checks_failure/stderr | 18 -- tests/011_remote_checks_failure/stdout | 1 - tests/011_remote_checks_failure/test.yml | 78 ------ tests/snapshot_tests.rs | 9 - 7 files changed, 273 insertions(+), 215 deletions(-) delete mode 100644 tests/010_remote_checks_ok/test.yml delete mode 100644 tests/011_remote_checks_failure/exitcode delete mode 100644 tests/011_remote_checks_failure/stderr delete mode 100644 tests/011_remote_checks_failure/stdout delete mode 100644 tests/011_remote_checks_failure/test.yml diff --git a/Cargo.lock b/Cargo.lock index dae02ae..bc15b1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,9 +6,11 @@ version = 3 name = "action-validator" version = "0.0.0-git" dependencies = [ + "assert_cmd", "clap", "console_error_panic_hook", "glob", + "rstest", "serde", "serde-wasm-bindgen", "serde_json", @@ -16,7 +18,6 @@ dependencies = [ "valico", "wasm-bindgen", "wasm-bindgen-test", - "wee_alloc", ] [[package]] @@ -47,6 +48,27 @@ dependencies = [ "libc", ] +[[package]] +name = "anstyle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "assert_cmd" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d6b683edf8d1119fe420a94f8a7e389239666aa72e65495d91c00462510151" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -80,6 +102,18 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bstr" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d4260bcc2e8fc9df1eac4919a720effeb63a3f0952f5bf4944adfa18897f09" +dependencies = [ + "memchr", + "once_cell", + "regex-automata", + "serde", +] + [[package]] name = "bumpalo" version = "3.12.0" @@ -92,12 +126,6 @@ version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -169,7 +197,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen", ] @@ -223,12 +251,30 @@ dependencies = [ "syn", ] +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "downcast-rs" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + [[package]] name = "erased-serde" version = "0.3.24" @@ -279,13 +325,108 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-timer" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" + +[[package]] +name = "futures-util" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "getrandom" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "libc", "wasi", @@ -386,6 +527,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.8" @@ -453,7 +603,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -468,12 +618,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "num-integer" version = "0.1.44" @@ -549,6 +693,46 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "predicates" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9" +dependencies = [ + "anstyle", + "difflib", + "itertools", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -632,12 +816,53 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +[[package]] +name = "rstest" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07f2d176c472198ec1e6551dc7da28f1c089652f66a7b722676c2238ebc0edf" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros", + "rustc_version", +] + +[[package]] +name = "rstest_macros" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7229b505ae0706e64f37ffc54a9c163e11022a6636d58fe1f3f52018257ff9f7" +dependencies = [ + "cfg-if", + "proc-macro2", + "quote", + "rustc_version", + "syn", + "unicode-ident", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.36.6" @@ -670,6 +895,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + [[package]] name = "serde" version = "1.0.152" @@ -731,6 +962,15 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b" +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + [[package]] name = "strsim" version = "0.10.0" @@ -757,6 +997,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + [[package]] name = "tinyvec" version = "1.5.0" @@ -866,6 +1112,15 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -878,7 +1133,7 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -903,7 +1158,7 @@ version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -972,18 +1227,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/tests/010_remote_checks_ok/test.yml b/tests/010_remote_checks_ok/test.yml deleted file mode 100644 index 88adf73..0000000 --- a/tests/010_remote_checks_ok/test.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Test - -on: - push: - pull_request: - branches: - - main - -defaults: - run: - shell: bash - -jobs: - check: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - default: true - - - name: Check Formatting - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check - - - name: Check with Clippy - uses: actions-rs/clippy-check@v1 - with: - args: -- -Dwarnings - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Shellcheck - uses: ludeeus/action-shellcheck@master - - - name: Install shfmt - uses: mfinelli/setup-shfmt@master - - - name: Run shfmt - run: shfmt -d bin/* - - - build: - strategy: - matrix: - rust-toolchain: - - stable - - nightly - os: - - ubuntu-latest - - macos-latest - - windows-latest - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust-toolchain }} - override: true - default: true - - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --all-features diff --git a/tests/011_remote_checks_failure/exitcode b/tests/011_remote_checks_failure/exitcode deleted file mode 100644 index d00491f..0000000 --- a/tests/011_remote_checks_failure/exitcode +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/011_remote_checks_failure/stderr b/tests/011_remote_checks_failure/stderr deleted file mode 100644 index c9bc9dc..0000000 --- a/tests/011_remote_checks_failure/stderr +++ /dev/null @@ -1,18 +0,0 @@ -Validation failed: ValidationState { - action_type: Some( - Workflow, - ), - file_path: Some( - "./tests/011_remote_checks_failure/test.yml", - ), - errors: [ - Unknown { - code: "action_not_found", - detail: Some( - "Could not find action: actions/checkouts@v2", - ), - path: "jobs/build/steps/uses/actions/checkouts@v2", - title: "Action Not Found", - }, - ], -} diff --git a/tests/011_remote_checks_failure/stdout b/tests/011_remote_checks_failure/stdout deleted file mode 100644 index 79ef8c0..0000000 --- a/tests/011_remote_checks_failure/stdout +++ /dev/null @@ -1 +0,0 @@ -Fatal error validating ./tests/011_remote_checks_failure/test.yml diff --git a/tests/011_remote_checks_failure/test.yml b/tests/011_remote_checks_failure/test.yml deleted file mode 100644 index 6a5105e..0000000 --- a/tests/011_remote_checks_failure/test.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Test - -on: - push: - pull_request: - branches: - - main - -defaults: - run: - shell: bash - -jobs: - check: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - default: true - - - name: Check Formatting - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check - - - name: Check with Clippy - uses: actions-rs/clippy-check@v1 - with: - args: -- -Dwarnings - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Shellcheck - uses: ludeeus/action-shellcheck@master - - - name: Install shfmt - uses: mfinelli/setup-shfmt@master - - - name: Run shfmt - run: shfmt -d bin/* - - - build: - strategy: - matrix: - rust-toolchain: - - stable - - nightly - os: - - ubuntu-latest - - macos-latest - - windows-latest - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout - uses: actions/checkouts@v2 - - - name: Setup Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust-toolchain }} - override: true - default: true - - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --all-features diff --git a/tests/snapshot_tests.rs b/tests/snapshot_tests.rs index 9f56ff0..568bd8d 100644 --- a/tests/snapshot_tests.rs +++ b/tests/snapshot_tests.rs @@ -126,15 +126,6 @@ impl SnapshotTest { #[case("007_funky_syntax")] #[case("008_job_dependencies")] #[case("009_multi_file")] -#[cfg(not(feature = "remote-checks"))] fn snapshot(#[case] dir_name: String) { SnapshotTest::new(dir_name).execute(); } - -#[rstest] -#[case("010_remote_checks_ok")] -#[case("011_remote_checks_failure")] -#[cfg(feature = "remote-checks")] -fn snapshot_remote_checks(#[case] dir_name: String) { - SnapshotTest::new(dir_name).execute(); -} From f86098c6341a0f1ed21181c5c67a66bac81f3942 Mon Sep 17 00:00:00 2001 From: Ben Heidemann Date: Wed, 3 May 2023 12:15:58 +0100 Subject: [PATCH 4/5] fix: run.mjs parent directory renaming --- package.json | 2 +- tests/run.mjs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 5a176c4..7b0d7d0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "GPL-3.0-only", "scripts": { "build": "npx wasm-pack build --out-dir target/wasm-pack/build --no-typescript --target nodejs --features js && cp target/wasm-pack/build/action_validator_bg.wasm packages/core/ && cp target/wasm-pack/build/action_validator.js packages/core/ && cp target/wasm-pack/build/action_validator.js packages/core/", - "test": "node test/run.mjs", + "test": "node tests/run.mjs", "lint": "prettier --check .", "format": "prettier --write ." }, diff --git a/tests/run.mjs b/tests/run.mjs index 7b026e6..6956c28 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -9,9 +9,9 @@ const update = process.argv.includes("--update") || process.argv.includes("-u"); const start = Date.now(); const passed = fs - .readdirSync("test") - // get all directories in test/ - .map((entry) => `test/${entry}`) + .readdirSync("tests") + // get all directories in tests/ + .map((entry) => `tests/${entry}`) .filter((entry) => fs.statSync(entry).isDirectory()) // get the first .yml files in each directory .map((testDir) => [testDir, ...fs.readdirSync(testDir)]) From a7a20f17dc20163db76a6c8748c9fd77f929c959 Mon Sep 17 00:00:00 2001 From: award28 Date: Wed, 3 May 2023 12:43:18 -0400 Subject: [PATCH 5/5] Update qa job and js package tests; remove `run` binary --- .github/workflows/qa.yml | 7 ++--- packages/cli/package.json | 2 +- packages/core/package.json | 2 +- tests/run | 56 -------------------------------------- 4 files changed, 4 insertions(+), 63 deletions(-) delete mode 100755 tests/run diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index 699e603..2f98819 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -44,11 +44,8 @@ jobs: - name: Shellcheck uses: ludeeus/action-shellcheck@master - - name: Install shfmt - uses: mfinelli/setup-shfmt@master - - - name: Run shfmt - run: shfmt -d bin/* test/run + - name: Run Cargo Test + run: cargo test - name: Setup Node uses: actions/setup-node@v3 diff --git a/packages/cli/package.json b/packages/cli/package.json index 3b08d82..7ef99d5 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -21,7 +21,7 @@ }, "scripts": { "build": "npx wasm-pack build --out-dir target/wasm-pack/build --no-typescript --target nodejs --features js && cp target/wasm-pack/build/action_validator_bg.wasm dist/ && cp target/wasm-pack/build/action_validator.js dist/ && cp target/wasm-pack/build/action_validator.js dist/", - "test": "node test/run.mjs", + "test": "node tests/run.mjs", "lint": "prettier --check .", "format": "prettier --write ." }, diff --git a/packages/core/package.json b/packages/core/package.json index 7ef9b17..3ee260c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -21,7 +21,7 @@ "types": "action_validator.d.ts", "scripts": { "build": "npx wasm-pack build --out-dir target/wasm-pack/build --no-typescript --target nodejs --features js && cp target/wasm-pack/build/action_validator_bg.wasm dist/ && cp target/wasm-pack/build/action_validator.js dist/ && cp target/wasm-pack/build/action_validator.js dist/", - "test": "node test/run.mjs", + "test": "node tests/run.mjs", "lint": "prettier --check .", "format": "prettier --write ." } diff --git a/tests/run b/tests/run deleted file mode 100755 index f249e41..0000000 --- a/tests/run +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -cd "$(dirname "${BASH_SOURCE[0]}")" - -readonly cmd="../target/debug/action-validator" - -if ! [ -x "$cmd" ]; then - echo "No action-validator to test; have you run 'cargo build' lately?" >&2 - exit 1 -fi - -for t in [0-9]*; do - expected_stdout="$(cat "$t/stdout" 2>/dev/null || true)" - expected_stderr="$(cat "$t/stderr" 2>/dev/null || true)" - expected_exitcode="$(cat "$t/exitcode" 2>/dev/null || echo 0)" - - dir="$(mktemp -d)" - trap 'rm -rf "$dir"' EXIT - - failed=n - rv=0 - - readarray -t -d '' testfiles < <(find "$t"/ -name '*.yml' -print0) - - "$cmd" "${testfiles[@]}" >"$dir/stdout" 2>"$dir/stderr" || rv="$?" - stdout="$(cat "$dir"/stdout)" - stderr="$(cat "$dir"/stderr)" - - if [ "$rv" != "$expected_exitcode" ]; then - echo "Test $t exited with unexpected code: expected $expected_exitcode, got $rv" >&2 - failed=y - fi - - if [ "$stdout" != "$expected_stdout" ]; then - echo "Test $t produced unexpected stdout:" >&2 - diff -u <(echo "$expected_stdout") <(echo "$stdout") >&2 || true - failed=y - fi - - if [ "$stderr" != "$expected_stderr" ]; then - echo "Test $t produced unexpected stderr:" >&2 - diff -u <(echo "$expected_stderr") <(echo "$stderr") >&2 || true - failed=y - fi - - rm -rf "$dir" - trap "" EXIT - - if [ "$failed" = "y" ]; then - exit 1 - fi -done - -echo "All tests passed."