Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: Workflow to upload apk and ipa to TestApp.io app distribution
on: [push, pull_request, workflow_dispatch]
on:
workflow_dispatch:
push:
branches: [main]

jobs:
linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Get sample .apk for test purposes
run: wget https://github.com/testappio/cli/raw/main/sample-apps/sample-app.apk
run: curl -fsSL --max-time 60 -o sample-app.apk https://github.com/testappio/fastlane-plugin-testappio/raw/main/fastlane/sample/sample-app.apk
- name: Upload .apk artifact to TestApp.io app distribution
uses: ./
with:
Expand All @@ -17,23 +20,23 @@ jobs:
file: sample-app.apk
git_release_notes: true
include_git_commit_id: true
release_notes: ""
notify: true
release_notes: "Action CI test"
notify: false

macos:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get sample .ipa for test purposes
run: wget https://github.com/testappio/cli/raw/main/sample-apps/sample-app.ipa
- name: Upload .ipa artifact to TestApp.io app distribution
uses: actions/checkout@v4
- name: Get sample .apk for test purposes (the sample .ipa profile expired in 2022)
run: curl -fsSL --max-time 60 -o sample-app.apk https://github.com/testappio/fastlane-plugin-testappio/raw/main/fastlane/sample/sample-app.apk
- name: Upload .apk artifact from macOS to TestApp.io app distribution
uses: ./
with:
api_token: ${{secrets.TESTAPPIO_API_TOKEN}}
app_id: ${{secrets.TESTAPPIO_APP_ID}}
file: sample-app.ipa
file: sample-app.apk
git_release_notes: false
include_git_commit_id: false
release_notes: "my release notes here..."
notify: true
release_notes: "Action CI test"
notify: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _More info here: [https://help.testapp.io/ta-cli](https://help.testapp.io/ta-cli
| Key | Description | Env Var(s) | Default |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------- | ------- |
| api_token | You can get it from https://portal.testapp.io/profile/tokens | TESTAPPIO_API_TOKEN | |
| app_id | You can get it from your app page at [https://portal.testapp.io/apps](https://portal.testapp.io/apps?action=select-for-integrations) | TESTAPPIO_APP_ID | |
| app_id | You can get it from your app page at [https://portal.testapp.io/apps](https://portal.testapp.io/apps?to=app-integrations&tab=releases) | TESTAPPIO_APP_ID | |
| release | It can be either both or Android or iOS | TESTAPPIO_RELEASE | |
| file | Path to the either Android .APK file or iOS .IPA file | TESTAPPIO_FILE_PATH | |
| release_notes | Manually add the release notes to be displayed for the testers | TESTAPPIO_RELEASE_NOTES | |
Expand Down
8 changes: 3 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ branding:
runs:
using: "composite"
steps:
- run: curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
- run: curl -fLs --connect-timeout 10 --max-time 60 https://github.com/testappio/cli/releases/latest/download/install | bash
shell: bash
- run: chmod +x ${{ github.action_path }}/entrypoint.sh
shell: bash
- run: sh ${{ github.action_path }}/entrypoint.sh
- run: sh "$GITHUB_ACTION_PATH/entrypoint.sh"
env:
INPUT_API_TOKEN: ${{ inputs.api_token }}
TESTAPPIO_API_TOKEN: ${{ inputs.api_token }}
INPUT_APP_ID: ${{ inputs.app_id }}
INPUT_FILE: ${{ inputs.file }}
INPUT_RELEASE_NOTES: ${{ inputs.release_notes }}
Expand Down
53 changes: 40 additions & 13 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
#!/bin/sh

APK_PATH=""
IPA_PATH=""
RELEASE=""
FILE="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"$INPUT_FILE
FILE_EXT=${INPUT_FILE##*.}

if [ "$FILE_EXT" = "apk" ]; then
RELEASE="android"
APK_PATH=$FILE
if [ -z "${TESTAPPIO_API_TOKEN-}" ]; then
printf 'api_token is required.\n' >&2
exit 1
fi
if [ -z "${INPUT_APP_ID-}" ]; then
printf 'app_id is required.\n' >&2
exit 1
fi
unset API_TOKEN

case "$INPUT_FILE" in
*.[Aa][Pp][Kk]) set -- --release=android "--apk=$INPUT_FILE" ;;
*.[Ii][Pp][Aa]) set -- --release=ios "--ipa=$INPUT_FILE" ;;
*)
printf 'file must end in .apk or .ipa.\n' >&2
exit 1
;;
esac

for input in "git_release_notes=${INPUT_GIT_RELEASE_NOTES-}" \
"include_git_commit_id=${INPUT_INCLUDE_GIT_COMMIT_ID-}" \
"notify=${INPUT_NOTIFY-}"; do
name=${input%%=*}
value=${input#*=}
case "$value" in
'') continue ;;
1|[Tt]|[Tt][Rr][Uu][Ee]) value=true ;;
0|[Ff]|[Ff][Aa][Ll][Ss][Ee]) value=false ;;
*)
printf '%s must be true or false.\n' "$name" >&2
exit 1
;;
esac
if [ "$name" = include_git_commit_id ]; then
name=git_commit_id
fi
set -- "$@" "--$name=$value"
done

