Skip to content

Commit

Permalink
Merge pull request #576 from Crown-Commercial-Service/deploy-from-github
Browse files Browse the repository at this point in the history
Add the ability to deploy to GPaaS via GitHub actions
  • Loading branch information
tim-s-ccs authored Nov 8, 2023
2 parents 9d6dd4b + cacd0c8 commit af19068
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 59 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/deploy_to_gpaas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "Deploy latest code to GPaaS"

on:
workflow_call:
inputs:
environment:
description: 'The name of the environment we are deploying to'
required: true
type: string
secrets:
CF_API:
description: 'The GPaaS API'
required: true
CF_USERNAME:
description: 'The GPaaS Username'
required: true
CF_PASSWORD:
description: 'The GPaaS Password'
required: true
CF_ORG:
description: 'The org to deploy to'
required: true

concurrency:
group: deploy-${{ inputs.environment }}

jobs:
run-unit-tests:
uses: ./.github/workflows/rubyonrails.yml

run-docker-tests:
uses: ./.github/workflows/docker-image.yml

deploy-to-application:
runs-on: ubuntu-latest
needs:
- run-unit-tests
- run-docker-tests
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Deploy to GPaaS
uses: citizen-of-planet-earth/cf-cli-action@master
with:
cf_api: ${{ secrets.CF_API }}
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: ${{ secrets.CF_ORG }}
cf_space: ${{ inputs.environment }}
command: push -f config/manifests/${{ inputs.environment }}.yml --strategy rolling
7 changes: 1 addition & 6 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
name: Docker Image CI

on:
push:
branches-ignore:
- develop
- staging
- main
pull_request:
workflow_call:

jobs:
docker:
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: "Ruby on Rails CI"

on:
push:
branches-ignore:
- develop
- staging
- main
pull_request:
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:
Expand All @@ -25,7 +30,7 @@ jobs:
env:
RAILS_ENV: test
DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test"
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CC_TEST_REPORTER_ID: ${{ secrets.cc_test_reporter_id }}

steps:
- name: Checkout code
Expand All @@ -49,4 +54,4 @@ jobs:
uses: paambaati/codeclimate-action@v5.0.0
with:
debug: true
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'develop' }}
if: ${{ inputs.publish_test_report }}
55 changes: 55 additions & 0 deletions .github/workflows/setup_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "Set up deployment of latest code to GPaaS"

on:
push:
branches:
- develop
- staging
- main

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/develop")
echo "development"
;;
"refs/heads/staging")
echo "pre-production"
;;
"refs/heads/main")
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 }}"

deploy-to-gpaas:
uses: ./.github/workflows/deploy_to_gpaas.yml
needs:
- determine-environment
with:
environment: ${{ needs.determine-environment.outputs.ENV_NAME }}
secrets:
CF_API: ${{ secrets.CF_API }}
CF_USERNAME: ${{ secrets.CF_USERNAME }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
CF_ORG: ${{ secrets.CF_ORG }}
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Run our tests"

on:
push:
branches-ignore:
- develop
- staging
- main
pull_request:

jobs:
run-unit-tests:
uses: ./.github/workflows/rubyonrails.yml
with:
publish_test_report: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'develop' }}
secrets:
cc_test_reporter_id: ${{ secrets.CC_TEST_REPORTER_ID }}

run-docker-build:
uses: ./.github/workflows/docker-image.yml
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Print Marketplace IDAM

[![Build Status](https://app.travis-ci.com/Crown-Commercial-Service/pmp-idam.svg?branch=develop)](https://app.travis-ci.com/Crown-Commercial-Service/pmp-idam)
[![Test Status](https://github.com/Crown-Commercial-Service/pmp-idam/actions/workflows/test.yml/badge.svg)](https://github.com/Crown-Commercial-Service/pmp-idam/actions/workflows/test.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/0cd357c324b2731fb1bc/maintainability)](https://codeclimate.com/github/Crown-Commercial-Service/pmp-idam/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/0cd357c324b2731fb1bc/test_coverage)](https://codeclimate.com/github/Crown-Commercial-Service/pmp-idam/test_coverage)

**Deployments**
| Environment | Deployment status |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Development | ![Latest Development deployment](https://github.com/Crown-Commercial-Service/pmp-idam/actions/workflows/setup_deployment.yml/badge.svg?branch=develop) |
| Pre-Production | ![Latest Pre-Production deployment](https://github.com/Crown-Commercial-Service/pmp-idam/actions/workflows/setup_deployment.yml/badge.svg?branch=staging) |
| Production | ![Latest Production deployment](https://github.com/Crown-Commercial-Service/pmp-idam/actions/workflows/setup_deployment.yml/badge.svg?branch=main) |

## Prerequisites

This README assumes you are using a MacBook. If you are using a different operating system you may need to take different steps to achive the same results but the prerequisites are likely to be the same or similar.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit af19068

Please sign in to comment.