Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad committed Dec 31, 2024
1 parent cf8bb78 commit 0dc5167
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 47 deletions.
16 changes: 8 additions & 8 deletions loco-new/base_template/.github/workflows/ci.yaml.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${% raw %}{{ env.RUST_TOOLCHAIN }}{% endraw %}
components: rustfmt
- name: Run cargo fmt
uses: actions-rs/cargo@v1
Expand All @@ -43,7 +43,7 @@ jobs:
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${% raw %}{{ env.RUST_TOOLCHAIN }}{% endraw %}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Run cargo clippy
Expand Down Expand Up @@ -88,19 +88,19 @@ jobs:
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
toolchain: ${% raw %}{{ env.RUST_TOOLCHAIN }}{% endraw %}

{%- if settings.asset %}
{%- if settings.asset.kind == "client" %}
- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{matrix.node-version}}
registry-url: https://registry.npmjs.org
node-version: ${% raw %}{{matrix.node-version}}{% endraw %}
- name: Build frontend
run: npm install && npm run build
working-directory: ./frontend
{%- endif -%}
{%- endif -%}
{%- endif %}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Run cargo test
Expand All @@ -109,6 +109,6 @@ jobs:
command: test
args: --all-features --all
env:
REDIS_URL: redis://localhost:${{job.services.redis.ports[6379]}}
REDIS_URL: redis://localhost:${% raw %}{{job.services.redis.ports[6379]}}{% endraw %}
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres_test

62 changes: 23 additions & 39 deletions loco-new/tests/templates/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,44 +95,28 @@ fn test_cargo_toml(

#[rstest]
fn test_github_ci_yaml(
#[values(".github/workflows/ci.yaml")] ci_file: &str,
#[values(AssetsOption::None, AssetsOption::Serverside, AssetsOption::Clientside)]
asset: AssetsOption,
) {
let generator: TestGenerator = run_generator(AssetsOption::Clientside);
let content = assertion::yaml::load(generator.path(ci_file));

assertion::yaml::assert_path_is_object(&content, &["jobs", "test", "steps"]);

let expected: serde_yaml::Value = serde_yaml::from_str(
r"
- name: Checkout the code
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{matrix.node-version}}
registry-url: https://registry.npmjs.org
- name: Build frontend
run: npm install && npm run build
working-directory: ./frontend
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --all
env:
REDIS_URL: redis://localhost:${{job.services.redis.ports[6379]}}
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres_test
",
)
.unwrap();
assertion::yaml::assert_path_value_eq(
&content,
&["jobs", "test", "steps"],
&expected,
);
let generator: TestGenerator = run_generator(asset.clone());
let content =
std::fs::read_to_string(generator.path(".github").join("workflows").join("ci.yaml"))
.expect("could not open file");

let frontend_section = r" - name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{matrix.node-version}}
- name: Build frontend
run: npm install && npm run build
working-directory: ./frontend
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2";

match asset {
AssetsOption::Serverside | AssetsOption::None => {
assert!(!content.contains(frontend_section));
}
AssetsOption::Clientside => assert!(content.contains(frontend_section)),
}
}

0 comments on commit 0dc5167

Please sign in to comment.