From feec6cc4a04059b8d8614cd658bad09e03393067 Mon Sep 17 00:00:00 2001 From: "Daniel T. Soukup, PhD" <47944937+danieltsoukup@users.noreply.github.com> Date: Fri, 12 Jan 2024 06:38:18 -0500 Subject: [PATCH 1/7] Create python-app.yml Add testing and linting for main branch push and pull requests. --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..23115d1 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# 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: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +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 + run: | + pytest From 84fc01bbddfc0a6f5ce830d2074f6bd06e688f33 Mon Sep 17 00:00:00 2001 From: "Daniel T. Soukup, PhD" <47944937+danieltsoukup@users.noreply.github.com> Date: Fri, 12 Jan 2024 06:54:49 -0500 Subject: [PATCH 2/7] Update python-app.yml --- .github/workflows/python-app.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 23115d1..435f00d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -35,5 +35,8 @@ jobs: # 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 From 7c7ace6af0f478bd3d93887c71f141d7c44d7d6d Mon Sep 17 00:00:00 2001 From: "Daniel T. Soukup, PhD" <47944937+danieltsoukup@users.noreply.github.com> Date: Sat, 13 Jan 2024 09:49:59 -0500 Subject: [PATCH 3/7] Update python-app.yml add development testing --- .github/workflows/python-app.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 435f00d..d8c7c90 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,13 +1,13 @@ # 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: Python application +name: Pytest and Linting on: push: - branches: [ "main" ] + branches: [ "main", "development" ] pull_request: - branches: [ "main" ] + branches: [ "main", "development" ] permissions: contents: read From e2f71bcb47d8e0911196dfc34e7e9112dfbfe88b Mon Sep 17 00:00:00 2001 From: "Daniel T. Soukup, PhD" <47944937+danieltsoukup@users.noreply.github.com> Date: Sat, 13 Jan 2024 16:06:56 -0500 Subject: [PATCH 4/7] Create codeql.yml --- .github/workflows/codeql.yml | 84 ++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..7ce384b --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,84 @@ +# 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", "development" ] + pull_request: + branches: [ "main", "development" ] + 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}}" From 36d816017ad3005bea305086bd7f6130e6dee6bd Mon Sep 17 00:00:00 2001 From: "Daniel T. Soukup, PhD" <47944937+danieltsoukup@users.noreply.github.com> Date: Sat, 13 Jan 2024 16:29:04 -0500 Subject: [PATCH 5/7] Update and rename python-app.yml to test.yml --- .github/workflows/{python-app.yml => test.yml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{python-app.yml => test.yml} (93%) diff --git a/.github/workflows/python-app.yml b/.github/workflows/test.yml similarity index 93% rename from .github/workflows/python-app.yml rename to .github/workflows/test.yml index d8c7c90..8d5a370 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/test.yml @@ -5,9 +5,9 @@ name: Pytest and Linting on: push: - branches: [ "main", "development" ] + branches: [ "development" ] pull_request: - branches: [ "main", "development" ] + branches: [ "development" ] permissions: contents: read From c180612b848734a36762dcb35f61a734d88f872f Mon Sep 17 00:00:00 2001 From: Daniel Soukup Date: Sat, 13 Jan 2024 17:53:03 -0500 Subject: [PATCH 6/7] refactor actions and add build, deploy workdlow --- .github/workflows/build-deploy.yml | 26 +++++++++++++++++++++++ .github/workflows/codeql.yml | 6 +----- .github/workflows/dev-workflow.yml | 18 ++++++++++++++++ .github/workflows/heroku-deploy.yml | 32 +++++++++++++++++++++++++++++ .github/workflows/main-workflow.yml | 23 +++++++++++++++++++++ .github/workflows/test.yml | 8 ++------ 6 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build-deploy.yml create mode 100644 .github/workflows/dev-workflow.yml create mode 100644 .github/workflows/heroku-deploy.yml create mode 100644 .github/workflows/main-workflow.yml 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 index 7ce384b..88e8b14 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -11,11 +11,7 @@ # name: "CodeQL" -on: - push: - branches: [ "main", "development" ] - pull_request: - branches: [ "main", "development" ] +on: [ workflow_call ] schedule: - cron: '20 3 * * 6' 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 index 8d5a370..2ebd737 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,13 +1,9 @@ # 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: Pytest and Linting +name: "Test-and-Lint" -on: - push: - branches: [ "development" ] - pull_request: - branches: [ "development" ] +on: [ workflow_call ] permissions: contents: read From d133a64a471e941ee745158d008ef05a0e54eb34 Mon Sep 17 00:00:00 2001 From: Daniel Soukup Date: Sat, 13 Jan 2024 17:55:41 -0500 Subject: [PATCH 7/7] correct codeql action --- .github/workflows/codeql.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 88e8b14..9154fc5 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -11,7 +11,8 @@ # name: "CodeQL" -on: [ workflow_call ] +on: + workflow_call: schedule: - cron: '20 3 * * 6'