From 780b4667ff05ccb0d6a841f11e5486a465edf2d5 Mon Sep 17 00:00:00 2001 From: Anatolios Laskaris Date: Fri, 9 Feb 2024 17:14:42 +0200 Subject: [PATCH] fix: Check if tar is GNU type (#8) * Add gnu-tar check * F * F * Fix * No fucking linter * F * F * F? * F * F * F * Upload coll * F * Fix ansible version --- .github/workflows/ansible.yml | 50 ++++++++++++++++++++++----- README.md | 1 + extensions/molecule/converge.yml | 4 +++ extensions/molecule/prepare.yml | 4 +++ meta/runtime.yml | 2 +- plugins/modules/check_tar_type.py | 39 +++++++++++++++++++++ roles/ipfs_cli/tasks/00-preflight.yml | 4 +++ roles/nox/tasks/00-preflight.yml | 4 +++ 8 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 plugins/modules/check_tar_type.py diff --git a/.github/workflows/ansible.yml b/.github/workflows/ansible.yml index b46de70..f89fb06 100644 --- a/.github/workflows/ansible.yml +++ b/.github/workflows/ansible.yml @@ -18,26 +18,50 @@ env: FORCE_COLOR: 1 jobs: - lint: + # lint: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + + # - name: Run ansible-later + # uses: patrickjahns/ansible-later-action@v1.3.0 + # with: + # config: .later.yml + + # - name: Run ansible-lint + # uses: reviewdog/action-ansiblelint@v1 + # with: + # reporter: github-pr-check + # fail_on_error: true + + collection: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Run ansible-later - uses: patrickjahns/ansible-later-action@v1.3.0 + - name: Setup python + uses: actions/setup-python@v5 with: - config: .later.yml + python-version: "3.x" + cache: pip - - name: Run ansible-lint - uses: reviewdog/action-ansiblelint@v1 + - name: Install python dependencies + run: python -m pip install -r requirements.txt + + - name: Build collection + run: ansible-galaxy collection build . + + - name: Upload collection + uses: actions/upload-artifact@v4 with: - reporter: github-pr-check - fail_on_error: true + path: fluencelabs-provider-*.tar.gz + name: collection + if-no-files-found: error molecule: runs-on: ubuntu-latest - needs: lint + needs: collection strategy: fail-fast: false @@ -65,6 +89,14 @@ jobs: - name: Install python dependencies run: python -m pip install -r requirements.txt + - name: Download collection + uses: actions/download-artifact@v4 + with: + name: collection + + - name: Install collection + run: ansible-galaxy collection install fluencelabs-provider-*.tar.gz + - name: Run ${{ matrix.scenario }} scenario working-directory: extensions run: molecule test --scenario-name "${{ matrix.scenario }}" diff --git a/README.md b/README.md index 9ef0c03..a761e80 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Fluence provider toolkit. ## Requirements - Ansible >= 2.12 (might work on older versions) +- gnu-tar on MacOS control host (`brew install gnu-tar`) ## Roles diff --git a/extensions/molecule/converge.yml b/extensions/molecule/converge.yml index 78e28ec..c757ccc 100644 --- a/extensions/molecule/converge.yml +++ b/extensions/molecule/converge.yml @@ -5,6 +5,10 @@ nox_version: "0.16.13" nox_project_dir: "molecule" ipfs_cli_version: "0.25.0" + + collections: + - fluencelabs.provider + tasks: - name: Run nox role include_role: diff --git a/extensions/molecule/prepare.yml b/extensions/molecule/prepare.yml index 70662cb..f9d14f5 100644 --- a/extensions/molecule/prepare.yml +++ b/extensions/molecule/prepare.yml @@ -6,6 +6,10 @@ nox_project_dir: "molecule" nox_instances: [0] ipfs_cli_version: "0.25.0" + + collections: + - fluencelabs.provider + tasks: - name: Run nox role include_role: diff --git a/meta/runtime.yml b/meta/runtime.yml index c72963f..f13ba8b 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1 +1 @@ -requires_ansible: ">=2.16.0" +requires_ansible: ">=2.12.0" diff --git a/plugins/modules/check_tar_type.py b/plugins/modules/check_tar_type.py new file mode 100644 index 0000000..3990851 --- /dev/null +++ b/plugins/modules/check_tar_type.py @@ -0,0 +1,39 @@ +#!/usr/bin/python + +from ansible.module_utils.basic import AnsibleModule +import platform + + +def check_tar_type(module): + cmd = ['tar', '--version'] + rc, out, err = module.run_command(cmd, check_rc=False) + + if rc != 0 or ('GNU tar' not in out and 'bsdtar' not in out): + return None, out + if 'GNU tar' in out: + return 'gnu', out + else: + return 'bsd', out + + +def main(): + module = AnsibleModule( + argument_spec={} + ) + + tar_type, tar_output = check_tar_type(module) + + if tar_type == 'gnu': + module.exit_json( + changed=False, + msg="GNU tar is installed.", + tar_type=tar_type) + else: + fail_msg = "Non GNU tar is installed." + if platform.system() == 'Darwin': + fail_msg += " You can install GNU tar with 'brew install gnu-tar'." + module.fail_json(msg=fail_msg, tar_output=tar_output) + + +if __name__ == '__main__': + main() diff --git a/roles/ipfs_cli/tasks/00-preflight.yml b/roles/ipfs_cli/tasks/00-preflight.yml index ef0db0d..a52d7bb 100644 --- a/roles/ipfs_cli/tasks/00-preflight.yml +++ b/roles/ipfs_cli/tasks/00-preflight.yml @@ -16,3 +16,7 @@ - nox_dir is string - nox_dir | length quiet: true + +- name: check that tar is GNU type # noqa + tags: always + fluencelabs.provider.check_tar_type: diff --git a/roles/nox/tasks/00-preflight.yml b/roles/nox/tasks/00-preflight.yml index 5dcc0ae..cb07ca3 100644 --- a/roles/nox/tasks/00-preflight.yml +++ b/roles/nox/tasks/00-preflight.yml @@ -9,6 +9,10 @@ quiet: true when: nox_run_id | string | length +- name: check that tar is GNU type # noqa + tags: always + fluencelabs.provider.check_tar_type: + - name: check "nox_instances" variable tags: always ansible.builtin.assert: