Skip to content

Commit

Permalink
Add GitHub Action to publish content.
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklan committed Jun 19, 2024
1 parent 79b5dba commit 9063f74
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/actions/create-ssh-key/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 'Create SSH key'
description: 'Setups SSH key for future use.'

inputs:
private-key:
description: 'Private key contents (id_rsa)'
required: true

host-label:
description: 'SSH name'
default: 'server'

host:
description: 'Default connection host'
required: true

port:
description: 'SSH port'
default: '22'

user:
description: 'Default connection user'
required: true

strict-host-key-checking:
description: 'Is host key should be strict checked'
# Disabled by default for straight forward connection.
default: 'no'

runs:
using: "composite"
steps:
- name: Create SSH key
shell: bash
run: |
mkdir -p ~/.ssh;
echo "${{ inputs.private-key }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
cat >>~/.ssh/config <<END
Host ${{ inputs.host-label }}
HostName ${{ inputs.host }}
Port ${{ inputs.port }}
User ${{ inputs.user }}
IdentityFile ~/.ssh/id_rsa
StrictHostKeyChecking ${{ inputs.strict-host-key-checking }}
END
43 changes: 43 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CD

on:
workflow_dispatch:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

jobs:
publish:
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
name: Publish
runs-on: ubuntu-latest
environment:
name: production
url: https://niklan.net
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create SSH key
uses: ./.github/actions/create-ssh-key
with:
private-key: ${{ secrets.cd_production_deploy_key }}
user: ${{ secrets.cd_production_user }}
host: ${{ secrets.cd_production_host }}
port: ${{ secrets.cd_production_port }}

- name: Sync content
shell: bash
run: |
ssh server <<< "
cd ${{ secrets.cd_production_content_directiory }}
mkdir -p ${{ secrets.cd_production_deploy_files }}
drush sql:dump \
--gzip \
--structure-tables-list=cache,cache_*,flood,history,queue,search_index,search_api_*,semaphore,sequences,sessions,watchdog \
> ${{ secrets.cd_production_deploy_directory }}/pre-deploy.sql.gz
git fetch
git checkout
git pull
drush niklan:sync:blog
"

0 comments on commit 9063f74

Please sign in to comment.