Skip to content

Commit

Permalink
fix formatting error and add endforce_flow workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
setheliot committed Sep 11, 2024
1 parent b417b0e commit 5b7bdad
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

# This is where tests can be added for each commit
- name: Run tests
run: |
echo "Test placeholder"
########################
# Run unit tests
########################

# Init python, install dependencies, and test our app.
- name: Initialize Python 3.7
uses: actions/setup-python@v1
with:
python-version: ${{matrix.python-version}}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test app
run: |
pytest src/
# Different environments (stage, prod, etc) would also have some tests
# specific to that environment. Those should go in another workflow
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/enforce-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This GitHub action enforces that only merges from previous env will be accepted to next env
# for example: only merges from stage will be accepted into main (prod)

name: Enforce Flow

on:
push:
branches:
- main
- stage
pull_request:
branches:
- main
- stage

jobs:
enforce_flow:
name: Enforce Flow
runs-on: ubuntu-latest
steps:
# This is where we would add a check for merging into stage if we add an environment before stage
- name: No need to check if merging into stage
if: github.base_ref == 'stage'
run: exit 0

# If merging into main, ensure it is from stage
- name: Fail if PR is not from stage
if: github.base_ref == 'main' && github.head_ref != 'stage'
run: |
echo "Error: Pull request to main must come from the stage branch."
echo "This pull request is from ${{ github.head_ref }}"
exit 1
- name: Verify if tests passed on stage branch
run: |
echo "Checking if Tests passed on stage..."
if: ${{ github.event.pull_request.head.ref == 'stage' }}
continue-on-error: false
8 changes: 4 additions & 4 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
steps:
# Checkout the code.
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

########################
# Run unit tests
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

# Generate version label for the image
- name: Set Short SHA
Expand Down Expand Up @@ -157,6 +157,6 @@ jobs:

- name: Terraform Apply
run: |
terraform apply -auto-approve -input=false
-var="app_image=ghcr.io/setheliot/xyz-demo-app:${{env.SHA_SHORT}}"
terraform apply -auto-approve -input=false \
-var="app_image=ghcr.io/setheliot/xyz-demo-app:${{env.SHA_SHORT}}" \
-var-file=environment/${{ github.ref_name }}.tfvars

0 comments on commit 5b7bdad

Please sign in to comment.