Merge pull request #26 from github/integration-tests

Testing overhaul
This commit is contained in:
David Verdeguer 2020-05-12 10:36:21 +02:00 committed by GitHub
commit a76042ab4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 434 additions and 45 deletions

View file

@ -1,4 +1,6 @@
me: "CodeQL config"
name: "CodeQL config"
queries:
- name: Run custom queries
uses: ./queries
paths-ignore:
- tests

View file

@ -13,5 +13,6 @@ jobs:
- uses: actions/checkout@v1
- uses: ./init
with:
config-file: ./.github/codeql/codeql-config.yml
languages: javascript
config-file: ./.github/codeql/codeql-config.yml
- uses: ./analyze

View file

@ -1,22 +1,117 @@
name: "Integration Testing"
on: [push]
on: [push, pull_request]
jobs:
dispatch-events:
if: github.event.repository.full_name == 'github/codeql-action'
runs-on: ubuntu-latest
steps:
- name: Send repository dispatch events
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.CODEQL_TESTING_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/Anthophila/amazon-cognito-js-copy/dispatches \
-d '{"event_type":"codeql-integration","client_payload": {"sha": "${{ github.sha }}"}}'
multi-language-repo_test-autodetect-languages:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
curl -X POST \
-H "Authorization: Bearer ${{ secrets.CODEQL_TESTING_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/Anthophila/electron-test-action/dispatches \
-d '{"event_type":"codeql-integration","client_payload": {"sha": "${{ github.sha }}"}}'
steps:
- uses: actions/checkout@v2
- name: Move codeql-action
shell: bash
run: |
mkdir ../action
shopt -s dotglob
mv * ../action/
mv ../action/tests/multi-language-repo/* .
- uses: ./../action/init
- name: Build code
shell: bash
run: ./build.sh
- uses: ./../action/analyze
env:
TEST_MODE: true
multi-language-repo_test-custom-queries:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Move codeql-action
shell: bash
run: |
mkdir ../action
shopt -s dotglob
mv * ../action/
mv ../action/tests/multi-language-repo/* .
- uses: ./../action/init
with:
languages: cpp,csharp,java,javascript,python
config-file: ./.github/codeql/custom-queries.yml
- name: Build code
shell: bash
run: ./build.sh
- uses: ./../action/analyze
env:
TEST_MODE: true
# Currently is not possible to analyze Go in conjunction with other languages in macos
multi-language-repo_test-go-custom-queries:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v2
if: ${{ matrix.os == 'macos-latest' }}
with:
go-version: '^1.13.1'
- uses: actions/checkout@v2
- name: Move codeql-action
shell: bash
run: |
mkdir ../action
shopt -s dotglob
mv * ../action/
mv ../action/tests/multi-language-repo/* .
- uses: ./../action/init
with:
languages: go
config-file: ./.github/codeql/custom-queries.yml
- name: Build code
shell: bash
run: ./build.sh
- uses: ./../action/analyze
env:
TEST_MODE: true
multi-language-repo_rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Move codeql-action
shell: bash
run: |
mkdir ../action
shopt -s dotglob
mv * ../action/
mv ../action/tests/multi-language-repo/* .
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Install Code Scanning integration
run: bundle add code-scanning-rubocop --version 0.2.0 --skip-install
- name: Install dependencies
run: bundle install
- name: Rubocop run
run: |
bash -c "
bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
[[ $? -ne 2 ]]
"
- uses: ./../action/upload-sarif
with:
sarif_file: rubocop.sarif
env:
TEST_MODE: true

View file

@ -1,8 +1,16 @@
name: "Check generated JavaScript"
name: "Lint, Build & Test"
on: [pull_request]
on: [push, pull_request]
jobs:
tslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: tslint
run: npm run-script lint
check-js:
runs-on: ubuntu-latest
@ -25,3 +33,11 @@ jobs:
exit 1
fi
echo "Success: JavaScript files are up to date"
npm-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: npm run-script test
run: npm run-script test

View file

@ -1,12 +0,0 @@
name: "npm run-script test"
on: [push]
jobs:
npm-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: npm run-script test
run: npm run-script test

View file

@ -1,12 +0,0 @@
name: "TSLint"
on: [push]
jobs:
tslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: tslint
run: npm run-script lint

5
lib/upload-lib.js generated
View file

@ -58,6 +58,11 @@ exports.combineSarifFiles = combineSarifFiles;
// If the request fails then this will retry a small number of times.
async function uploadPayload(payload) {
core.info('Uploading results');
// If in test mode we don't want to upload the results
const testMode = process.env['TEST_MODE'] === 'true' || false;
if (testMode) {
return true;
}
const githubToken = core.getInput('token');
const ph = new auth.BearerCredentialHandler(githubToken);
const client = new http.HttpClient('Code Scanning : Upload SARIF', [ph]);

View file

@ -52,6 +52,12 @@ export function combineSarifFiles(sarifFiles: string[]): string {
async function uploadPayload(payload): Promise<boolean> {
core.info('Uploading results');
// If in test mode we don't want to upload the results
const testMode = process.env['TEST_MODE'] === 'true' || false;
if (testMode) {
return true;
}
const githubToken = core.getInput('token');
const ph: auth.BearerCredentialHandler = new auth.BearerCredentialHandler(githubToken);
const client = new http.HttpClient('Code Scanning : Upload SARIF', [ph]);

View file

@ -0,0 +1,29 @@
name: Use custom queries
disable-default-queries: true
queries:
# Query suites
- name: Select a query suite
uses: ./codeql-qlpacks/complex-python-qlpack/rootAndBar.qls
# QL pack subset
- name: Select a ql file
uses: ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
- name: Select a subfolder
uses: ./codeql-qlpacks/complex-javascript-qlpack/foo
- name: Select a folder with two subfolders
uses: ./codeql-qlpacks/complex-javascript-qlpack/foo2
# Inrepo QL pack
- name: Select an inrepo ql pack
uses: ./codeql-qlpacks/csharp-qlpack
- name: Java queries
uses: ./codeql-qlpacks/java-qlpack
# External QL packs
- name: Go queries
uses: Anthophila/go-querypack@master
- name: Cpp queries
uses: Anthophila/cpp-querypack@second-branch
- name: Javascript queries
uses: Anthophila/javascript-querypack/show_ifs2.ql@master
- name: Python queries
uses: Anthophila/python-querypack/show_ifs2.ql@second-branch

View file

@ -0,0 +1,2 @@
source "https://rubygems.org" do
end

View file

@ -0,0 +1,8 @@
class Main {
public static void main(String args[]) {
if (true) {
System.out.println("Hello, World!");
}
}
}

View file

@ -0,0 +1,8 @@
#!/bin/bash
gcc -o main main.c
dotnet build
javac Main.java

View file

@ -0,0 +1,11 @@
/**
* @name Foo Show Ifs
* @description Foo Show Ifs
* @kind problem
* @id complex-javascript-querypack/foo-show-ifs
*/
import javascript
from IfStmt i
select i, "foo if"

