Skip to content

Commit

Permalink
I have refactored our GitHub actions to allow us to trigger deployments.
Browse files Browse the repository at this point in the history
I have removed the existing scripts related to the build_test on AWS. I have also moved the unit-test and feature-test jobs into separate workflows so they can be reused in other workflows.

I have created the workflow which should (hopefully) then deploy the code to the correct environments, but this still needs to be tested and sorted.
  • Loading branch information
tim-s-ccs committed Sep 14, 2022
1 parent 2425d2b commit 6811e34
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 126 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/deploy_to_aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "Deploy latest code to AWS"

on:
push:
branches:
- develop
- master
- preview
- production

jobs:
determine-environment:
runs-on: ubuntu-latest
outputs:
env_name: ${{ steps.determine_environment.outputs.env_name }}
steps:
- name: Determine the environment to deploy to
id: determine_environment
run: |
echo "Running on branch ${{ github.ref }}"
if [ "${{ github.ref }}" = "refs/heads/master" ]; then
echo "::set-output name=env_name::CMPDEV"
elif [ "${{ github.ref }}" = "refs/heads/develop" ]; then
echo "::set-output name=env_name::Sandbox"
elif [ "${{ github.ref }}" = "refs/heads/preview" ]; then
echo "::set-output name=env_name::Preview"
elif [ "${{ github.ref }}" = "refs/heads/production" ]; then
echo "::set-output name=env_name::Production"
else
echo "::set-output name=env_name::FAIL"
fi
- name: Fail if not an environment
run: |
echo "ERROR: No environment found"
exit 1
if: steps.determine_environment.outputs.env_name == 'FAIL'

- name: Show where we are deploying to
run: echo "We will deploy to ${{ steps.determine_environment.outputs.env_name }}"

run-unit-tests:
needs:
- determine-environment
uses: ./.github/workflows/unit_tests.yaml

run-feature-tests:
needs:
- determine-environment
uses: ./.github/workflows/feature_tests.yaml
with:
run_all_feature_tests: true

deploy-to-application:
runs-on: ubuntu-latest
needs:
- determine-environment
- run-unit-tests
- run-feature-tests
environment:
name: ${{ needs.determine-environment.outputs.env_name }}
steps:
- name: Trigger AWS CodePipeline - main container
uses: tim-s-ccs/[email protected]
with:
aws-region: ${{ secrets.AWS_PIPELINE_REGION }}
aws-access-key: ${{ secrets.AWS_PIPELINE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_PIPELINE_SECRET_KEY }}
pipeline-name: ${{ secrets.AWS_PIPELINE_MAIN_NAME }}

deploy-to-sidekiq:
runs-on: ubuntu-latest
needs:
- determine-environment
- run-unit-tests
- run-feature-tests
environment:
name: ${{ needs.determine-environment.outputs.env_name }}
steps:
- name: Trigger AWS CodePipeline - sidekiq container
uses: tim-s-ccs/[email protected]
with:
aws-region: ${{ secrets.AWS_PIPELINE_REGION }}
aws-access-key: ${{ secrets.AWS_PIPELINE_ACCESS_KEY }}
aws-secret-key: ${{ secrets.AWS_PIPELINE_SECRET_KEY }}
pipeline-name: ${{ secrets.AWS_PIPELINE_SIDEKIQ_NAME }}
56 changes: 56 additions & 0 deletions .github/workflows/feature_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
workflow_call:
inputs:
run_all_feature_tests:
description: 'A trigger to run all the feature tests instead of a subset'
default: false
required: false
type: boolean

jobs:
feature-test:
runs-on: ubuntu-20.04

services:
postgres:
image: postgis/postgis:11-2.5
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password

env:
RAILS_ENV: test
DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test"
CUCUMBER_FORMAT: progress

steps:
- name: Setup Gecko driver
uses: browser-actions/setup-geckodriver@latest

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

- name: Install Ruby and gems
uses: ruby/[email protected]
with:
bundler-cache: true

- name: Set up database schema
run: bin/rails db:test:prepare

- name: Compile assets
run: bin/rails assets:precompile

- name: Seed DB with test data
run: bin/rails db:static

- name: Run feature tests
run: bin/rails cucumber:pipeline
if: ${{ !inputs.run_all_feature_tests }}

- name: Run all feature tests
run: bin/rails cucumber:ok
if: ${{ inputs.run_all_feature_tests }}
102 changes: 13 additions & 89 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
@@ -1,95 +1,19 @@
name: "Ruby on Rails CI"

on:
- push
- pull_request
push:
branches-ignore:
- develop
- master
- preview
- production
pull_request:

jobs:
unit-test:
runs-on: ubuntu-18.04
run-unit-tests:
uses: ./.github/workflows/unit_tests.yaml

services:
postgres:
image: postgis/postgis:11-2.5
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password

env:
RAILS_ENV: test
DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test"
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

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

- name: Install Ruby and gems
uses: ruby/[email protected]
with:
bundler-cache: true

- name: Set up database schema
run: bin/rails db:test:prepare

- name: Compile assets
run: bin/rails assets:precompile

- name: Run unit tests
run: bin/rake

- name: publish code coverage
uses: paambaati/[email protected]
with:
debug: true
if: github.event_name == 'pull_request'

feature-test:
runs-on: ubuntu-18.04

services:
postgres:
image: postgis/postgis:11-2.5
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password

env:
RAILS_ENV: test
DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test"
CUCUMBER_FORMAT: progress

steps:
- name: Setup Gecko driver
uses: browser-actions/setup-geckodriver@latest

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

- name: Install Ruby and gems
uses: ruby/[email protected]
with:
bundler-cache: true

- name: Set up database schema
run: bin/rails db:test:prepare

- name: Compile assets
run: bin/rails assets:precompile

- name: Seed DB with test data
run: bin/rails db:static

- name: Run feature tests
run: bin/rails cucumber:pipeline
if: github.event.pull_request.base.ref != 'preview' && github.event.pull_request.base.ref != 'production'

- name: Run all feature tests
run: bin/rails cucumber:ok
if: github.event.pull_request.base.ref == 'preview' || github.event.pull_request.base.ref == 'production'
run-feature-tests:
uses: ./.github/workflows/feature_tests.yaml
with:
run_all_feature_tests: ${{ github.event.pull_request.base.ref == 'preview' || github.event.pull_request.base.ref == 'production' }}
45 changes: 45 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
- workflow_call

jobs:
unit-test:
runs-on: ubuntu-20.04

services:
postgres:
image: postgis/postgis:11-2.5
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password

env:
RAILS_ENV: test
DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test"
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

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

- name: Install Ruby and gems
uses: ruby/[email protected]
with:
bundler-cache: true

- name: Set up database schema
run: bin/rails db:test:prepare

- name: Compile assets
run: bin/rails assets:precompile

- name: Run unit tests
run: bin/rake

- name: publish code coverage
uses: paambaati/[email protected]
with:
debug: true
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master'
29 changes: 0 additions & 29 deletions pipeline_pre_build_tests.sh

This file was deleted.

8 changes: 0 additions & 8 deletions pipeline_run_build_tests.sh

This file was deleted.

0 comments on commit 6811e34

Please sign in to comment.