Skip to content

Commit

Permalink
Simplify arguments (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeReaper authored Jul 6, 2022
1 parent eb577e8 commit 64834b5
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 261 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
MAIN=$(cat branch-main/version)
VERSION=$(cat version)
sh lane.d/shell-github-action-semver-compare "$MAIN" "$VERSION"
sh lane.d/shell-github-action-semver-compare -m "$MAIN" -c "$VERSION"
- name: Output version
id: version
Expand Down Expand Up @@ -56,9 +56,14 @@ jobs:
run: |
VERSION='${{ needs.version-check.outputs.version }}'
printf '#!/bin/sh\nVERSION=''%s''\n' "$VERSION" > bundle/lane
tail +4 lane >> bundle/lane
tail +2 lane >> bundle/lane
chmod +x bundle/lane
- name: Verify version-injected-lane
run: |
sh bundle/lane -v | grep -iv unreleased
[ $? -eq 0 ] || exit 1
- name: Package files
run: |
VERSION=$(cat version)
Expand Down
126 changes: 43 additions & 83 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ jobs:
diff -q 1 2 || { echo "Unexpected difference:"; diff 1 2; exit 1; }
diff -q 2 3 || { echo "Unexpected difference:"; diff 2 3; exit 1; }
- name: Test missing lanes directory
run: |
rm -rf lanes
set +e
sh ./lane > /dev/null
[ $? -eq 2 ] || exit 1
- name: Test missing lane
run: |
rm -rf lanes
Expand Down Expand Up @@ -126,45 +118,48 @@ jobs:
run: |
mkdir ./empty-folder
- name: Test missing argument
- name: Test missing arguments
run: |
set +e
sh lane.d/mobile-static-resources-images > /dev/null
[ $? -eq 1 ] || exit 1
[ $? -eq 2 ] || exit 1
- name: Test non-existing ini file
- name: Test missing input file
run: |
set +e
sh lane.d/mobile-static-resources-images ./non-existing.file > /dev/null
[ $? -eq 1 ] || exit 1
sh lane.d/mobile-static-resources-images -o result > /dev/null
[ $? -eq 2 ] || exit 1
- name: Test empty asset folder
- name: Test missing output file
run: |
echo 'INPUT=./empty-folder/' > ini
echo 'OUTPUT=./result' >> ini
set +e
sh lane.d/mobile-static-resources-images -i input > /dev/null
[ $? -eq 2 ] || exit 1
- name: Test non-existing input folder
run: |
set +e
sh lane.d/mobile-static-resources-images -i ./non-existing-folder -o result > /dev/null
[ $? -eq 3 ] || exit 1
- name: Test empty asset folder
run: |
set +e
sh lane.d/mobile-static-resources-images ini
sh lane.d/mobile-static-resources-images -i empty-folder -o result
[ $? -eq 0 ] || exit 1
diff -q .github/test-resources/mobile-static-resources-images/empty.swift result > /dev/null || { echo "Unexpected difference:"; diff .github/test-resources/mobile-static-resources-images/empty.swift result; exit 1; }
- name: Test with asset folder
run: |
echo 'INPUT=.github/test-resources/mobile-static-resources-images/assets' > ini
echo 'OUTPUT=./result' >> ini
set +e
sh lane.d/mobile-static-resources-images ini
sh lane.d/mobile-static-resources-images -i .github/test-resources/mobile-static-resources-images/assets -o result
[ $? -eq 0 ] || exit 1
diff -q .github/test-resources/mobile-static-resources-images/assets.swift result > /dev/null || { echo "Unexpected difference:"; diff .github/test-resources/mobile-static-resources-images/assets.swift result; exit 1; }
- name: Test creating output folder
run: |
echo 'INPUT=./empty-folder/' > ini
echo 'OUTPUT=./will/be/created' >> ini
set +e
sh lane.d/mobile-static-resources-images ini
sh lane.d/mobile-static-resources-images -i empty-folder -o will/be/created
[ $? -eq 0 ] || exit 1
[ -d "./will/be" ] || { echo "Output folder was not created"; exit 1; }
Expand All @@ -178,85 +173,51 @@ jobs:
run: |
set +e
sh lane.d/mobile-update-translations > /dev/null
[ $? -eq 1 ] || exit 1
- name: Test non-existing ini file
run: |
set +e
sh lane.d/mobile-update-translations ./non-existing.file > /dev/null
[ $? -eq 1 ] || exit 1
[ $? -eq 2 ] || exit 1
- name: Test missing configuration for missing input
run: |
echo 'MAIN_LANGUAGE=EN' > ini
echo 'KEY_ROW=1' >> ini
echo 'CONFIGURATION=.github/test-resources/mobile-update-translations/configuration/mapping' >> ini
echo 'OUTPUT=result.swift' >> ini
set +e
sh lane.d/mobile-update-translations ini
[ $? -eq 1 ] || exit 1
sh lane.d/mobile-update-translations -t ios -k 1 -m EN -o result.swift -c "4 DA result.DA.strings" -c "3 EN result.EN.strings"
[ $? -eq 2 ] || exit 1
- name: Test missing configuration for input not a file
run: |
echo 'INPUT=.github/test-resources/' > ini
echo 'MAIN_LANGUAGE=EN' >> ini
echo 'KEY_ROW=1' >> ini
echo 'CONFIGURATION=.github/test-resources/mobile-update-translations/configuration/mapping' >> ini
echo 'OUTPUT=result.swift' >> ini
set +e
sh lane.d/mobile-update-translations ini
[ $? -eq 1 ] || exit 1
sh lane.d/mobile-update-translations -t ios -k 1 -m EN -o result.swift -c "4 DA result.DA.strings" -c "3 EN result.EN.strings" -i .github/test-resources/
[ $? -eq 2 ] || exit 1
- name: Test missing configuration for missing main language
run: |
echo 'INPUT=.github/test-resources/mobile-update-translations/configuration/input.csv' > ini
echo 'KEY_ROW=1' >> ini
echo 'CONFIGURATION=.github/test-resources/mobile-update-translations/configuration/mapping' >> ini
echo 'OUTPUT=result.swift' >> ini
set +e
sh lane.d/mobile-update-translations ini
[ $? -eq 1 ] || exit 1
sh lane.d/mobile-update-translations -t ios -k 1 -o result.swift -c "4 DA result.DA.strings" -c "3 EN result.EN.strings" -i .github/test-resources/mobile-update-translations/configuration/input.csv
[ $? -eq 2 ] || exit 1
- name: Test missing configuration for missing key row
run: |
echo 'INPUT=.github/test-resources/mobile-update-translations/configuration/input.csv' > ini
echo 'MAIN_LANGUAGE=EN' >> ini
echo 'CONFIGURATION=.github/test-resources/mobile-update-translations/configuration/mapping' >> ini
echo 'OUTPUT=result.swift' >> ini
set +e
sh lane.d/mobile-update-translations ini
[ $? -eq 1 ] || exit 1
sh lane.d/mobile-update-translations -t ios -m EN -o result.swift -c "4 DA result.DA.strings" -c "3 EN result.EN.strings" -i .github/test-resources/mobile-update-translations/configuration/input.csv
[ $? -eq 2 ] || exit 1
- name: Test missing configuration for missing output
run: |
echo 'INPUT=.github/test-resources/mobile-update-translations/configuration/input.csv' > ini
echo 'MAIN_LANGUAGE=EN' >> ini
echo 'KEY_ROW=1' >> ini
echo 'CONFIGURATION=.github/test-resources/mobile-update-translations/configuration/mapping' >> ini
set +e
sh lane.d/mobile-update-translations ini
[ $? -eq 1 ] || exit 1
sh lane.d/mobile-update-translations -t ios -k 1 -m EN -c "4 DA result.DA.strings" -c "3 EN result.EN.strings" -i .github/test-resources/mobile-update-translations/configuration/input.csv
[ $? -eq 2 ] || exit 1
- name: Test ios output is created as expected
run: |
set +e
sh lane.d/mobile-update-translations .github/test-resources/mobile-update-translations/configuration/config.ini
sh lane.d/mobile-update-translations -t ios -k 1 -m EN -o result.swift -c "4 DA result.DA.strings" -c "3 EN result.EN.strings" -i .github/test-resources/mobile-update-translations/configuration/input.csv
[ $? -eq 0 ] || exit 1
diff -q .github/test-resources/mobile-update-translations/expected-ios/result.swift result.swift > /dev/null || { echo "Unexpected difference:"; diff .github/test-resources/mobile-update-translations/expected-ios/result.swift result.swift; exit 1; }
diff -q .github/test-resources/mobile-update-translations/expected-ios/result.EN.strings result.EN.strings > /dev/null || { echo "Unexpected difference:"; diff .github/test-resources/mobile-update-translations/expected-ios/result.EN.strings result.EN.strings; exit 1; }
diff -q .github/test-resources/mobile-update-translations/expected-ios/result.DA.strings result.DA.strings > /dev/null || { echo "Unexpected difference:"; diff .github/test-resources/mobile-update-translations/expected-ios/result.DA.strings result.DA.strings; exit 1; }
- name: Test android output is created as expected
run: |
echo android > .github/test-resources/mobile-update-translations/configuration/mapping/.type
set +e
sh lane.d/mobile-update-translations .github/test-resources/mobile-update-translations/configuration/config.ini
sh lane.d/mobile-update-translations -t android -k 1 -c "4 DA result.DA.strings" -c "3 EN result.EN.strings" -i .github/test-resources/mobile-update-translations/configuration/input.csv
[ $? -eq 0 ] || exit 1
diff -q .github/test-resources/mobile-update-translations/expected-android/result.EN.strings result.EN.strings > /dev/null || { echo "Unexpected difference:"; diff .github/test-resources/mobile-update-translations/expected-android/result.EN.strings result.EN.strings; exit 1; }
diff -q .github/test-resources/mobile-update-translations/expected-android/result.DA.strings result.DA.strings > /dev/null || { echo "Unexpected difference:"; diff .github/test-resources/mobile-update-translations/expected-android/result.DA.strings result.DA.strings; exit 1; }
Expand All @@ -271,12 +232,11 @@ jobs:
- name: Test non-existing file
run: |
set +e
sh lane.d/shell-run-github-workflow-tests ./non-existing-file > /dev/null
sh lane.d/shell-run-github-workflow-tests -i ./non-existing-file > /dev/null
[ $? -eq 1 ] || exit 1
- name: Test running tests
run: |
set -e
sh lane.d/shell-run-github-workflow-tests .github/test-resources/shell-run-github-workflow-tests/test.yaml
sh lane.d/shell-run-github-workflow-tests -i .github/test-resources/shell-run-github-workflow-tests/test.yaml
shell-github-action-semver-compare:
name: Test Shell Github Action Semver Compare
Expand All @@ -288,36 +248,36 @@ jobs:
run: |
set +e
sh lane.d/shell-github-action-semver-compare > /dev/null
[ $? -eq 1 ] || exit 1
[ $? -eq 2 ] || exit 1
- name: Test missing main version argument
run: |
set +e
sh lane.d/shell-github-action-semver-compare "" "0.0.0" > /dev/null
[ $? -eq 0 ] || exit 1
sh lane.d/shell-github-action-semver-compare -c "0.0.0" > /dev/null
[ $? -eq 2 ] || exit 1
- name: Test missing current version argument
run: |
set +e
sh lane.d/shell-github-action-semver-compare "0.0.0" "" > /dev/null
[ $? -eq 1 ] || exit 1
sh lane.d/shell-github-action-semver-compare -m "0.0.0" > /dev/null
[ $? -eq 2 ] || exit 1
- name: Test matching versions
run: |
set +e
sh lane.d/shell-github-action-semver-compare "0.0.0" "0.0.0" > /dev/null
sh lane.d/shell-github-action-semver-compare -m "0.0.0" -c "0.0.0" > /dev/null
[ $? -eq 10 ] || exit 1
- name: Test descending versions
run: |
set +e
sh lane.d/shell-github-action-semver-compare "1.2.3" "0.0.0" > /dev/null
sh lane.d/shell-github-action-semver-compare -m "1.2.3" -c "0.0.0" > /dev/null
[ $? -eq 20 ] || exit 1
- name: Test ascending versions
run: |
set +e
sh lane.d/shell-github-action-semver-compare "1.2.3" "3.2.1" > /dev/null
sh lane.d/shell-github-action-semver-compare -m "1.2.3" -c "3.2.1" > /dev/null
[ $? -eq 0 ] || exit 1
shellcheck:
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
yq 4.25.3
jq 1.6
shellcheck 0.8.0
lane 0.0.2
36 changes: 12 additions & 24 deletions lane
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/sh
VERSION='unreleased'
# DANGER: LINES ABOVE MUST BE ALIGNED WITH RELEASE BUILD

set -e
OLD_PWD=$(pwd)
LANED_PWD="${0}.d"

trap 'set +x; cd "$OLD_PWD" >/dev/null 2>&1; rm -rf $TMP >/dev/null 2>&1' 0
trap 'exit 2' 1 2 3 15
Expand All @@ -16,7 +14,7 @@ _DISPLAY_HELP()

_DISPLAY_VERSION()
{
echo "Version: $VERSION"
echo "Version: ${VERSION:-unreleased}"
}

_DISPLAY_LANES()
Expand All @@ -39,31 +37,21 @@ while [ ! -d lanes ] && [ ! "$(pwd)" = '/' ]; do
cd ..
done

if [ ! -d lanes ]; then
echo "Unable to find \`lanes\` working from $OLD_PWD" >&2
exit 2
fi

if [ -z "$1" ]; then
_DISPLAY_LANES
exit 1
fi

LANE_PWD=$(pwd)
LANES_PWD=$(pwd)

if [ -f "${LANE_PWD}/lane.d/$1" ]; then
if [ -z "$2" ]; then
INI=$(basename "$0")
sh "${LANE_PWD}/lane.d/$1" "${LANE_PWD}/lanes/${INI}.ini"
else
LANE="$1"
for TARGET in "${LANED_PWD}/$1" "${LANES_PWD}/lanes/$1"; do
if [ -f "$TARGET" ]; then
shift
sh "${LANE_PWD}/lane.d/$LANE" "$@"
sh "$TARGET" "$@"
exit 0
fi
elif [ -f "${LANE_PWD}/lanes/$1" ]; then
sh "${LANE_PWD}/lanes/$1" "${LANE_PWD}/lanes/${1}.ini"
else
echo "Attempt to run unrecognized lane: '${1}'"
_DISPLAY_LANES
exit 10
fi
done

echo "Attempt to run unrecognized lane: '${1}'"
_DISPLAY_LANES
exit 10
Loading

0 comments on commit 64834b5

Please sign in to comment.