diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..3b24ee7 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,25 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + groups: + python-packages: + patterns: + - "*" + + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + groups: + action-packages: + patterns: + - "*" diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml new file mode 100644 index 0000000..8235231 --- /dev/null +++ b/.github/workflows/build-and-push.yml @@ -0,0 +1,56 @@ +# TODO + +#name: Build and Push Docker Images +# +#on: +# push: +# branches: +# - main +# +#env: +# REGISTRY: ghcr.io +# IMAGE_NAME: ${{ github.repository_owner }} +# +#jobs: +# build-and-push: +# runs-on: ubuntu-latest +# permissions: +# contents: read +# packages: write +# +# steps: +# - name: Check out code +# uses: actions/checkout@v4 +# +# - name: Log in to the Container registry +# uses: docker/login-action@v3 +# with: +# registry: ${{ env.REGISTRY }} +# username: ${{ github.actor }} +# password: ${{ secrets.WRITE_PACKAGE_TOKEN }} +# +# - name: Build and push fia-api Docker image +# id: docker_build +# uses: docker/build-push-action@v5 +# with: +# file: ./container/fia_api.D +# push: true +# tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/fia-api +# +# - name: Checkout the Gitops repository +# uses: actions/checkout@v4 +# with: +# repository: fiaisis/gitops +# token: ${{ secrets.GITOPS_STAGING_EDIT_TOKEN }} +# +# - name: Edit the YAML fia-api file for staging +# uses: mikefarah/yq@v4.43.1 +# with: +# cmd: yq e -i '.spec.template.spec.containers[] |= select(.name == "fia-api").image = "ghcr.io/fiaisis/fia-api@${{ steps.docker_build.outputs.digest }}"' './components/fia-api/overlays/staging/fia-api.yml' +# +# - name: Commit and push changes +# run: | +# git config --local user.email "action@github.com" +# git config --local user.name "GitHub Action" +# git commit -am "Update fia-api to use ${{ steps.docker_build.outputs.digest }}" +# git push diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..eec6234 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,78 @@ +# 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" + +on: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + schedule: + - cron: "0 0 * * 1" + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["python"] + # CodeQL supports [ $supported-codeql-languages ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9 + with: + languages: ${{ matrix.language }} + # 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. + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9 + + # ℹī¸ 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@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000..5751b89 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,27 @@ +# Dependency Review Action +# +# This Action will scan dependency manifest files that change as part of a Pull Request, +# surfacing known-vulnerable versions of the packages declared or updated in the PR. +# Once installed, if the workflow run is marked as required, +# PRs introducing known-vulnerable packages will be blocked from merging. +# +# Source repository: https://github.com/actions/dependency-review-action +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + + - name: 'Checkout Repository' + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: 'Dependency Review' + uses: actions/dependency-review-action@5bbc3ba658137598168acb2ab73b21c432dd411b # v4.2.5 diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 0000000..46065bf --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,44 @@ +--- +on: + push: + branches-ignore: + - main +permissions: + contents: write + +jobs: + black: + permissions: + contents: write # for Git to git push + runs-on: ubuntu-latest + steps: + - name: Checkout project + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3.5.0 + + - name: Set up Python + uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v4.5.0 + with: + python-version: '3.12' + + - name: Set up cache for Python dependencies. + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install .[formatting] + - name: Run black + run: | + black --line-length 120 . + - name: Commit changes + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "black auto commit" || true + git push \ No newline at end of file diff --git a/.github/workflows/image-scan.yml b/.github/workflows/image-scan.yml new file mode 100644 index 0000000..9caf5d2 --- /dev/null +++ b/.github/workflows/image-scan.yml @@ -0,0 +1,43 @@ +# TODO + +#name: Image Scan +#on: +# schedule: +# - cron: "49 8 * * *" +# +#env: +# REGISTRY: ghcr.io +# IMAGE_NAME: ${{ github.repository_owner }} +# +#jobs: +# build: +# name: Trivy image scan +# runs-on: ubuntu-20.04 +# steps: +# - name: Checkout code +# uses: actions/checkout@v4 +# +# - name: Build Docker image +# uses: docker/build-push-action@v5 +# with: +# file: ./container/fia_api.D +# tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/fia_api:${{ github.sha }} +# +# - name: Run Trivy vulnerability scanner +# uses: aquasecurity/trivy-action@master +# with: +# image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/fia_api:${{ github.sha }} +# format: sarif +# output: trivy-results.sarif +# ignore-unfixed: true +# exit-code: 1 +# +# - name: Print results +# run: cat trivy-results.sarif +# if: failure() +# +# - name: Upload Trivy scan results to GitHub Security tab +# uses: github/codeql-action/upload-sarif@v3 +# if: failure() +# with: +# sarif_file: trivy-results.sarif diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..0e2a2b6 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,35 @@ +--- +on: push + +permissions: + contents: read + +jobs: + code-inspection: + runs-on: ubuntu-latest + steps: + - name: Checkout project + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3.5.0 + + - name: Set up python + uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v4.5.0 + with: + python-version: '3.12' + + - name: Set up cache for Python dependencies + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install .[code-inspection] + - name: Run pylint + run: pylint src app.py + + - name: Run MyPy + run: mypy --strict . \ No newline at end of file diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml new file mode 100644 index 0000000..8d55e00 --- /dev/null +++ b/.github/workflows/scorecards.yml @@ -0,0 +1,76 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '20 7 * * 2' + push: + branches: ["main"] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + contents: read + actions: read + + steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + + - name: "Checkout code" + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository, or + # - you are installing Scorecards on a *private* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + # For private repositories: + # - `publish_results` will always be set to `false`, regardless + # of the value entered here. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9 + with: + sarif_file: results.sarif diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d7bbfd5 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,133 @@ +# TODO + +#--- +#on: push +# +#permissions: +# contents: read +# +#jobs: +# pytest: +# runs-on: ubuntu-latest +# steps: +# - name: Checkout project +# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3.5.0 +# +# - name: Set up python +# uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v4.5.0 +# with: +# python-version: '3.12' +# +# - name: Set up cache for Python dependencies +# uses: actions/cache@v4 +# with: +# path: ~/.cache/pip +# key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} +# restore-keys: | +# ${{ runner.os }}-pip- +# +# - name: Install dependencies. +# run: | +# python -m pip install --upgrade pip +# python -m pip install .[test] +# - name: Run pytest +# run: pytest . --random-order --random-order-bucket=global --ignore=test/e2e --ignore=test/core/test_repositories_integration.py --cov --cov-report=xml +# +# - name: Upload coverage +# uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0 +# with: +# token: ${{ secrets.CODECOV_TOKEN }} +# +# +# integration: +# runs-on: ubuntu-latest +# +# services: +# postgres: +# image: postgres:latest +# env: +# POSTGRES_USER: postgres +# POSTGRES_PASSWORD: password +# POSTGRES_DB: fia +# ports: +# - 5432:5432 +# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 +# +# steps: +# - name: Check out repository +# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 +# +# - name: Set up Python +# uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 +# with: +# python-version: '3.12' +# +# - name: Set up cache for Python dependencies +# uses: actions/cache@v4 +# with: +# path: ~/.cache/pip +# key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} +# restore-keys: | +# ${{ runner.os }}-pip- +# +# - name: Install dependencies +# run: | +# python -m pip install --upgrade pip +# pip install .[test] +# +# - name: Run tests +# env: +# DATABASE_URL: postgresql://postgres:password@localhost:5432/test_db +# run: | +# pytest test/core/test_repositories_integration.py --random-order --random-order-bucket=global --cov --cov-report=xml +# +# - name: Upload coverage +# uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0 +# with: +# token: ${{ secrets.CODECOV_TOKEN }} +# e2e: +# runs-on: ubuntu-latest +# +# services: +# postgres: +# image: postgres:14.7 +# env: +# POSTGRES_USER: postgres +# POSTGRES_PASSWORD: password +# POSTGRES_DB: fia +# ports: +# - 5432:5432 +# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 +# +# steps: +# - name: Check out repository +# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 +# +# - name: Set up Python +# uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 +# with: +# python-version: '3.12' +# +# - name: Set up cache for Python dependencies +# uses: actions/cache@v4 +# with: +# path: ~/.cache/pip +# key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} +# restore-keys: | +# ${{ runner.os }}-pip- +# +# - name: Install dependencies +# run: | +# python -m pip install --upgrade pip +# pip install .[test] +# +# - name: Run tests +# env: +# DATABASE_URL: postgresql://postgres:password@localhost:5432/test_db +# run: | +# pytest test/e2e --random-order --random-order-bucket=global --cov --cov-report=xml +# +# - name: Upload coverage +# uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0 +# with: +# token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file