Skip to content

Commit

Permalink
Feature: GitHub Actions (#81)
Browse files Browse the repository at this point in the history
Allows for deployments to occur directly from GitHub Actions. This happens by running a bash script on the remote server that deploys the Discord bot.

This creates an easier to use interface with a log for bot deployments. This also creates a pipeline that updates staging directly on push.
  • Loading branch information
zeroclutch committed Sep 26, 2023
1 parent a02f089 commit 6cb3187
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy Production

run-name: ${{ github.actor }} is deploying Gamebot to production

on:
workflow_dispatch:
inputs:
branch:
type: string
default: master
required: false

jobs:
deploy-staging:
uses: ./.github/workflows/deploy-staging.yml
with:
branch: master
secrets: inherit
deploy:
needs: deploy-staging
uses: ./.github/workflows/deploy.yml
with:
environment: production
log_level: info
branch: master
secrets: inherit
47 changes: 47 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy Staging

run-name: ${{ github.actor }} is deploying Gamebot to staging

on:
# Allow for automatic deployment on branches that aren't concerned about downtime
push:
branches:
- staging
workflow_dispatch:
inputs:
branch:
type: string
default: staging
required: false
log_level:
description: 'Log level'
type: choice
options:
- trace
- debug
- info
- warn
- error
default: info
required: false
# Workflow calls allow for this action to be called by other actions
workflow_call:
inputs:
branch:
type: string
default: staging
required: false
log_level:
description: 'Log level'
type: string
default: info
required: false

jobs:
deploy:
uses: ./.github/workflows/deploy.yml
with:
environment: staging
log_level: ${{ inputs.log_level }}
branch: ${{ inputs.branch }}
secrets: inherit
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: deploy

run-name: ${{ github.actor }} is deploying Gamebot

on:
workflow_call:
inputs:
environment:
description: 'Deployment environment'
type: string
required: true
log_level:
description: 'Log level'
type: string
default: 'info'
required: false
branch:
description: 'Branch to deploy from'
type: string
required: false

jobs:
run-unit-tests:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
run-deployment:
needs: run-unit-tests
runs-on: ubuntu-latest
steps:
- name: Run deployment script
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
port: 22
key: ${{ secrets.SSH_KEY }}
script: /home/ubuntu/deploy/bot.sh -e ${{ inputs.environment }} -b ${{ inputs.branch }}

0 comments on commit 6cb3187

Please sign in to comment.