Skip to content

Creation of a github action workflow

Jørn Skifter Andersen edited this page Nov 30, 2022 · 16 revisions

Setup:

  1. Github action is located here: https://github.com/OS2Forms/os2forms8/actions/workflows/deploy-release-to-test.yml the script that it is executing is attached to this task:

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

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.

Executed the script which 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

In order to make the ssh connection work, we need to add credentials/secrets to github (on available if you have admin rights): https://github.com/OS2Forms/os2forms8/settings/secrets/actions HOST: 193.84.27.193 PORT: 22 USERNAME: [server username] KEY: [server user private key] Test by creating new release

  1. Nothing extra needs to be done for test.os2forms.dk, but here is the steps what were necessary: 2.1 Create and setup github workflow (that needs to be done in the main branch - in our case master) 2.2 Add rebuild_installation.sh script to the server 2.3 Test rebuild_installation.sh and and make sure that it is working

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

Script: 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
Clone this wiki locally