diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml new file mode 100644 index 0000000..33faa33 --- /dev/null +++ b/.github/workflows/platform.yml @@ -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 }} diff --git a/meta/galaxy-requirements.yml b/meta/galaxy-requirements.yml new file mode 100644 index 0000000..fcd1bc6 --- /dev/null +++ b/meta/galaxy-requirements.yml @@ -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 diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 61de970..1a46094 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -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 diff --git a/molecule/mt4/converge.yml b/molecule/mt4/converge.yml index b1b770d..2ad96ae 100644 --- a/molecule/mt4/converge.yml +++ b/molecule/mt4/converge.yml @@ -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: | diff --git a/molecule/mt5/converge.yml b/molecule/mt5/converge.yml index eb8f079..12db19f 100644 --- a/molecule/mt5/converge.yml +++ b/molecule/mt5/converge.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index d054651..31af17d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 @@ -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 @@ -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" diff --git a/templates/mt4_install.verb.j2 b/templates/mt4_install.verb.j2 index e15606e..2cba693 100644 --- a/templates/mt4_install.verb.j2 +++ b/templates/mt4_install.verb.j2 @@ -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.