Llevo un par de días sin lograr resolvver un error que me lanza GitHub Actions cuando intento ejecutar el siguiente script bash:
#!/bin/bash -e
declare -A versionNameUpdateLevels=(["major"]=0 ["minor"]=1 ["security"]=2)
variant=${VARIANT,,}
shouldUpdateVersionName=${SHOULD_UPDATE_VERSION_NAME}
versionNameUpdateLevel=${VERSION_NAME_UPDATE_LEVEL,,}
versionFile="${GITHUB_WORKSPACE}/version.gradle"
echo "Verifying current version info"
mapfile -t < ${versionFile}
IFS=":" read -a previousVersionCodeArray <<<${MAPFILE[2]}
previousVersionCode=${previousVersionCodeArray[1]:1:-1}
IFS=":" read -a previousVersionNameArray <<<${MAPFILE[3]}
previousVersionName=${previousVersionNameArray[1]:2:-1}
echo ::set-output name=previous-version-code::"${previousVersionCode}"
echo ::set-output name=previous-version-name::"${previousVersionName}"
if [[ "${variant}" == "debug" ]]; then
echo "Debug variants should not be updated"
exit 0
fi
echo "Updating version info"
if [[ "${shouldUpdateVersionName}" == true ]]; then
if ! [[ -n "${versionNameUpdateLevels[$versionNameUpdateLevel]}" ]]; then
echo "Invalid versionNameUpdateLevel, possible values are 'security', 'minor' or 'major'"
exit 1
fi
fi
updatedVersionCode="$((previousVersionCode+1))"
IFS="." read -a versionNameArray <<<${previousVersionName}
majorLevel=${versionNameArray[0]}
minorLevel=${versionNameArray[1]}
securityLevel=${versionNameArray[2]}
if [[ "${versionNameUpdateLevel}" == "major" ]]; then
majorLevel=$((majorLevel+1))
minorLevel=0
securityLevel=0
elif [[ "${versionNameUpdateLevel}" == "minor" ]]; then
minorLevel=$((minorLevel+1))
securityLevel=0
else
securityLevel=$((securityLevel+1))
fi
updatedVersionName="${majorLevel}.${minorLevel}.${securityLevel}"
rm -rf ${versionFile}
touch ${versionFile}
echo "ext {" >> ${versionFile}
echo " app = [" >> ${versionFile}
echo " versionCode: ${updatedVersionCode}," >> ${versionFile}
echo " versionName: \"${updatedVersionName}\"" >> ${versionFile}
echo " ]" >> ${versionFile}
echo "}" >> ${versionFile}
echo ::set-output name=updated-version-code::"${updatedVersionCode}"
echo ::set-output name=updated-version-name="${updatedVersionName}"
commitMsg="${variant~} version cut ${updatedVersionName} build ${updatedVersionCode}"
echo ::set-output name=version-info-commit-msg::"${commitMsg}"
echo "Done"
exit 0
El archivo version.gradle que intento generar se debe ve así:
ext {
app = [
versionCode: ###,
versionName: "#.#.#"
]
}
Logro ejecutar el script sin problemas desde mi workflow pero me da este error:
/home/runner/work/_temp/71abcf83-5b27-43c7-aca0-66c1bdab4a2a.sh: line 1: unexpected EOF while looking for matching `]' Error: Process completed with exit code 2.
Ya revisé todos los corchetes ']' de mi script y no veo nada mal, igual simulé las env localmente y el script si funciona como debe usando WSL2 y Ubuntu 2020.4, hay algo que esté pasando por alto?