if [ "$FILE_EXT" = "ipa" ]; then
RELEASE="ios"
IPA_PATH=$FILE
if [ -n "${INPUT_RELEASE_NOTES-}" ]; then
set -- "$@" "--release_notes=$INPUT_RELEASE_NOTES"
fi

ta-cli publish --api_token="$INPUT_API_TOKEN" --app_id="$INPUT_APP_ID" --release="$RELEASE" --apk="$APK_PATH" --ipa="$IPA_PATH" --release_notes="$INPUT_RELEASE_NOTES" --git_release_notes=$INPUT_GIT_RELEASE_NOTES --git_commit_id=$INPUT_INCLUDE_GIT_COMMIT_ID --notify=$INPUT_NOTIFY --source="Github Action"
exec ta-cli publish --app_id="$INPUT_APP_ID" --source="Github Action" "$@"
177 changes: 177 additions & 0 deletions tests/test_entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import json
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
import uuid


ACTION_DIRECTORY = Path(__file__).resolve().parents[1]
ENTRYPOINT = ACTION_DIRECTORY / "entrypoint.sh"


class InstallerTest(unittest.TestCase):
def test_installer_download_has_time_limits(self):
action = (ACTION_DIRECTORY / "action.yml").read_text(encoding="utf-8")
installer = next(line for line in action.splitlines() if "- run: curl " in line)
self.assertRegex(installer, r"--connect-timeout [1-9]\d*")
self.assertRegex(installer, r"--max-time [1-9]\d*")

def test_empty_http_error_stops_the_installer_step(self):
action = (ACTION_DIRECTORY / "action.yml").read_text(encoding="utf-8")
installer = next(line.split("run: ", 1)[1] for line in action.splitlines() if line.lstrip().startswith("- run: curl "))
with tempfile.TemporaryDirectory() as directory:
curl = Path(directory) / "curl"
# An empty HTTP error response succeeds unless curl's fail option is set.
curl.write_text("#!/bin/sh\ncase \"$1\" in -*f*) exit 22 ;; esac\nexit 0\n", encoding="utf-8")
curl.chmod(0o700)

result = subprocess.run(
["bash", "--noprofile", "--norc", "-eo", "pipefail", "-c", installer],
env={"PATH": f"{directory}:/usr/bin:/bin"},
capture_output=True,
text=True,
check=False,
)
self.assertEqual(result.returncode, 22)


