Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add validation for module source URLs #406

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

Open
matifali wants to merge 7 commits into main
base: main
Choose a base branch
Loading
from atif/validate-readme-source

Conversation

Copy link
Member

@matifali matifali commented Sep 1, 2025
edited
Loading

Would prevents issues like the one I fixed in #404

This change should have caught that error as

2025年09月01日 13:12:45.132 [erro] ...
 msg= Error during "README parsing" phase of README validation:
 - "registry/umair/modules/digitalocean-region/README.md": incorrect source URL format: found "registry.coder.com/coder/digitalocean-region/coder", expected "registry.coder.com/umair/digitalocean-region/coder"
error: script "validate-readme" exited with code 1

diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index
53b912b..eb3cf8b 100644 --- a/.github/workflows/ci.yaml +++
b/.github/workflows/ci.yaml @@ -63,8 +63,8 @@ jobs: - name: Set up Go
uses: actions/setup-go@v5 with: - go-version: "1.23.2" - - name:
Validate contributors + go-version: "1.25.0" + - name: Validate Reademde
run: go build ./cmd/readmevalidation && ./readmevalidation - name:
Remove build file artifact run: rm ./readmevalidation
Signed-off-by: Muhammad Atif Ali <me@matifali.dev>
@matifali matifali force-pushed the atif/validate-readme-source branch 3 times, most recently from 98efa49 to 898e773 Compare September 1, 2025 14:50
- Downgrade Go version in CI to 1.24 for consistency.
- Fix naming and path issues in `readmevalidation` code.
- Improve regex validation for module and namespace names.
- Correct typos and improve comments for clarity.
@matifali matifali force-pushed the atif/validate-readme-source branch from 898e773 to 3b6b1ba Compare September 1, 2025 14:53
@@ -63,8 +63,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.2"
- name: Validate contributors
go-version: "1.24"
Copy link
Member Author

@matifali matifali Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having weird issues with running Golang CI locally, and had to match the Go version.

Copy link
Member Author

@matifali matifali Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests generated by gemini CLI

@matifali matifali changed the title (削除) chore: Aadd validation for Terraform module source URLs (削除ここまで) (追記) chore: add validation for Terraform module source URLs (追記ここまで) Sep 1, 2025
@matifali matifali changed the title (削除) chore: add validation for Terraform module source URLs (削除ここまで) (追記) chore: add validation for module source URLs (追記ここまで) Sep 1, 2025
Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is close. I think there's a couple of changes we can make the code a bit better, though

return namespace, moduleName, nil
}

func validateModuleSourceURL(body string, filePath string) []error {
Copy link
Member

@Parkreiner Parkreiner Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I knew more about Coder templates. Do templates have a source field (or anything equivalent) that might need to be validated, too?

Copy link
Member Author

@matifali matifali Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no its not applicable to templates

Comment on lines 47 to 56
if strings.HasPrefix(nextLine, "```") {
if strings.HasPrefix(nextLine, "```tf") && firstTerraformBlock {
isInsideTerraform = true
firstTerraformBlock = false
} else if isInsideTerraform {
// End of first terraform block.
break
}
continue
}
Copy link
Member

@Parkreiner Parkreiner Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be rewritten as:

if strings.HasPrefix(nextLine, "```") {
	if strings.HasPrefix(nextLine, "```tf") {
		isInsideTerraform = true
		continue
	}
	if isInsideTerraform {
		break
	}
}

I don't see the point of the firstTerraformBlock variable. If we always break at the end of the first Terraform code block, we don't really need to track anything extra

Copy link
Member Author

@matifali matifali Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to check all tf blocks.

Copy link
Member

@Parkreiner Parkreiner Sep 4, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something obvious, then. What validation requirement(s) are we trying to fulfill?

I was under the impression that we wanted the first Terraform block to contain a source field, but that other sources could be valid for the other blocks. Are we trying to keep all sources fully "boxed in" for Coder templates?

Not saying that the current code is wrong, but I'm not fully sure what we're trying to protect against, so I just want to make sure I'm giving good feedback

Copy link
Member Author

@matifali matifali Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to make sure all sources for all codeblock in a module README.md are in correct format. This should not apply to templates if it does its probably a bug.

Copy link
Member

@Parkreiner Parkreiner Sep 5, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant "modules" instead of "templates"

But if the goal is to check all Terraform blocks, then we'll need to remove the firstTerraformBlock variable completely.

With how the code is currently set up, once we hit the end of the first block, we always hit the else if block and immediately break out of the loop. We would need to update the loop logic to keep going after reaching the end of a block – flipping isInsideTerraform back to false and then probably just continue

- Make regex more specific for registry.coder.com patterns only
- Refactor to add namespace and resourceName fields to coderResourceReadme struct
- Inline path parsing logic into parseCoderResourceReadme
- Update validateModuleSourceURL to use struct fields instead of filePath parameter
- Simplify Terraform block detection logic
- Reduce nesting with early continue statements
- Add comment explaining regex pattern
- Extract registry.coder.com into a constant
- Improve test readability with extracted variables
- Remove redundant checks in tests
- Replace custom contains function with strings.Contains
Co-authored-by: matifali <matifali@users.noreply.github.com>
@matifali matifali removed the request for review from 35C4n0r September 13, 2025 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@bcpeinhardt bcpeinhardt Awaiting requested review from bcpeinhardt

@Parkreiner Parkreiner Awaiting requested review from Parkreiner

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /