Skip to content

Update --language support for new-query subcommand #28

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions CodeQLToolkit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Shared.Tests", "test\CodeQLToolkit.Shared.Tests\CodeQLToolkit.Shared.Tests.csproj", "{E57121C2-2A2E-487C-9C32-A7D8914E9123}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Tests", "test\CodeQLToolkit.Features.Tests\CodeQLToolkit.Features.Tests.csproj", "{F1234567-89AB-CDEF-0123-456789ABCDEF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -55,6 +57,10 @@ Global
{E57121C2-2A2E-487C-9C32-A7D8914E9123}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E57121C2-2A2E-487C-9C32-A7D8914E9123}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E57121C2-2A2E-487C-9C32-A7D8914E9123}.Release|Any CPU.Build.0 = Release|Any CPU
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -65,6 +71,7 @@ Global
{A1F78CBC-9AE9-4360-A06B-395F368B183A} = {05645E0E-835A-4627-BDAE-C27EC39B23EE}
{B85F1529-3321-4AD2-924A-6EA478145DC5} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C}
{E57121C2-2A2E-487C-9C32-A7D8914E9123} = {05645E0E-835A-4627-BDAE-C27EC39B23EE}
{F1234567-89AB-CDEF-0123-456789ABCDEF} = {05645E0E-835A-4627-BDAE-C27EC39B23EE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BF8F3B81-F4DC-4608-A41C-F00F3E5A05CA}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,33 @@ public class InstallCommand : CommandTarget
{
public bool CustomBundles { get; set; }
public bool QuickBundles { get; set; }
public string[] Packs { get; set; }
public string[] Packs { get; set; } = Array.Empty<string>();

void SetEnvironmentVariableMultiTarget(string name, string value)
{
Log<InstallCommand>.G().LogInformation($"Setting {name} to {value}...");

Environment.SetEnvironmentVariable(name, value);

// Only attempt to write to GITHUB_ENV if we're running in GitHub Actions
if (AutomationTypeHelper.AutomationTypeFromString(AutomationTarget) == AutomationType.ACTIONS)
{
string? githubEnvPath = Environment.GetEnvironmentVariable("GITHUB_ENV");
try
{
if (File.Exists(githubEnvPath))
if (!string.IsNullOrEmpty(githubEnvPath) && File.Exists(githubEnvPath))
{
File.AppendAllText(githubEnvPath, $"{name}={value}\n");
Log<InstallCommand>.G().LogInformation($"Successfully wrote {name} to GITHUB_ENV file.");
}
else
{
throw new Exception("Could not find GITHUB_ENV file.");
Log<InstallCommand>.G().LogWarning($"GITHUB_ENV file not found. Environment variable {name} set locally only.");
}
}
catch (Exception)
catch (Exception ex)
{
Log<InstallCommand>.G().LogError($"Could not write to GITHUB_ENV file.");
throw;
Log<InstallCommand>.G().LogWarning($"Could not write to GITHUB_ENV file: {ex.Message}. Environment variable {name} set locally only.");
}
}
}
Expand Down
105 changes: 105 additions & 0 deletions src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,69 @@
<None Update="Templates\Query\cpp\testref.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\csharp\expected.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\csharp\new-dataflow-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\csharp\new-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\csharp\qlpack-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\csharp\qlpack-test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\csharp\test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\csharp\testref.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\go\expected.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\go\new-dataflow-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\go\new-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\go\qlpack-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\go\qlpack-test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\go\test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\go\testref.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\java\expected.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\java\new-dataflow-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\java\new-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\java\qlpack-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\java\qlpack-test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\java\test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\java\testref.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\javascript\expected.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand All @@ -72,6 +135,48 @@
<None Update="Templates\Query\javascript\testref.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\python\expected.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\python\new-dataflow-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\python\new-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\python\qlpack-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\python\qlpack-test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\python\test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\python\testref.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\ruby\expected.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\ruby\new-dataflow-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\ruby\new-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\ruby\qlpack-query.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\ruby\qlpack-test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\ruby\test.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Query\ruby\testref.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Templates\Test\Actions\install-codeql.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ public QueryScaffoldFeature()
{
FeatureName = "Query";
}
public override LanguageType[] SupportedLangauges => new LanguageType[] { LanguageType.C, LanguageType.CPP, LanguageType.JAVASCRIPT };
public override LanguageType[] SupportedLangauges => new LanguageType[] {
LanguageType.C,
LanguageType.CPP,
LanguageType.CSHARP,
LanguageType.GO,
LanguageType.JAVA,
LanguageType.JAVASCRIPT,
LanguageType.PYTHON,
LanguageType.RUBY
};

public void Register(Command parentCommand)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public override void Run()
WriteTemplateIfOverwriteOrNotExists("qlpack-query", query.QueryPackPath, "new query pack", new
{
queryPackScope = query.Scope,
queryPackName = query.QueryPackName
queryPackName = query.QueryPackName,
ql_language = query.Language.ToDirectory()
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// not implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @id {{language}}/{{query_pack_name}}/{{query_name}}
* @name {{query_name}}
* @description {{description}}
* @kind path-problem
* @precision high
* @problem.severity error
* @tags {{query_pack_name}}
*/

import {{ql_language_import}}
import DataFlow::PathGraph

class Config extends TaintTracking::Configuration {
Config() { this = "MyConfig" }

override predicate isSource(DataFlow::Node source) {
// Define your sources here
none()
}

override predicate isSink(DataFlow::Node sink) {
// Define your sinks here
none()
}
}

from Config config, DataFlow::PathNode source, DataFlow::PathNode sink
where config.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "Replace this with your dataflow query."
14 changes: 14 additions & 0 deletions src/CodeQLToolkit.Features/Templates/Query/csharp/new-query.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @id {{language}}/{{query_pack_name}}/{{query_name}}
* @name {{query_name}}
* @description {{description}}
* @kind problem
* @precision medium
* @problem.severity error
* @tags {{query_pack_name}}
*/

import {{ql_language_import}}

from Expr e
select e, "Replace this with your query."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: {{query_pack_scope}}/{{query_pack_name}}
version: 0.0.0
description: Default description
suites:
license:
dependencies:
codeql/csharp-all: "^0.6.3"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: {{query_pack_scope}}/{{query_pack_name}}
version: 0.0.0
description: Default description
suites:
license:
extractor: csharp
dependencies:
{{query_pack_dependency}}: '*'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// not implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{query_name}}.ql
2 changes: 2 additions & 0 deletions src/CodeQLToolkit.Features/Templates/Query/go/expected.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
edges
| {{ query_name }}.go:0:0:0:0 | {{ query_name }} |
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @id {{language}}/{{query_pack_name}}/{{query_name}}
* @name {{query_name}}
* @description {{description}}
* @kind path-problem
* @precision high
* @problem.severity error
* @tags {{query_pack_name}}
*/

import {{ql_language_import}}
import DataFlow::PathGraph

class Config extends TaintTracking::Configuration {
Config() { this = "MyConfig" }

override predicate isSource(DataFlow::Node source) {
// Define your sources here
none()
}

override predicate isSink(DataFlow::Node sink) {
// Define your sinks here
none()
}
}

from Config config, DataFlow::PathNode source, DataFlow::PathNode sink
where config.hasFlowPath(source, sink)
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

The Go dataflow template uses an outdated API pattern. Line 22 is missing the override keyword for the isSink predicate, and the template should use the newer module-based configuration pattern consistent with other language templates.

Suggested change
where config.hasFlowPath(source, sink)
from DataFlow::Config::PathNode source, DataFlow::Config::PathNode sink
where DataFlow::Config.hasFlowPath(source, sink)

Copilot uses AI. Check for mistakes.

select sink.getNode(), source, sink, "Replace this with your dataflow query."
14 changes: 14 additions & 0 deletions src/CodeQLToolkit.Features/Templates/Query/go/new-query.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @id {{language}}/{{query_pack_name}}/{{query_name}}
* @name {{query_name}}
* @description {{description}}
* @kind problem
* @precision medium
* @problem.severity error
* @tags {{query_pack_name}}
*/

import {{ql_language_import}}

from Expr e
select e, "Replace this with your query."
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: {{query_pack_name}}
version: 0.0.0
library: false
dependencies:
codeql/{{ql_language}}-all: "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: {{query_pack_name}}-tests
version: 0.0.0
dependencies:
codeql/{{ql_language}}-all: "*"
{{query_pack_name}}: "*"
6 changes: 6 additions & 0 deletions src/CodeQLToolkit.Features/Templates/Query/go/test.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {{ql_language_import}}
import TestUtilities.InlineExpectationsTest

module {{query_name}}Test implements TestSig {
string getARelevantTag() { result = "{{query_name}}" }
}
6 changes: 6 additions & 0 deletions src/CodeQLToolkit.Features/Templates/Query/go/testref.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Test case for {{query_name}}
package main

func main() {
// ${{query_name}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
edges
| {{ query_name }}.java:0:0:0:0 | {{ query_name }} |
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @id {{language}}/{{query_pack_name}}/{{query_name}}
* @name {{query_name}}
* @description {{description}}
* @kind path-problem
* @precision medium
* @problem.severity error
* @tags {{query_pack_name}}
*/

import {{ql_language_import}}
import DataFlow::PathGraph

module Config implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) {
// Define your source here
none()
}

predicate isSink(DataFlow::Node node) {
// Define your sink here
none()
}
}

module Flow = TaintTracking::Global<Config>;

from Flow::PathNode source, Flow::PathNode sink
where Flow::flowPath(source, sink)
select sink.getNode(), source, sink, "Replace this with your query."
Loading
Loading