#!/usr/bin/env python3

import sys
import subprocess
import re
from datetime import datetime

class bcolors:
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    ENDC = '\033[0m'

localizable_files = [
    'playstore/en/*.txt',
    'app/src/main/res/values/strings.xml',
    'app/src/main/res/raw/*.txt'
    ]
localized_locations = [
    'playstore/*/*.txt',
    'app/src/main/res/values-*/strings.xml',
    'app/src/main/res/raw-*/*.txt'
    ]

default_files = {}
for fileglob in localizable_files:
    output = subprocess.run('git ls-files {} | xargs -n1 git log --format=format:"~ %aI" --name-only -n1'.format(fileglob), shell=True,stdout=subprocess.PIPE).stdout.decode('utf-8')

    currentdate = ""
    for line in output.splitlines():
        if line[:1] == "~":
            currentdate = datetime.fromisoformat(line[2:])
        else:
            fileid = line.replace('/en/','/')
            default_files[fileid] = {
                'filename': line,
                'commit_date': currentdate
                }

errors = 0
for fileglob in localized_locations:
    output = subprocess.run('git ls-files {} | grep -v "playstore/en/" | xargs -n1 git log --format=format:"~ %aI" --name-only -n1'.format(fileglob), shell=True,stdout=subprocess.PIPE).stdout.decode('utf-8')
    currentdate = ""
    for line in output.splitlines():
        if line[:1] == "~":
            currentdate = datetime.fromisoformat(line[2:])
        else:
            fileid = re.sub('(playstore/)[^/]+/', '\\1', line)
            fileid = re.sub('(main/res/[^-/]+)-[^/]+', '\\1', fileid)
            if (currentdate.timestamp() >= default_files[fileid]['commit_date'].timestamp()):
                print("[{}PASS{}] {} is up-to-date.".format(bcolors.OKGREEN,bcolors.ENDC,line))
            else:
                errors = errors + 1
                print("[{}FAIL{}] {} is outdated.".format(bcolors.WARNING,bcolors.ENDC,line))

if (errors > 0):
    print("{}{} outdated localization files found.{}".format(bcolors.WARNING,errors,bcolors.ENDC))
    sys.exit(-1)
else:
    print("All localization files up-to-date.")


@@ -148,17 +148,17 @@
  '%5C033%5B9
-3
+1
 m'%0A    E
@@ -1709,16 +1709,52 @@
 to-date.
+ localized: %7B%7D newer than source: %7B%7D
 %22.format
@@ -1787,16 +1787,65 @@
 NDC,line
+,currentdate,default_files%5Bfileid%5D%5B'commit_date'%5D
 ))%0A     
@@ -1942,16 +1942,52 @@
 utdated.
+ localized: %7B%7D older than source: %7B%7D
 %22.format
@@ -2020,16 +2020,65 @@
 NDC,line
+,currentdate,default_files%5Bfileid%5D%5B'commit_date'%5D
 ))%0A%0Aif (

Add some debug output to test to try to find out why it fails locally and passes in the GHAction