0

I am running a .sh script and it runs fine locally (sh /Users/Me/Documents/development/MyRepo/localizable.sh).

However, when I add it to Github actions, I get permission denied.

Exact error:

Run chmod +x localizable.sh 
  chmod +x localizable.sh 
  export LOCALIZATION_OUTPUT=$(bash ./localizable.sh) 
  export LOCALIZATION_OUTPUT="${LOCALIZATION_OUTPUT//'%'/'%25'}" 
  export LOCALIZATION_OUTPUT="${LOCALIZATION_OUTPUT//$'n'/'%0A'}" 
  export LOCALIZATION_OUTPUT="${LOCALIZATION_OUTPUT//$'<NL>'/'%0A'}" 
  export LOCALIZATION_OUTPUT="${LOCALIZATION_OUTPUT//$''/'%0A'}" 
  export LOCALIZATION_OUTPUT="${LOCALIZATION_OUTPUT//$'\r'/'%0D'}" 
  echo $(cat output.txt) 
  echo "::set-output name=message::$LOCALIZATION_OUTPUT"
  shell: /bin/bash -e {0}
./localizable.sh: line 38: MyProject/Localizations/en.lproj/Localizable.strings: Permission denied
grep: Unmatched ( or \(
grep: Unmatched ( or \(
./localizable.sh: line 50: done: command not found
./localizable.sh: line 38: MyProject/Localizations/en.lproj/Localizable.strings: Permission denied
grep: Unmatched ( or \(

This is what .sh file looks like:

#!/bin/sh
if [[ -z $lang ]]
    then
    lang="en"
fi
searchDir="MyProject/Localizations/$lang.lproj"
echo "*Verifying NSLocalizationStrings in "$searchDir"*"
output=$(grep -R  NSLocalizedString . --include="*.swift")
count=$(( 0 ))
missing=$(( 0 ))
unusable=$(( 0 ))
OIFS="${IFS}"
NIFS=$'\n'
IFS="${NIFS}"
echo "Entering Loop ${output}"
for LINE in ${output} ; do
    echo "loop entered"
    IFS="${OIFS}"
    quotes=`echo $LINE | awk -F\" '{ for(i=2; i<=NF; i=i+2){ a = a"\\""$i"\\"""^";} {print a; a="";}}'`
    key=`echo $quotes | cut -f1 -d"^"`
    # 1. Issues with extracting keys if \[\[ -z $key \]\]
    if [[ -z $key ]]
    then
        (( unusable += 1 ))
    echo "Couldn't extract key: " $LINE
    fi
    keyLength=$(echo ${#key})
    
    # 2. Issues with keys that are too long
    if [ $keyLength -gt 79 ]
    then
        (( unusable += 1 ))
    echo "Key too long ("$keyLength"): " $key
    fi
    keyString=$key" ="
    found=$(iconv -sc -f UTF-16 -t UTF-8
"$searchDir/Localizable.strings" | grep "$keyString")
        if [[ -z $found ]]
        then
        found=$(grep -r "$keyString" "$searchDir"/ --include=*.strings)
        fi
        if [[ -z $found ]]
        then
            (( missing += 1 )) 
        echo "<NL>**Missing**: \`$key\` from: 
        <NL>\`\`\`swift<NIL>$LINE<NL>\`\`\`" 
        fi 
        (( count += 1 )) 
        
        IFS="${NIFS}" done IFS="${OIFS}"
done
IFS="${OIFS}" 
echo "<NL>Out of $count keys: <NL>- $unusable not determined<NL>- $missing missing" 
if [[ $missing > 0 ]] 
then 
    echo "::set-output name=keys_missing::true" >> output.txt 
else echo "::set-output name=keys_missing::false" >> output.txt 
fi

How can I get this to run on Github, or anywhere else besides my computer?

user1107173
  • 10,334
  • 16
  • 72
  • 117
  • Please paste your script first at [shellcheck.net](http://www.shellcheck.net/) and try to implement the recommendations made there. – Cyrus Aug 07 '20 at 23:56
  • 1
    `sh` ([Bourne-shell](https://en.wikipedia.org/wiki/Bourne_shell)) is usally not `bash` ([Bourne-again shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell))). – Cyrus Aug 07 '20 at 23:57

2 Answers2

1

I changed to bash and used https://www.shellcheck.net/ to modify all issues, try as follow:

#!/bin/bash
if [[ -z $lang ]]
    then
    lang="en"
fi
searchDir="MyProject/Localizations/$lang.lproj"
echo "*Verifying NSLocalizationStrings in $searchDir*"
output=$(grep -R  NSLocalizedString . --include="*.swift")
count=$(( 0 ))
missing=$(( 0 ))
unusable=$(( 0 ))
OIFS="${IFS}"
NIFS=$'\n'
IFS="${NIFS}"
echo "Entering Loop ${output}"
for LINE in ${output} ; do
    echo "loop entered"
    IFS="${OIFS}"
    quotes=$(echo "$LINE" | awk -F\" '{ for(i=2; i<=NF; i=i+2){ a = a"\\""$i"\\"""^";} {print a; a="";}}')
    key=$(echo "$quotes" | cut -f1 -d"^")
    # 1. Issues with extracting keys if \[\[ -z $key \]\]
    if [[ -z $key ]]
    then
        (( unusable += 1 ))
    echo "Couldn't extract key: $LINE"
    fi
    keyLength=$(${#key})
    
    # 2. Issues with keys that are too long
    if [[ $keyLength -gt 79 ]]
    then
        (( unusable += 1 ))
    echo "Key too long ($keyLength): $key"
    fi
    keyString=$key" ="
    found=$(iconv -sc -f UTF-16 -t UTF-8
"$searchDir/Localizable.strings" | grep "$keyString")
        if [[ -z $found ]]
        then
        found=$(grep -r "$keyString" "$searchDir"/ --include=*.strings)
        fi
        if [[ -z $found ]]
        then
            (( missing += 1 )) 
        echo "<NL>**Missing**: \`$key\` from: 
        <NL>\`\`\`swift<NIL>$LINE<NL>\`\`\`" 
        fi 
        (( count += 1 )) 
        
        IFS="${NIFS}" 'done' IFS="${OIFS}"
done
IFS="${OIFS}" 
echo "<NL>Out of $count keys: <NL>- $unusable not determined<NL>- $missing missing" 
if [[ $missing -gt 0 ]] 
then 
    echo "::set-output name=keys_missing::true" >> output.txt 
else echo "::set-output name=keys_missing::false" >> output.txt 
fi
1

Add additional step to Github actions:

- name: Make executeable
    run: chmod +x ./localizable.sh

maybe this works?

Found this information here.

sunriax
  • 592
  • 4
  • 16