Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Bug Report Template
name: 🐛 Bug Report
description: Report unexpected behavior, failures, or issues in the project.
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/verify-templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Verify Templates

on:
pull_request:

jobs:
verify-templates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Run verify-templates test
run: cargo test --test verify_templates
1 change: 1 addition & 0 deletions templates/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- outlines the expected standards of behavior for individuals within an organization or group. -->
# Code of Conduct

## Our Commitment
Expand Down
1 change: 0 additions & 1 deletion templates/issue-templates/bug.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Bug Report Template
name: 🐛 Bug Report
description: Report unexpected behavior, failures, or issues in the project.
Expand Down
2 changes: 2 additions & 0 deletions templates/pr-templates/bug.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!-- Submit a fix for a known bug -->
---

name: 🐞 Bug Fix
about: Submit a fix for a known bug
title: "[BUGFIX] <short summary>"
Expand Down
3 changes: 3 additions & 0 deletions templates/pr-templates/community.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<!-- Propose or enhance collaboration with the community -->

---

name: 🤝 Community Collaboration
about: Propose or enhance collaboration with the community
title: "[COMMUNITY] <short summary>"
Expand Down
2 changes: 2 additions & 0 deletions templates/pr-templates/default.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!-- Submit a new feature, bug fix, or improvement -->
---

name: 🚀 Pull Request
about: Submit a new feature, bug fix, or improvement
title: "[PR] <short summary>"
Expand Down
1 change: 1 addition & 0 deletions templates/pr-templates/docs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- Propose improvements or additions to project documentation -->
---
name: 📚 Documentation Update
about: Propose improvements or additions to project documentation
Expand Down
1 change: 1 addition & 0 deletions templates/pr-templates/dx.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- Share feedback or suggestions to improve the developer experience -->
---
name: 🛠️ Developer Experience Feedback
about: Share feedback or suggestions to improve the developer experience
Expand Down
1 change: 1 addition & 0 deletions templates/pr-templates/feature.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- Propose and implement a new feature -->
---
name: ✨ Feature Request
about: Propose and implement a new feature
Expand Down
1 change: 1 addition & 0 deletions templates/pr-templates/test.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- Propose changes to tests or add new tests -->
---
name: 🧪 Test Improvement
about: Propose changes to tests or add new tests
Expand Down
90 changes: 90 additions & 0 deletions tests/verify_templates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use std::collections::HashMap;
use std::fs;
use std::io::{BufRead, BufReader};
use std::path::Path;

// Checks that all template files in the `templates` directory start with a comment
// appropriate for their file type. This is useful for ensuring that templates are well-documented
// and provide clear instructions or context for users who create new repositories from these templates.
#[test]
fn all_templates_start_with_comment() {
let template_dir = Path::new("./templates");

// Map extensions to comment symbols
let comment_map = HashMap::from([
("rs", "//"),
("py", "#"),
("sh", "#"),
("js", "//"),
("ts", "//"),
("html", "<!--"),
("css", "/*"),
("yaml", "#"),
("yml", "#"),
("toml", "#"),
("md", "<!--"),
]);

assert!(
template_dir.exists(),
"Template directory does not exist: {:?}",
template_dir
);

fn check_templates_in_dir(
dir: &Path,
comment_map: &HashMap<&str, &str>,
failed_files: &mut Vec<(String, String, String)>,
) {
for entry in fs::read_dir(dir).expect("Failed to read templates directory") {
let entry = entry.expect("Failed to read file entry");
let path = entry.path();

if path.is_dir() {
check_templates_in_dir(&path, comment_map, failed_files);
} else if path.is_file() {
let extension = path.extension().and_then(|s| s.to_str()).unwrap_or("");
let comment_prefix = comment_map.get(extension).unwrap_or(&"#");

let file = fs::File::open(&path).expect("Failed to open template file");
let mut reader = BufReader::new(file);
let mut first_line = String::new();

reader
.read_line(&mut first_line)
.expect("Failed to read first line");

let trimmed = first_line.trim_start();

let starts_with_comment = trimmed.starts_with(comment_prefix);
if !starts_with_comment {
failed_files.push((
path.display().to_string(),
comment_prefix.to_string(),
first_line.clone(),
));
}
}
}
}

let mut failed_files = Vec::new();
check_templates_in_dir(template_dir, &comment_map, &mut failed_files);

if !failed_files.is_empty() {
println!("\n❌ The following files do not start with the expected comment:");
for (file, expected, first_line) in &failed_files {
println!(
"🔺 File: {}\n Expected prefix: {:?}\n First line: {}\n",
file,
expected,
first_line.trim_end()
);
}
}

assert!(
failed_files.is_empty(),
"Some template files do not start with the expected comment. See output above."
);
Comment thread
RafaelJohn9 marked this conversation as resolved.
}
Loading