From 37b1f3663b7988e1d8ed0a06f54a4dc20c26187d Mon Sep 17 00:00:00 2001 From: Tim Warner Date: Tue, 9 Jan 2024 07:02:39 -0600 Subject: [PATCH] Add lesson 5 workflows --- .github/workflows/environment-protections.yml | 48 +++++++++++++++++++ .../workflows/install-cache-dependencies.yml | 33 +++++++++++++ .github/workflows/job-config-matrix.yml | 37 ++++++++++++++ .github/workflows/workflow-approval.yml | 31 ++++++++++++ .gitignore | 1 + .../interact-with-docker-image.sh | 0 .../codeql-app-scan.yml | 0 .../create-artifact.yml | 0 .../create-release.yml | 0 .../docker-publish.yml | 0 .../workflows => workflow_dev}/python_app.yml | 0 .../python_app_2.yml | 0 12 files changed, 150 insertions(+) create mode 100644 .github/workflows/environment-protections.yml create mode 100644 .github/workflows/install-cache-dependencies.yml create mode 100644 .github/workflows/job-config-matrix.yml create mode 100644 .github/workflows/workflow-approval.yml rename {lesson_04 => misc}/interact-with-docker-image.sh (100%) rename {.github/workflows => workflow_dev}/codeql-app-scan.yml (100%) rename {.github/workflows => workflow_dev}/create-artifact.yml (100%) rename {.github/workflows => workflow_dev}/create-release.yml (100%) rename {.github/workflows => workflow_dev}/docker-publish.yml (100%) rename {.github/workflows => workflow_dev}/python_app.yml (100%) rename {.github/workflows => workflow_dev}/python_app_2.yml (100%) diff --git a/.github/workflows/environment-protections.yml b/.github/workflows/environment-protections.yml new file mode 100644 index 0000000..91fd979 --- /dev/null +++ b/.github/workflows/environment-protections.yml @@ -0,0 +1,48 @@ +name: Multi-Environment Deployment + +on: + push: + branches: + - alpha + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + - name: Install dependencies + run: pip install -r requirements.txt + - name: Run tests + run: python -m unittest + + deploy-dev: + needs: build + runs-on: ubuntu-latest + environment: dev + steps: + - uses: actions/checkout@v2 + - name: Deploy to Development + run: echo "Deploying to Development environment..." + + deploy-test: + needs: build + runs-on: ubuntu-latest + environment: test + steps: + - uses: actions/checkout@v2 + - name: Deploy to Test + run: echo "Deploying to Test environment..." + + deploy-prod: + needs: build + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + environment: prod + steps: + - uses: actions/checkout@v2 + - name: Deploy to Production + run: echo "Deploying to Production environment..." diff --git a/.github/workflows/install-cache-dependencies.yml b/.github/workflows/install-cache-dependencies.yml new file mode 100644 index 0000000..743fe10 --- /dev/null +++ b/.github/workflows/install-cache-dependencies.yml @@ -0,0 +1,33 @@ +name: Install and cache dependencies + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Cache Python dependencies + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-python-${{ hashFiles('**/src/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-python- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r src/requirements.txt + # Add additional steps for linting, testing, etc. diff --git a/.github/workflows/job-config-matrix.yml b/.github/workflows/job-config-matrix.yml new file mode 100644 index 0000000..e9ebaf3 --- /dev/null +++ b/.github/workflows/job-config-matrix.yml @@ -0,0 +1,37 @@ +name: Python Matrix Testing + +on: + push: + branches: [ alpha ] + pull_request: + branches: [ alpha ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7, 3.8, 3.9, 3.10] + framework: ['flask', 'django'] + include: + - framework: 'flask' + additional-package: 'Flask-Testing' + - framework: 'django' + additional-package: 'Django-Testing' + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install ${{ matrix.additional-package }} + - name: Run tests + run: | + if [ ${{ matrix.framework }} = 'flask' ]; then + # run Flask tests + elif [ ${{ matrix.framework }} = 'django' ]; then + # run Django tests + fi diff --git a/.github/workflows/workflow-approval.yml b/.github/workflows/workflow-approval.yml new file mode 100644 index 0000000..b7d82d7 --- /dev/null +++ b/.github/workflows/workflow-approval.yml @@ -0,0 +1,31 @@ +name: Deployment with Approval Gates + +on: + push: + branches: + - alpha + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + - name: Install dependencies + run: pip install -r requirements.txt + - name: Run tests + run: python -m unittest + + deploy-to-prod: + needs: build-and-test + runs-on: ubuntu-latest + environment: + name: production + steps: + - uses: actions/checkout@v2 + - name: Deploy to Production + run: echo "Deploying to production environment..." + # Replace with actual deployment commands diff --git a/.gitignore b/.gitignore index ec0485a..b71cb32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ +__pycache__ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/lesson_04/interact-with-docker-image.sh b/misc/interact-with-docker-image.sh similarity index 100% rename from lesson_04/interact-with-docker-image.sh rename to misc/interact-with-docker-image.sh diff --git a/.github/workflows/codeql-app-scan.yml b/workflow_dev/codeql-app-scan.yml similarity index 100% rename from .github/workflows/codeql-app-scan.yml rename to workflow_dev/codeql-app-scan.yml diff --git a/.github/workflows/create-artifact.yml b/workflow_dev/create-artifact.yml similarity index 100% rename from .github/workflows/create-artifact.yml rename to workflow_dev/create-artifact.yml diff --git a/.github/workflows/create-release.yml b/workflow_dev/create-release.yml similarity index 100% rename from .github/workflows/create-release.yml rename to workflow_dev/create-release.yml diff --git a/.github/workflows/docker-publish.yml b/workflow_dev/docker-publish.yml similarity index 100% rename from .github/workflows/docker-publish.yml rename to workflow_dev/docker-publish.yml diff --git a/.github/workflows/python_app.yml b/workflow_dev/python_app.yml similarity index 100% rename from .github/workflows/python_app.yml rename to workflow_dev/python_app.yml diff --git a/.github/workflows/python_app_2.yml b/workflow_dev/python_app_2.yml similarity index 100% rename from .github/workflows/python_app_2.yml rename to workflow_dev/python_app_2.yml