class EntrypointTest(unittest.TestCase):
def setUp(self):
self.directory = tempfile.TemporaryDirectory()
self.addCleanup(self.directory.cleanup)
self.workspace = Path(self.directory.name)
self.token = uuid.uuid4().hex
self.capture = self.workspace / "invocation.json"
stub = self.workspace / "ta-cli"
stub.write_text(
"""#!/usr/bin/env python3
import json
import os
import sys

token = os.environ['FIXTURE_TOKEN']
with open(os.environ['FIXTURE_CAPTURE'], 'w') as capture:
json.dump({
'has_token_in_environment': os.environ.get('TESTAPPIO_API_TOKEN') == token,
'has_legacy_token_in_environment': 'API_TOKEN' in os.environ,
'has_token_argument': any(arg == '--api_token' or arg.startswith('--api_token=') or token in arg for arg in sys.argv[1:]),
'argv': [arg for arg in sys.argv[1:] if token not in arg],
}, capture)
sys.exit(int(os.environ.get('FIXTURE_EXIT_STATUS', '0')))
""",
encoding="utf-8",
)
stub.chmod(0o700)

def run_entrypoint(self, file, **inputs):
env = {
"PATH": f"{self.workspace}:{os.environ['PATH']}",
"FIXTURE_TOKEN": self.token,
"FIXTURE_CAPTURE": str(self.capture),
"TESTAPPIO_API_TOKEN": self.token,
"INPUT_APP_ID": "sample-app",
"INPUT_FILE": str(file),
"INPUT_RELEASE_NOTES": 'Notes with "quotes" and $ & *',
**inputs,
}
return subprocess.run(
["sh", ENTRYPOINT], cwd=self.workspace, env=env, capture_output=True, text=True
)

def invocation(self):
return json.loads(self.capture.read_text(encoding="utf-8"))

def test_absolute_apk_is_passed_as_one_argument(self):
file = self.workspace / "with spaces [copy] & more.apk"
file.touch()
self.assertEqual(self.run_entrypoint(file).returncode, 0)
argv = self.invocation()["argv"]
self.assertIn(f"--apk={file}", argv)
self.assertIn("--release=android", argv)
self.assertIn('--release_notes=Notes with "quotes" and $ & *', argv)

def test_relative_ipa_is_passed_as_one_argument(self):
file = Path("relative output.ipa")
(self.workspace / file).touch()
self.assertEqual(self.run_entrypoint(file).returncode, 0)
argv = self.invocation()["argv"]
self.assertIn(f"--ipa={file}", argv)
self.assertIn("--release=ios", argv)

def test_uppercase_artifact_extension_is_accepted(self):
file = self.workspace / "output.IPA"
file.touch()
self.assertEqual(self.run_entrypoint(file).returncode, 0)
self.assertIn(f"--ipa={file}", self.invocation()["argv"])

def test_token_is_in_child_environment_and_absent_from_arguments(self):
self.assertEqual(self.run_entrypoint("app.apk", API_TOKEN=self.token).returncode, 0)
invocation = self.invocation()
self.assertTrue(invocation["has_token_in_environment"])
self.assertFalse(invocation["has_legacy_token_in_environment"])
self.assertFalse(invocation["has_token_argument"])

def test_empty_required_inputs_stop_before_cli_or_ambient_fallback(self):
required_inputs = (
("api_token", "TESTAPPIO_API_TOKEN", "API_TOKEN", self.token),
("app_id", "INPUT_APP_ID", "APP_ID", "ambient-app"),
)
for name, input_var, legacy_var, legacy_value in required_inputs:
with self.subTest(name=name):
self.capture.unlink(missing_ok=True)
result = self.run_entrypoint("app.apk", **{input_var: "", legacy_var: legacy_value})
self.assertNotEqual(result.returncode, 0)
self.assertTrue(name in result.stderr and legacy_value not in result.stderr + result.stdout)
self.assertFalse(self.capture.exists())

