Skip to content

Commit

Permalink
Merge pull request #12 from EA31337/dev
Browse files Browse the repository at this point in the history
Development enhancements
  • Loading branch information
kenorb authored Jul 7, 2024
2 parents 5b99691 + a8e57fb commit 61c40a0
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 23 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
name: Platform (Linux)

env:
ARTIFACT_NAME: ${{ inputs.artifact || 'platform' }}
CHECKOUT_REF: ${{ inputs.ref || 'dev' }}
CLEANUP: ${{ inputs.cleanup || true }}
REPOSITORY: EA31337/ansible-role-metatrader
VERSION: ${{ inputs.version || 5 }}

# yamllint disable-line rule:truthy
on:
pull_request:
paths:
- '.github/workflows/platform.yml'
push:
branches:
- 'master'
- '*dev*'
paths:
- '.github/workflows/platform.yml'
workflow_call:
inputs:
artifact:
default: platform
description: Artifact name
required: false
type: string
cleanup:
default: false
description: Whether to run clean-up job
required: false
type: boolean
ref:
default: dev
description: The branch, tag or SHA to checkout.
required: false
type: string
version:
default: 5
description: Version to install
type: number

jobs:
platform-linux:
name: Platform
outputs:
workdir: ${{ github.workspace }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.CHECKOUT_REF }}
repository: ${{ env.REPOSITORY }}
- name: Runs playbook
uses: dawidd6/action-ansible-playbook@v2
with:
configuration: |
[defaults]
nocows = false
stdout_callback = yaml
directory: ${{ env.WORKDIR }}
options: |
--connection local
--inventory localhost,
--verbose
playbook: molecule/mt${{ env.VERSION }}/converge.yml
requirements: meta/galaxy-requirements.yml
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: |
~/.wine/drive_c/Program Files*/**/*MT*
~/.wine/drive_c/Program Files*/**/*Meta*
timeout-minutes: 20
cleanup:
name: Clean-up
needs: [platform-linux]
runs-on: ubuntu-latest
steps:
- uses: geekyeggo/delete-artifact@v4
if: env.CLEANUP && github.repository == env.REPOSITORY
with:
name: ${{ env.ARTIFACT_NAME }}
9 changes: 9 additions & 0 deletions meta/galaxy-requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# A file containing a list of collections to be installed.
# Usage:
# ansible-galaxy install -r galaxy-requirements.yml
---
roles:
- name: ea31337.metatrader
scm: git
src: https://github.com/EA31337/ansible-role-metatrader.git
version: dev
3 changes: 2 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
- name: Converge
hosts: all
gather_facts: true
tasks:
- name: Include main role
ansible.builtin.include_role:
ansible.builtin.import_role:
name: ea31337.metatrader
vars:
# @fixme: https://github.com/Winetricks/winetricks/issues/2119
Expand Down
2 changes: 1 addition & 1 deletion molecule/mt4/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
tasks:
- name: Include main role
ansible.builtin.include_role:
ansible.builtin.import_role:
name: ea31337.metatrader
vars:
metatrader_setup_url: |
Expand Down
2 changes: 1 addition & 1 deletion molecule/mt5/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
tasks:
- name: Include main role
ansible.builtin.include_role:
ansible.builtin.import_role:
name: ea31337.metatrader
vars:
metatrader_version: 5
Expand Down
85 changes: 66 additions & 19 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
---
- name: Validates variables
ansible.builtin.assert:
that:
- metatrader_setup_url | length > 0
- name: Checks if platform is already installed
register: file_mt_installed_exists
- name: Collects local facts
ansible.builtin.setup:
filter:
- ansible_local
when: false
- name: Checks if platform is already exist
ansible.builtin.stat:
path: ~/.wine/.installed-mt{{ metatrader_version }}
path: "{{ ansible_local['metatrader'][metatrader_version | string].path }}"
register: stat_mt
when: ansible_local['metatrader'] is defined
- name: Ensures platform is installed
when:
- ansible_os_family != "Windows"
- name: Ensures Curl is present
ansible.builtin.package:
name: curl
state: present
when:
- ansible_os_family != "Windows"
- not file_mt_installed_exists.stat.exists
- name: Installs MetaTrader (via Winetricks)
when:
- ansible_os_family != "Windows"
- not file_mt_installed_exists.stat.exists
- ansible_local['metatrader'] is not defined
- ansible_os_family != "Windows" # gather_facts is required.
- (stat_mt.stat is not defined) or (not stat_mt.stat.exists)
block:
- name: Validates variables
ansible.builtin.assert:
that:
- metatrader_setup_url | length > 0
- name: Checks if platform is already installed
register: file_mt_installed_exists
ansible.builtin.stat:
path: ~/.wine/.installed-mt{{ metatrader_version }}
when:
- ansible_os_family != "Windows"
- name: Ensures Curl is present
ansible.builtin.package:
name: curl
state: present
when:
- ansible_os_family != "Windows"
- not file_mt_installed_exists.stat.exists
- name: Ensures verb installation file is present
ansible.builtin.template:
src: mt{{ metatrader_version }}_install.verb.j2
dest: /tmp/mt{{ metatrader_version }}_install.verb
mode: "0640"
when:
- not file_mt_installed_exists.stat.exists
- name: Ensures MetaTrader is installed (via verb file)
ansible.builtin.shell:
# noqa command-instead-of-shell
Expand All @@ -37,6 +50,8 @@
creates: ~/.wine/.installed-mt{{ metatrader_version }}
args:
executable: /bin/bash
when:
- not file_mt_installed_exists.stat.exists
- name: Ensures verb installation file is absent
ansible.builtin.file:
path: /tmp/mt{{ metatrader_version }}_install.verb
Expand All @@ -45,3 +60,35 @@
ansible.builtin.include_tasks: verify.yml
tags:
- metatrader_verify
- name: Saves platform facts
become: true
when:
- >-
ansible_local['metatrader'] is not defined
or (find_mt_res.files[0].path | dirname)
!= ansible_local['metatrader'][metatrader_version | string].path
block:
- name: Sets fact
ansible.builtin.set_fact:
cacheable: true
metatrader: >-
{
'{{ metatrader_version | int }}':
{
'path': '{{ find_mt_res.files[0].path | dirname }}'
}
}
when:
- find_mt_res is defined
- find_mt_res.files | length > 0
- metatrader_version is defined
- name: Ensures that Ansible local facts directory exists
ansible.builtin.file:
path: /etc/ansible/facts.d
state: directory
mode: '0755'
- name: Saves role's facts
ansible.builtin.copy:
content: "{{ ansible_facts['metatrader'] }}"
dest: /etc/ansible/facts.d/metatrader.fact
mode: "0644"
2 changes: 1 addition & 1 deletion templates/mt4_install.verb.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load_mt4_install()

if w_workaround_wine_bug 7156 "${title} needs wingdings.ttf, installing opensymbol"
then
echo w_call opensymbol # @fixme: GH-6
w_call opensymbol # @fixme: GH-6
fi

# Opens a webpage.
Expand Down

0 comments on commit 61c40a0

Please sign in to comment.