View file

@ -0,0 +1,11 @@
/**
* @name Bar Show Ifs
* @description Bar Show Ifs
* @kind problem
* @id complex-javascript-querypack/bar-ifs
*/
import javascript
from IfStmt i
select i, "bar if"

View file

@ -0,0 +1,11 @@
/**
* @name Barfoobar Show Ifs
* @description Barfoobar Show Ifs
* @kind problem
* @id complex-javascript-querypack/barfoobar-ifs
*/
import javascript
from IfStmt i
select i, "barfoobar if"

View file

@ -0,0 +1,11 @@
/**
* @name Foo2 Show Ifs
* @description Foo2 Show Ifs
* @kind problem
* @id complex-javascript-querypack/foo2-ifs
*/
import javascript
from IfStmt i
select i, "foo2 if"

View file

@ -0,0 +1,3 @@
name: complex-javascript-querypack
version: 0.0.1
libraryPathDependencies: codeql-javascript

View file

@ -0,0 +1,11 @@
/**
* @name Root Show Ifs
* @description Root Show Ifs
* @kind problem
* @id complex-javascript-querypack/root-show-ifs
*/
import javascript
from IfStmt i
select i, "root if"

View file

@ -0,0 +1,11 @@
/**
* @name Foo/Bar Show Ifs
* @description Foo/Bar Show Ifs
* @kind problem
* @id complex-python-querypack/foo/bar/show-ifs
*/
import python
from If i
select i, "foo/bar if"

View file

@ -0,0 +1,11 @@
/**
* @name Foo Show Ifs
* @description Foo Show Ifs
* @kind problem
* @id complex-python-querypack/foo/show-ifs
*/
import python
from If i
select i, "foo if"

View file

@ -0,0 +1,3 @@
name: inrepo-python-querypack
version: 0.0.1
libraryPathDependencies: codeql-python

View file

@ -0,0 +1,2 @@
- query: show_ifs.ql
- query: foo/bar/show_ifs.ql

View file

@ -0,0 +1,11 @@
/**
* @name Show Ifs
* @description Show Ifs
* @kind problem
* @id complex-python-querypack/show-ifs
*/
import python
from If i
select i, "hello if"

View file

@ -0,0 +1,3 @@
name: inrepo-cpp-querypack
version: 0.0.1
libraryPathDependencies: codeql-cpp

View file

@ -0,0 +1,11 @@
/**
* @name Show Cpp Ifs
* @description Show Cpp Ifs
* @kind problem
* @id inrepo-cpp-querypack/show-ifs
*/
import cpp
from IfStmt i
select i, "hello if"

View file

@ -0,0 +1,3 @@
name: inrepo-csharp-querypack
version: 0.0.1
libraryPathDependencies: codeql-csharp

View file

@ -0,0 +1,11 @@
/**
* @name Show Csharp Ifs
* @description Show Csharp Ifs
* @kind problem
* @id inrepo-csharp-querypack/show-ifs
*/
import csharp
from IfStmt i
select i, "hello if"

View file

@ -0,0 +1,3 @@
name: inrepo-go-querypack
version: 0.0.1
libraryPathDependencies: codeql-go

View file

@ -0,0 +1,11 @@
/**
* @name Show Go Ifs
* @description Show Go Ifs
* @kind problem
* @id inrepo-go-querypack/show-ifs
*/
import go
from IfStmt i
select i, "hello if"

View file

@ -0,0 +1,3 @@
name: inrepo-java-querypack
version: 0.0.1
libraryPathDependencies: codeql-java

View file

@ -0,0 +1,11 @@
/**
* @name Show Java Ifs
* @description Show Java Ifs
* @kind problem
* @id inrepo-java-querypack/show-ifs
*/
import java
from IfStmt i
select i, "hello if"

View file

@ -0,0 +1,3 @@
name: inrepo-javascript-querypack
version: 0.0.1
libraryPathDependencies: codeql-javascript

View file

@ -0,0 +1,11 @@
/**
* @name Show Javascript Ifs
* @description Show Javascript Ifs
* @kind problem
* @id inrepo-javascript-querypack/show-ifs
*/
import javascript
from IfStmt i
select i, "hello if"

View file

@ -0,0 +1,3 @@
name: inrepo-python-querypack
version: 0.0.1
libraryPathDependencies: codeql-python

View file

@ -0,0 +1,11 @@
/**
* @name Show Python Ifs
* @description Show Python Ifs
* @kind problem
* @id inrepo-python-querypack/show-ifs
*/
import python
from If i
select i, "hello if"

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>multi_language_test</RootNamespace>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,8 @@
#include "stdio.h"
int main(int argc, char **argv) {
if (1) {
printf("Hello, World!\n");
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace HelloWorldApp {
class Geeks {
static void Main(string[] args) {
if (true) {
Console.WriteLine("Hello World!");
}
}
}
}

View file

@ -0,0 +1,9 @@
package main
import "fmt"
func main() {
if true {
fmt.Println("hello world")
}
}

View file

@ -0,0 +1,3 @@
if (true) {
console.log("Hello, World!");
}

View file

@ -0,0 +1,9 @@
#!/usr/bin/python3
def main():
if True:
print("Hello, World!")
if __name__ == '__main__':
main()

View file

@ -0,0 +1,11 @@
#!/usr/bin/ruby
# frozen_string_literal: true
def main
v = ARGV[0]
puts 'with arg?' unless v.nil?
puts 'hello there'
end
main