Skip to content

Commit

Permalink
Merge pull request #55 from dsavchenko/live-preview-action
Browse files Browse the repository at this point in the history
Live preview action
  • Loading branch information
volodymyrss authored Dec 19, 2023
2 parents f9ba105 + 04da544 commit 19a59d7
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/live-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Preview PR on galaxy.odahub.fr
on:
pull_request:
branches:
- main
types:
- opened
- labeled
- synchronize
paths-ignore:
- '.github/**'
- 'deprecated/**'
- 'docs/**'
- '*'
env:
GALAXY_FORK: galaxyproject
GALAXY_BRANCH: release_23.1

jobs:
setup:
if: contains( github.event.pull_request.labels.*.name, 'test-live')
name: Determine changed repositories
runs-on: ubuntu-latest
outputs:
tool-list: ${{ steps.discover.outputs.tool-list }}
steps:
- uses: actions/setup-python@v4
with:
python-version: "3.7"
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fake a Planemo run to determine tool list
uses: galaxyproject/planemo-ci-action@v1
id: discover
with:
galaxy-fork: ${{ env.GALAXY_FORK }}
galaxy-branch: ${{ env.GALAXY_BRANCH }}
python-version: "3.7"
- name: Show tool list
run: echo '${{ steps.discover.outputs.tool-list }}'

# deploy the tools
deploy:
name: Deploy
if: contains( github.event.pull_request.labels.*.name, 'test-live') && needs.setup.outputs.tool-list
needs: setup
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install requirenments
run: sudo apt-get install -y ansible
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Deploy tools
env:
TOOL_LIST: ${{ needs.setup.outputs.tool-list }}
pr_num: ${{ github.event.pull_request.number }}
run: |
cd deploy-preview
dir_list=`for tl in $TOOL_LIST ; do echo $tl | awk -F '/' '{print $2}'; done | uniq`
for dr in $dir_list; do
tools_list=`for tl in $TOOL_LIST; do if [[ "$tl" == *"$dr"* ]] ; then basename $tl ; fi ; done`
export tools_list
export tool_dir=$dr
ansible-playbook deploy.yml
done
6 changes: 6 additions & 0 deletions deploy-preview/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[defaults]
inventory = hosts
timeout = 60

[ssh_connection]
pipelining = true
49 changes: 49 additions & 0 deletions deploy-preview/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
- hosts: all
become: true
become_user: root
vars:
src_tools_dir: ../tools
dest_tools_dir: /srv/galaxy/staging_tools
dest_tools_conf: /srv/galaxy/server/config/staging_tool_conf.xml
tools_list: "{{ lookup('env', 'tools_list').split() }}"
tool_dir: "{{ lookup('env', 'tool_dir') }}"
pr_num: "{{ lookup('env', 'pr_num') }}"


tasks:
- name: Sync tool dir
ansible.posix.synchronize:
src: "{{ src_tools_dir }}/{{ tool_dir }}/"
dest: "{{ dest_tools_dir }}/{{ tool_dir }}_pr{{ pr_num }}"
rsync_opts:
- "--chown=galaxy:galaxy"

- name: Make id unique
replace:
path: "{{ dest_tools_dir }}/{{ tool_dir }}_pr{{ pr_num }}/{{ item }}"
regexp: '<tool id="([a-z0-9_]+)"'
replace: '<tool id="\1_pr{{ pr_num }}"'
loop: "{{ tools_list }}"

- name: Make name unique
replace:
path: "{{ dest_tools_dir }}/{{ tool_dir }}_pr{{ pr_num }}/{{ item }}"
regexp: '<tool(.*)name="([a-z0-9_]+)"'
replace: '<tool\1name="\2_pr{{ pr_num }}"'
loop: "{{ tools_list }}"

- name: Clean previous references
lineinfile:
path: "{{ dest_tools_conf }}"
regexp: '^\s*<tool\s+file="{{ tool_dir }}_pr{{ pr_num }}/'
state: absent
loop: "{{ tools_list }}"

- name: Enable tools
lineinfile:
path: "{{ dest_tools_conf }}"
regexp: '^\s*<tool\s+file="{{ tool_dir }}_pr{{ pr_num }}/{{ item|regex_escape }}"'
insertafter: '<section id="astro_staging"'
line: ' <tool file="{{ tool_dir }}_pr{{ pr_num }}/{{ item }}" />'
loop: "{{ tools_list }}"
2 changes: 2 additions & 0 deletions deploy-preview/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[all]
galaxy.odahub.fr ansible_ssh_user=ubuntu

0 comments on commit 19a59d7

Please sign in to comment.