【问题标题】:Bash: chmod +x localizable.sh : Permission deniedBash:chmod +x localizable.sh:权限被拒绝
【发布时间】:2020-11-28 07:14:27
【问题描述】:

我正在运行 .sh 脚本,它在本地运行良好 (sh /Users/Me/Documents/development/MyRepo/localizable.sh)。

但是,当我将其添加到 Github 操作时,我的权限被拒绝。

确切的错误:

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 \(

这是 .sh 文件的样子:

#!/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

我怎样才能让它在 Github 或除我的计算机之外的任何其他地方运行?

【问题讨论】:

标签: bash github git-bash github-actions building-github-actions


【解决方案1】:

向 Github 操作添加额外步骤:

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

也许这行得通?

找到此信息here

【讨论】:

    【解决方案2】:

    我改成bash,用https://www.shellcheck.net/修改所有问题,尝试如下:

    #!/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
    

    【讨论】:

      猜你喜欢
      • 2015-06-29
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 2018-07-19
      • 2011-03-24
      相关资源
      最近更新 更多