Skip to content

Creation of a github action workflow

Stanislav Kutasevits edited this page Dec 1, 2022 · 16 revisions

How to create Github action:

  • Go to Actions - https://github.com/OS2Forms/os2forms8/actions
  • Depending on if you already have an action or creating a new one, you will get a different screen:
  • If there are previous actions, click on Click on New workflow
  • Click Set up a workflow yourself:
  • Add the content of your workflow, for example like this:

name: Deploy release to test.os2forms.dk https://github.com/OS2Forms/os2forms8/actions/workflows/deploy-release-to-test.yml

on:
  release:
    types: [published]
jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: executing remote ssh commands using password
      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        key: ${{ secrets.KEY }}
        port: ${{ secrets.PORT }}
        script: |
          whoami
          sh /var/www/test.os2forms.dk/private/os2forms_init/rebuild_installation.sh

This workflow will react to a new release being published and execute the scripts after it.

The script executed is located on the server in [doc root]/private/os2forms_init/rebuild_installation.sh:

#! /bin/bash
cd /var/www/test.os2forms.dk
drush sql-dump | gzip > /var/www/test.os2forms.dk/private/os2forms_init/db_dumps/test.os2forms.dk_latest.sql.gz
git pull
rm composer.lock
composer install
drush cr

How to setup the server

  • Create the user for the github action
  • Create the keys for the user
  • Make sure SSH is accessible
  • Login with the user at least once to make sure there is no prompt
  • Add rebuild_installation.sh script to the server
  • Test rebuild_installation.sh and and make sure that it is working

The script will be triggered every time a new release has been created. The execution details can be seen here: https://github.com/OS2Forms/os2forms8/actions/workflows/deploy-release-to-test.yml

How to setup the connection

HOST: 193.84.27.193
PORT: 22
USERNAME: [server username]
KEY: [server user private key]

Test by creating new release

Debugging

For debugging go the the script that was executet. You can se each "run".