Skip to content

Commit

Permalink
Support manual deployments (#29)
Browse files Browse the repository at this point in the history
* Update CD workflow to support manual deployments

* Optimize the CI pipeline to only test what has changed
  • Loading branch information
joseph-flinn authored Aug 19, 2023
1 parent 49e9d1b commit ab83d0a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/build-n-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ name: Build and Deploy

on:
workflow_dispatch:
inputs: {}
inputs:
deploy-frontend:
description: "Deploy Frontend"
default: false
type: boolean
deploy-backend:
description: "Deploy Backend"
default: false
type: boolean
update-data:
description: "Update Data"
default: false
type: boolean
push:
branches:
- main
Expand All @@ -23,9 +35,9 @@ jobs:
- name: Detect Changes
id: changes
run: |
FRONTEND_DIFF=$(git diff --name-only origin/main -- frontend/* | wc -l | xargs)
DATA_DIFF=$(git diff --name-only origin/main -- data/* | wc -l | xargs)
BACKEND_DIFF=$(git diff --name-only origin/main -- backend/* | wc -l | xargs)
FRONTEND_DIFF=$(git diff --name-only HEAD~1 -- frontend/* | wc -l | xargs)
DATA_DIFF=$(git diff --name-only HEAD~1 -- data/* | wc -l | xargs)
BACKEND_DIFF=$(git diff --name-only HEAD~1 -- backend/* | wc -l | xargs)
if [[ "$FRONTEND_DIFF" == "1" ]]; then
echo "frontend-changed=true" >> $GITHUB_OUTPUT
Expand All @@ -42,7 +54,7 @@ jobs:
build-frontend:
name: Build Frontend
if: ${{ needs.setup.outputs.frontend-changed == 'true' }}
if: ${{ needs.setup.outputs.frontend-changed == 'true' || inputs.deploy-frontend }}
needs: [setup]
runs-on: ubuntu-latest
steps:
Expand All @@ -64,7 +76,7 @@ jobs:

deploy-frontend:
name: Deploy Frontend
if: ${{ needs.setup.outputs.frontend-changed == 'true' }}
if: ${{ needs.setup.outputs.frontend-changed == 'true' || inputs.deploy-frontend }}
runs-on: ubuntu-latest
needs:
- setup
Expand All @@ -83,7 +95,7 @@ jobs:

build-n-deploy-data:
name: Build Data
if: ${{ needs.setup.outputs.data-changed == 'true' }}
if: ${{ needs.setup.outputs.data-changed == 'true' || inputs.update-data }}
needs: [setup]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -113,7 +125,7 @@ jobs:

deploy-backend:
name: Deploy Backend
if: ${{ needs.setup.outputs.backend-changed == 'true' }}
if: ${{ needs.setup.outputs.backend-changed == 'true' || inputs.deploy-backend }}
needs: [setup]
runs-on: ubuntu-latest
steps:
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,42 @@ on:
- main

jobs:
setup:
name: Deploy Setup
runs-on: ubuntu-latest
outputs:
frontend-changed: ${{ steps.changes.outputs.frontend-changed }}
data-changed: ${{ steps.changes.outputs.data-changed }}
backend-changed: ${{ steps.changes.outputs.backend-changed }}
steps:
- name: Checkout
uses: actions/[email protected]

- name: Detect Changes
id: changes
run: |
FRONTEND_DIFF=$(git diff --name-only origin/main -- frontend/* | wc -l | xargs)
DATA_DIFF=$(git diff --name-only origin/main -- data/* | wc -l | xargs)
BACKEND_DIFF=$(git diff --name-only origin/main -- backend/* | wc -l | xargs)
if [[ "$FRONTEND_DIFF" == "1" ]]; then
echo "frontend-changed=true" >> $GITHUB_OUTPUT
fi
if [[ "$DATA_DIFF" == "1" ]]; then
echo "data-changed=true" >> $GITHUB_OUTPUT
fi
if [[ "$BACKEND_DIFF" == "1" ]]; then
echo "backend-changed=true" >> $GITHUB_OUTPUT
fi
build-frontend:
name: Build Frontend
if: ${{ needs.setup.outputs.frontend-changed == 'true' }}
runs-on: ubuntu-latest
needs: [setup]
steps:
- name: Checkout
uses: actions/[email protected]
Expand All @@ -26,7 +59,9 @@ jobs:
build-data:
name: Build Data
if: ${{ needs.setup.outputs.data-changed == 'true' }}
runs-on: ubuntu-latest
needs: [setup]
steps:
- name: Checkout
uses: actions/[email protected]
Expand All @@ -40,7 +75,9 @@ jobs:
test-backend:
name: Deploy & Test Backend
if: ${{ needs.setup.outputs.backend-changed == 'true' }}
runs-on: ubuntu-latest
needs: [setup]
steps:
- name: Checkout
uses: actions/[email protected]
Expand Down

0 comments on commit ab83d0a

Please sign in to comment.