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 Oct 12, 2022
1 parent 4425b40 commit 7bf8f47
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 130 deletions.
14 changes: 11 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ updates:
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: weekly
- package-ecosystem: docker
interval: "weekly"
day: "sunday"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: weekly
interval: "weekly"
day: "sunday"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
93 changes: 93 additions & 0 deletions .github/workflows/deploy_to_aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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 "ENV_NAME=$(
case ${{ github.ref }} in
"refs/heads/feature/FMFR-1283-update-deployment-settings")
echo "CMPDEV"
;;
"refs/heads/develop")
echo "Sandbox"
;;
"refs/heads/preview")
echo "Preview"
;;
"refs/heads/production")
echo "Production"
;;
*)
echo "FAIL"
;;
esac
)" >> $GITHUB_OUTPUT
- 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 }}
108 changes: 18 additions & 90 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
@@ -1,95 +1,23 @@
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

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-unit-tests:
uses: ./.github/workflows/unit_tests.yaml
with:
publish_test_report: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master' }}
secrets:
cc_test_reporter_id: ${{ secrets.CC_TEST_REPORTER_ID }}

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' }}
55 changes: 55 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
on:
workflow_call:
inputs:
publish_test_report:
description: 'A trigger to publish the test report'
default: false
required: false
type: boolean
secrets:
cc_test_reporter_id:
description: 'The code climate test report ID'
required: false

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: ${{ inputs.publish_test_report }}
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 7bf8f47

Please sign in to comment.