def test_empty_booleans_are_omitted(self):
self.assertEqual(self.run_entrypoint("app.apk", INPUT_NOTIFY="").returncode, 0)
argv = self.invocation()["argv"]
for flag in ("git_release_notes", "git_commit_id", "notify"):
with self.subTest(flag=flag):
self.assertFalse(any(arg.startswith(f"--{flag}=") for arg in argv))

def test_empty_release_notes_are_omitted(self):
self.assertEqual(self.run_entrypoint("app.apk", INPUT_RELEASE_NOTES="").returncode, 0)
self.assertFalse(any(arg.startswith("--release_notes=") for arg in self.invocation()["argv"]))

def test_explicit_booleans_are_passed(self):
result = self.run_entrypoint(
"app.apk", INPUT_GIT_RELEASE_NOTES="true", INPUT_INCLUDE_GIT_COMMIT_ID="false", INPUT_NOTIFY="TRUE"
)
self.assertEqual(result.returncode, 0)
argv = self.invocation()["argv"]
self.assertIn("--git_release_notes=true", argv)
self.assertIn("--git_commit_id=false", argv)
self.assertIn("--notify=true", argv)

def test_mixed_case_booleans_are_normalized(self):
result = self.run_entrypoint("app.apk", INPUT_NOTIFY="tRuE", INPUT_GIT_RELEASE_NOTES="fAlSe")
self.assertEqual(result.returncode, 0)
args = self.invocation()["argv"]
self.assertIn("--notify=true", args)
self.assertIn("--git_release_notes=false", args)

def test_each_invalid_boolean_stops_before_invoking_cli(self):
for name in ("git_release_notes", "include_git_commit_id", "notify"):
with self.subTest(name=name):
result = self.run_entrypoint("app.apk", **{f"INPUT_{name.upper()}": "false --unexpected-argument *"})
self.assertNotEqual(result.returncode, 0)
self.assertIn(name, result.stderr)
self.assertNotIn("--unexpected-argument", result.stderr)
self.assertFalse(self.capture.exists())

def test_cli_failure_is_propagated(self):
self.assertEqual(self.run_entrypoint("app.ipa", FIXTURE_EXIT_STATUS="23").returncode, 23)

def test_unsupported_extension_stops_before_invoking_cli(self):
result = self.run_entrypoint("app.zip")
self.assertNotEqual(result.returncode, 0)
self.assertIn(".apk or .ipa", result.stderr)
self.assertFalse(self.capture.exists())


if __name__ == "__main__":
unittest.main()
29 changes: 29 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pathlib import Path
import re
import unittest


WORKFLOW = Path(__file__).resolve().parents[1] / '.github/workflows/main.yml'


class WorkflowTest(unittest.TestCase):
def test_manual_and_main_push_sample_uploads(self):
workflow = WORKFLOW.read_text(encoding='utf-8')
self.assertRegex(workflow, r'(?m)^on:\n workflow_dispatch:\n push:\n branches: \[main\]\n\njobs:$')
base = 'https://github.com/testappio/fastlane-plugin-testappio/raw/main/fastlane/sample'
for job, extension in [('linux', 'apk'), ('macos', 'apk')]:
with self.subTest(job=job):
match = re.search(rf'(?ms)^ {job}:\n(.*?)(?=^ [a-z]+:|\Z)', workflow)
self.assertIsNotNone(match)
steps = match.group(1)
self.assertIn('uses: actions/checkout@v4', steps)
self.assertIn(f'run: curl -fsSL --max-time 60 -o sample-app.{extension} {base}/sample-app.{extension}', steps)
self.assertIn(f'file: sample-app.{extension}', steps)
self.assertRegex(steps, r'(?m)^ notify: false$')
self.assertRegex(steps, r'(?m)^ release_notes: ["\']?Action CI test["\']?$')
self.assertIn('api_token: ${{secrets.TESTAPPIO_API_TOKEN}}', steps)
self.assertIn('app_id: ${{secrets.TESTAPPIO_APP_ID}}', steps)


if __name__ == '__main__':
unittest.main()