Skip to content

Commit

Permalink
Workflow integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
aweiland committed May 16, 2024
1 parent 9549c2a commit 8f46383
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 46 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/branch-delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ env:
AWS_REGION: us-east-1

jobs:
set-env-name:
uses: .github/workflows/env-name.yaml
destroy-preview-env:
name: Destroy Preview Env
if: github.event.ref_type == 'branch'
needs: [set-env-name]
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
env:
ENV_NAME: ${{ needs.set-env-name.outputs.env-name }}
ENV_SNAKE_NAME: ${{ needs.set-env-name.outputs.env-snake-name }}
steps:
- name: Set env name
run: |
echo "ENV_NAME=$(echo '${{ github.event.ref }}' | sed -E 's/([0-9]+)\/merge/pr\-\1/' | sed 's/\//\-/')" >> $GITHUB_ENV
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
38 changes: 31 additions & 7 deletions .github/workflows/create_db.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
name: Create-RDS-Database

on:
workflow_run:
workflows: ["Name-of-Your-Triggering-Workflow"]
types:
- completed
# TODO Delete this after testing
workflow_dispatch:
inputs:
db-name:
required: true
type: string
description: Database name to create
workflow_call:
inputs:
db-name:
required: true
type: string
description: Database name to create
# workflow_run:
# workflows: ["Name-of-Your-Triggering-Workflow"]
# types:
# - completed

jobs:
create_database:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux, cmiml]

steps:
- name: Checkout repository
Expand All @@ -23,8 +36,19 @@ jobs:
sudo apt-get install -y postgresql-client-16
- name: Create Database
run: |
PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.USERNAME }}" -d "${{ secrets.DATABASE_NAME }}" -c "CREATE DATABASE <DATABASE_NAME>;"
run: >-
PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}"
psql -tc "SELECT 1 FROM pg_database WHERE datname = '${{ inputs.db-name }}'" | grep -q 1 ||
PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}"
psql -U postgres -c "CREATE DATABASE ${{ inputs.db-name }}"
- name: Grant privileges
run: >-
PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}"
psql -U postgres -c "grant all privileges on database ${{ inputs.db-name }} to ${{ secrets.DB_BACKEND_USERNAME }};"
# - name: Create Database
# run: |
# PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.USERNAME }}" -d "${{ inputs.db-name }}" -c "CREATE DATABASE <DATABASE_NAME>;"

on-failure:
runs-on: ubuntu-latest
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ env:
AWS_REGION: us-east-1

jobs:
set-env-name:
uses: .github/workflows/env-name.yaml
destroy-preview-env:
name: Destroy Preview Env
needs: [set-env-name]
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
env:
ENV_NAME: ${{ needs.set-env-name.outputs.env-name }}
ENV_SNAKE_NAME: ${{ needs.set-env-name.outputs.env-snake-name }}
steps:
- name: Set env name
run: |
echo "ENV_NAME=$(echo '${{ github.ref_name }}' | sed -E 's/([0-9]+)\/merge/pr\-\1/' | sed 's/\//\-/')" >> $GITHUB_ENV
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
31 changes: 11 additions & 20 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ env:
jobs:
set-env-name:
uses: .github/workflows/env-name.yaml
# name: Set copilot environment name
# runs-on: ubuntu-latest
# steps:
# - name: Create env name
# id: env-name
# run: |
# echo "ENV_NAME=$(echo '${{ github.ref_name }}' | sed -E 's/([0-9]+)\/merge/pr\-\1/' | sed 's/\//\-/g')" >> $GITHUB_OUTPUTS
# - name: Snake case env name
# id: env-snake-name
# run: |
# echo "ENV_NAME_SNAKE=$(echo ${{ env.ENV_NAME }} | sed 's/\-/\_/g')" >> $GITHUB_OUTPUTS
# outputs:
# env-name: steps.env-name.outputs.ENV_NAME
# env-snake-name: steps.env-snake-name.outputs.ENV_NAME_SNAKE
create-preview-env:
name: Create Preview Env
needs: [set-env-name]
Expand Down Expand Up @@ -89,10 +75,20 @@ jobs:
outputs:
service-url: ${{ steps.service-url.outputs.SERVICE_URL }}

run-unit-tests:
needs: [create-preview-env]
uses: .github/workflows/tests.yaml

create-database:
needs: [set-env-name, create-preview-env]
uses: .github/workflows/create_db.yaml
with:
db-name: "mindlogger_backend_${{ needs.set-env-name.outputs.env-snake-name }}"

run-int-tests:
name: Run TAF Test Suite
needs: [create-preview-env, run-unit-tests]
if: ${{ always() && (needs.run-unit-tests.result == 'success') }}
runs-on: ubuntu-latest

permissions:
Expand Down Expand Up @@ -120,12 +116,7 @@ jobs:
- name: Setup Environment
run: |
sed -i 's/API_DOMAIN.*//' .env ;
# echo 'API_DOMAIN=https://api-dev.cmiml.net/' >> .env
echo 'API_DOMAIN=${{ needs.create-preview-env.outputs.service-url }}' >> .env
- name: Validate env
run: |
cat .env
- name: Get Secrets by Name and by ARN
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
Expand All @@ -150,7 +141,7 @@ jobs:
uses: thollander/actions-comment-pull-request@v2
with:
message: |
:x: TAF tests failed
:x: Integration tests failed
comment_tag: taf-results

- name: Collect artifacts
Expand Down
27 changes: 15 additions & 12 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
name: Automated tests

on:
pull_request:
types:
- opened
- reopened
- synchronize
push:
branches:
- "feature/**"
workflow_call:

# pull_request:
# types:
# - opened
# - reopened
# - synchronize
# push:
# branches:
# - "feature/**"

# Only run the latest. Cancel old runs in progress.
concurrency:
cancel-in-progress: true
group: "preview-env-manage-${{ github.ref_name }}"

jobs:
tests:
Expand Down Expand Up @@ -44,6 +42,11 @@ jobs:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }}
SLACK_TITLE: Run Unit Tests
SLACK_MESSAGE: 'Error when executing Unit tests!'
- name: Fail if tests failed
uses: actions/github-script@v3
with:
script: |
core.setFailed('Unit tests failed')
on-success:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion compose/fastapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ FROM base as fargate

USER root
RUN chmod 777 /tmp && mkdir -p /app/uploads && chown -R code:code /app
USER code
#USER code

RUN touch /app/uploads/.test
RUN touch /tmp/.test
Expand Down

0 comments on commit 8f46383

Please sign in to comment.