diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml new file mode 100644 index 0000000..ee0f6c8 --- /dev/null +++ b/.github/workflows/build-deploy.yml @@ -0,0 +1,26 @@ +# Deployment workflow to Heroku in a Docker container + +name: "Build-and-Deploy" + +on: [ workflow_call ] + +jobs: + build-and-deploy: + name: docker-build-deploy + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + + - name: Add API key from secret + run: | + echo "API_TOKEN=${{ secrets.TOKEN }}" + + + - name: Docker build + run: | + make prod_build + + - name: Deploy to Heroku + uses: ./.github/workflows/heroku-deploy.yml + diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..9154fc5 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,81 @@ +# 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: + workflow_call: + schedule: + - cron: '20 3 * * 6' + +jobs: + analyze: + name: Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + # required for all workflows + security-events: write + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] + # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use only 'javascript-typescript' 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 }} + # 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}}" diff --git a/.github/workflows/dev-workflow.yml b/.github/workflows/dev-workflow.yml new file mode 100644 index 0000000..2dfd2eb --- /dev/null +++ b/.github/workflows/dev-workflow.yml @@ -0,0 +1,18 @@ +# Development Checks - Test and Security Analysis + +name: "Dev Workflow" + +on: + push: + branches: [ "development" ] + pull_request: + branches: [ "development" ] + +jobs: + analyze: + name: codeql + uses: ./.github/workflows/codeql.yml + + tests: + name: tests + uses: ./.github/workflows/test.yml \ No newline at end of file diff --git a/.github/workflows/heroku-deploy.yml b/.github/workflows/heroku-deploy.yml new file mode 100644 index 0000000..34659fc --- /dev/null +++ b/.github/workflows/heroku-deploy.yml @@ -0,0 +1,32 @@ +# Heroku login and deploy workflow +# Requires +# - GitHub secrets with Heroku credentials +# - Access to the makefile + +name: Heroku-Login-Deploy + +on: [ workflow_call ] + +jobs: + login-deploy: + name: login-and-deploy + runs-on: ubuntu-latest + steps: + - name: login + run: | + cat < ~/.netrc +machine api.heroku.com + login ${{ secrets.HEROKU_EMAIL }} + password ${ secrets.HEROKU_API_KEY } +machine git.heroku.com + login ${{ secrets.HEROKU_EMAIL }} + password ${{ secrets.HEROKU_API_KEY }} +EOF + + - name: heroku-push + run: | + make heroku_push + + - name: heroku-release + run: | + make heroku_release \ No newline at end of file diff --git a/.github/workflows/main-workflow.yml b/.github/workflows/main-workflow.yml new file mode 100644 index 0000000..63a2812 --- /dev/null +++ b/.github/workflows/main-workflow.yml @@ -0,0 +1,23 @@ +# This CI/CD workflow will test, build a container and deploy the app to Heroku. + +name: "CI/CD Workflow" + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + codeql: + name: codeql + uses: ./.github/workflows/codeql.yml + + tests: + name: tests + uses: ./.github/workflows/test.yml + + deploy: + name: build and deploy + needs: [ tests, codeql ] + uses: ./.github/workflows/build-deploy.yml \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2ebd737 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,38 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: "Test-and-Lint" + +on: [ workflow_call ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + shell: bash + env: + TOKEN: ${{ secrets.TOKEN }} + run: | + pytest