#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2021 Shlomi Fish < https://www.shlomifish.org/ >
#
# Licensed under the terms of the MIT license.

"""

"""

import yaml


def main():
    """docstring for main"""
    with open("./.travis.yml", "rt") as infh:
        data = yaml.safe_load(infh)
    steps = []
    steps.append({
        "uses": ("actions/checkout@v2"),
        "with": {
            "submodules": "true",
        },
    })
    if 0:
        steps.append({
            "run":
            ("cd workflow ; (ls -lrtA ; false)"), })
    elif 0:
        steps.append({
            "run":
            ("cd . ; (ls -lrtA ; false)"), })
    steps.append({"run": ("sudo apt-get update -qq"), })
    steps.append({
        "run": ("sudo apt-get --no-install-recommends install -y " +
                " ".join(data['addons']['apt']['packages'])
                ),
        }
    )
    local_lib_shim = 'local_lib_shim() { eval "$(perl ' + \
        '-Mlocal::lib=$HOME/' + \
        'perl_modules)"; } ; local_lib_shim ; '
    for arr in ['before_install', 'install', 'script']:
        steps += [{"run": local_lib_shim + x} for x in data[arr]]
    o = {'jobs': {'test-black-hole-solver': {'runs-on': 'ubuntu-latest',
         'steps': steps, }},
         'name': 'use-github-actions', 'on': ['push', ], }
    with open(".github/workflows/use-github-actions.yml", "wt") as outfh:
        outfh.write(
            "# This file is GENERATED BY\n" +
            "# black-hole-solitaire/CI-testing/" +
            "translate-travis.yml-to-github-actions.py\n"
        )
        # yaml.safe_dump(o, outfh)
        yaml.safe_dump(o, stream=outfh, canonical=False, indent=4, )


main()

@@ -197,16 +197,385 @@
  yaml%0A%0A%0A
+def _write(output_path, data):%0A    with open(output_path, %22wt%22) as outfh:%0A        # yaml.safe_dump(o, outfh)%0A        outfh.write(%0A            %22# This file is GENERATED BY%5Cn%22 +%0A            %22# black-hole-solitaire/CI-testing/%22 +%0A            %22translate-travis.yml-to-github-actions.py%5Cn%22%0A        )%0A        yaml.safe_dump(data, stream=outfh, canonical=False, indent=4, )%0A%0A%0A
 def main
@@ -1708,26 +1708,30 @@
 , %7D%0A    
-with open(
+output_path = 
 %22.github
@@ -1768,312 +1768,51 @@
 yml%22
-, %22wt%22) as outfh:%0A        outfh.write(%0A            %22# This file is GENERATED BY%5Cn%22 +%0A            %22# black-hole-solitaire/CI-testing/%22 +%0A            %22translate-travis.yml-to-github-actions.py%5Cn%22%0A        )%0A        # yaml.safe_dump(o, outfh)%0A        yaml.safe_dump(o, stream=outfh, canonical=False, indent=4
+%0A    _write(output_path=output_path, data=o
 , )%0A

add generated-by notice to gh actions