Skip to content

Commit

Permalink
Separate codql.yml and create new issues workflows (hackforla#6692)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaylem authored May 6, 2024
1 parent 5394708 commit 4abfd4e
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 107 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/codeql-create-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This workflow generates new issues for CodeQL alerts if they do not exist
# It must be manually triggered
name: "CodeQL Create Issues"

on:
workflow_dispatch:

jobs:
codql-scan-job:
uses: ./.github/workflows/codeql-scan-job.yml

codeql-create-issues-job:
needs: codql-scan-job
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Fetch Alerts
- name: Fetch Alerts
id: fetch-alerts
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('./github-actions/trigger-issue/create-codeql-issues/fetch-alerts.js');
const fetchAlerts = script({ g: github, c: context });
return fetchAlerts
# Check Existing Issues
- name: Check Existing Issues
id: check-existing-issues
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('./github-actions/trigger-issue/create-codeql-issues/check-existing-issues.js');
const alerts = ${{ steps.fetch-alerts.outputs.result }};
const checkExistingIssues = script({ g: github, c: context, alerts});
return checkExistingIssues
# Create New Issues
- name: Create New Issues
id: create-new-issues
uses: actions/github-script@v7
with:
github-token: ${{ secrets.HACKFORLA_ADMIN_TOKEN }}
script: |
const script = require('./github-actions/trigger-issue/create-codeql-issues/create-new-issues.js');
const alertIds = ${{ steps.check-existing-issues.outputs.result }};
const newIssues = script({ g: github, c: context, alertIds});
77 changes: 77 additions & 0 deletions .github/workflows/codeql-scan-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

# This workflow called by codeql.yml and codeql-create-issues.yml
# It is a reusable workflow
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Scan Job"
# workflow_call enables this workflow to be called from other workflows
on:
workflow_call:

jobs:
analyze:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-and-quality
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"


111 changes: 5 additions & 106 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
# This is the main codeql.yml file which scans for CodeQL alerts.
# Most of the code is in .github/workflows/codeql-scan-job.yml
name: "CodeQL Scan"

on:
push:
Expand All @@ -22,97 +13,5 @@ on:
workflow_dispatch:

jobs:
analyze:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write
issues: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-and-quality
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"

# Fetch Alerts
- name: Fetch Alerts
id: fetch-alerts
if: github.event_name != 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('./github-actions/trigger-issue/create-codeql-issues/fetch-alerts.js');
const fetchAlerts = script({ g: github, c: context });
return fetchAlerts
# Check Existing Issues
- name: Check Existing Issues
id: check-existing-issues
if: github.event_name != 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('./github-actions/trigger-issue/create-codeql-issues/check-existing-issues.js');
const alerts = ${{ steps.fetch-alerts.outputs.result }};
const checkExistingIssues = script({ g: github, c: context, alerts});
return checkExistingIssues
# Create New Issues
- name: Create New Issues
id: create-new-issues
if: github.event_name != 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.HACKFORLA_ADMIN_TOKEN }}
script: |
const script = require('./github-actions/trigger-issue/create-codeql-issues/create-new-issues.js');
const alertIds = ${{ steps.check-existing-issues.outputs.result }};
const newIssues = script({ g: github, c: context, alertIds});
codeql-scan-job:
uses: ./.github/workflows/codeql-scan-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
We need to resolve the new alert [(${alertId})](https://github.com/hackforla/website/security/code-scanning/${alertId}) and either recommend dismissal of the alert or update the code files to resolve the alert.

### Action Items
- [ ] The following action item serves to "link" this issue as the "tracking issue" for the CodeQL alert and to provide more details regarding the alert: https://github.com/hackforla/website/security/code-scanning/${alertId}
- [ ] The following action item serves to "link" this issue as the "tracking issue" for the CodeQL alert and to provide more details regarding the alert:
- [ ] https://github.com/hackforla/website/security/code-scanning/${alertId}
- [ ] In a comment in this issue, add your analysis and recommendations. The recommendation can be one of the following: `dismiss as test`, `dismiss as false positive`, `dismiss as won't fix`, or `update code`. An example of a `false positive` is a report of a JavaScript syntax error that is caused by markdown or liquid symbols such as `---` or `{%`
- [ ] **If the recommendation is to dismiss the alert:**
- [ ] Apply the label `ready for dev lead`
Expand Down

0 comments on commit 4abfd4e

Please sign in to comment.