-
Notifications
You must be signed in to change notification settings - Fork 10
Creation of a github action workflow
Files: https://github.com/OS2Forms/os2forms8/actions/workflows/deploy-release-to-test.yml
Setup:
- 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 INDSÆT BILLEDE
Click Set up a workflow yourself: INDSÆT BILLEDE
- 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 script which is located on the server is /var/www/test.os2forms.dk/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 drush sql-drop -y gunzip -c /var/www/test.os2forms.dk/private/os2forms_init/db_dumps/test.os2forms.dk_init.sql.gz | drush sqlc git pull rm composer.lock composer install drush cr drush sql-dump | gzip > /var/www/test.os2forms.dk/private/os2forms_init/db_dumps/test.os2forms.dk_init.sql.gz
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
- 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