Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit d8baf61

Browse files
authored
Replace use_apk_signer with signer_tool step input (bitrise-steplib#88)
* Replace use_apk_signer with signer_tool step input * Rename and reorder e2e test workflows * Test signer_tool input * Update e2e test titles * Fix signer tool env var in tests * Fix signertool validation
1 parent 45b6a2b commit d8baf61

File tree

3 files changed

+148
-99
lines changed

3 files changed

+148
-99
lines changed

e2e/bitrise.yml

+106-87
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ app:
66
- TEST_APP_REPO: https://github.com/bitrise-io/sample-apps-android-abi-split.git
77
- TEST_APP_BRANCH: master
88
- TEST_APP_GRADLE_WRAPPER_PATH: ./gradlew
9+
- ORIG_SIGNER_TOOL: automatic
910
# define these in your .bitrise.secrets.yml
1011
# Keystore password == key password
1112
- SAME_PASS_ANDROID_KEYSTORE_URL: $SAME_PASS_ANDROID_KEYSTORE_URL
@@ -29,69 +30,140 @@ app:
2930
- STUDIO_GEN_ANDROID_KEY_PASSWORD: $STUDIO_GEN_ANDROID_KEY_PASSWORD
3031

3132
workflows:
32-
test_apk:
33+
test_apk_signing:
3334
envs:
3435
- TEST_APP_GRADLE_TASK: assembleRelease
3536
- APK_FILE_INCLUDE_FILTER: "*.apk"
3637
after_run:
37-
- _run_collection
38+
- _build_app_and_sign_with_keystore_combinations
3839

3940
# Using apksigner zipalign fails to zipalign already zipaligned artifact
40-
test_apk_debug:
41+
test_debug_apk_signing:
4142
envs:
4243
- TEST_APP_GRADLE_TASK: assembleDebug
4344
- APK_FILE_INCLUDE_FILTER: "*.apk"
4445
after_run:
45-
- _run_collection
46+
- _build_app_and_sign_with_keystore_combinations
4647

47-
test_bundle:
48+
test_app_bundle_signing:
4849
envs:
4950
- TEST_APP_GRADLE_TASK: bundleRelease
5051
- APK_FILE_INCLUDE_FILTER: "*.aab"
5152
after_run:
52-
- _run_collection
53+
- _build_app_and_sign_with_keystore_combinations
5354

54-
utility_test_same_pass:
55-
title: Step Test - keystore pass == key pass
55+
_build_app_and_sign_with_keystore_combinations:
56+
steps:
57+
- set-java-version:
58+
inputs:
59+
- set_java_version: 17
60+
- script:
61+
inputs:
62+
- content: |-
63+
#!/usr/bin/env bash
64+
set -ex
65+
rm -rf ./_tmp
66+
- change-workdir:
67+
title: Switch working dir to test/_tmp dir
68+
inputs:
69+
- path: ./_tmp
70+
- is_create_path: true
71+
- git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git:
72+
inputs:
73+
- repository_url: $TEST_APP_REPO
74+
- clone_into_dir: .
75+
- branch: $TEST_APP_BRANCH
76+
- install-missing-android-tools:
77+
inputs:
78+
- gradlew_path: $TEST_APP_GRADLE_WRAPPER_PATH
79+
- ndk_revision: 16
80+
run_if: .IsCI
81+
- script:
82+
inputs:
83+
- content: |-
84+
#!/usr/bin/env bash
85+
set -ex
86+
envman unset --key BITRISE_APK_PATH
87+
envman unset --key BITRISE_AAB_PATH
88+
- gradle-runner:
89+
inputs:
90+
- gradle_task: $TEST_APP_GRADLE_TASK
91+
- gradlew_path: $TEST_APP_GRADLE_WRAPPER_PATH
92+
- app_file_include_filter: $APK_FILE_INCLUDE_FILTER
93+
- script:
94+
inputs:
95+
- content: |-
96+
#!/usr/bin/env bash
97+
set -ex
98+
if [ -n "$BITRISE_APK_PATH" ]; then
99+
envman add --key ORIG_BITRISE_APK_PATH --value ${BITRISE_APK_PATH}
100+
fi
101+
after_run:
102+
- _sign_with_jarsigner_with_keystore_with_same_pass
103+
- _sign_with_apksigner_with_keystore_with_diff_pass
104+
- _sign_with_keystore_with_default_alias
105+
- _sign_with_studio_gen_keystore
106+
- _sign_with_custom_artifact_name
107+
108+
_sign_with_jarsigner_with_keystore_with_same_pass:
109+
title: Step Test - keystore pass == key pass - jarsigner
56110
envs:
57111
- KEYSTORE_URL: $SAME_PASS_ANDROID_KEYSTORE_URL
58112
- KEYSTORE_PASSWORD: $SAME_PASS_ANDROID_KEYSTORE_PASSWORD
59113
- KEYSTORE_ALIAS: $SAME_PASS_ANDROID_KEY_ALIAS
60114
- KEY_PASSWORD: $SAME_PASS_ANDROID_KEY_PASSWORD
115+
- SIGNER_TOOL: jarsigner
61116
after_run:
62-
- _run
117+
- _setup_signer_tool_env_var
118+
- _sign_app
119+
- _reset_signer_tool_env_var
63120

64-
utility_test_diff_pass:
65-
title: Step Test - keystore pass != key pass
121+
_sign_with_apksigner_with_keystore_with_diff_pass:
122+
title: Step Test - keystore pass != key pass - apksigner for APK files
66123
envs:
67124
- KEYSTORE_URL: $DIFF_PASS_ANDROID_KEYSTORE_URL
68125
- KEYSTORE_PASSWORD: $DIFF_PASS_ANDROID_KEYSTORE_PASSWORD
69126
- KEYSTORE_ALIAS: $DIFF_PASS_ANDROID_KEY_ALIAS
70127
- KEY_PASSWORD: $DIFF_PASS_ANDROID_KEY_PASSWORD
128+
steps:
129+
- script:
130+
inputs:
131+
- content: |-
132+
#!/usr/bin/env bash
133+
set -ex
134+
if [ -z "$BITRISE_AAB_PATH" ]; then
135+
envman add --key SIGNER_TOOL --value "apksigner"
136+
fi
71137
after_run:
72-
- _run
138+
- _setup_signer_tool_env_var
139+
- _sign_app
140+
- _reset_signer_tool_env_var
73141

74-
utility_test_default_alias:
142+
_sign_with_keystore_with_default_alias:
75143
title: Step Test - default alias
76144
envs:
77145
- KEYSTORE_URL: $DEFAULT_ALIAS_ANDROID_KEYSTORE_URL
78146
- KEYSTORE_PASSWORD: $DEFAULT_ALIAS_ANDROID_KEYSTORE_PASSWORD
79147
- KEYSTORE_ALIAS: $DEFAULT_ALIAS_ANDROID_KEY_ALIAS
80148
- KEY_PASSWORD: $DEFAULT_ALIAS_ANDROID_KEY_PASSWORD
81149
after_run:
82-
- _run
150+
- _setup_signer_tool_env_var
151+
- _sign_app
152+
- _reset_signer_tool_env_var
83153

84-
utility_test_studio_gen_keystore:
154+
_sign_with_studio_gen_keystore:
85155
title: Step Test - android studio generated keystore (jks)
86156
envs:
87157
- KEYSTORE_URL: $STUDIO_GEN_ANDROID_KEYSTORE_URL
88158
- KEYSTORE_PASSWORD: $STUDIO_GEN_ANDROID_KEYSTORE_PASSWORD
89159
- KEYSTORE_ALIAS: $STUDIO_GEN_ANDROID_KEY_ALIAS
90160
- KEY_PASSWORD: $STUDIO_GEN_ANDROID_KEY_PASSWORD
91161
after_run:
92-
- _run
162+
- _setup_signer_tool_env_var
163+
- _sign_app
164+
- _reset_signer_tool_env_var
93165

94-
utility_test_custom_artifact_name:
166+
_sign_with_custom_artifact_name:
95167
title: Step Test - android studio generated keystore (jks) + custom artifact name
96168
envs:
97169
- KEYSTORE_URL: $STUDIO_GEN_ANDROID_KEYSTORE_URL
@@ -100,10 +172,12 @@ workflows:
100172
- KEY_PASSWORD: $STUDIO_GEN_ANDROID_KEY_PASSWORD
101173
- OUTPUT_NAME: test-artifact-name
102174
after_run:
103-
- _run
104-
- utility_test_custom_artifact_name_again
175+
- _setup_signer_tool_env_var
176+
- _sign_app
177+
- _sign_with_custom_artifact_name_again
178+
- _reset_signer_tool_env_var
105179

106-
utility_test_custom_artifact_name_again:
180+
_sign_with_custom_artifact_name_again:
107181
title: Step Test - android studio generated keystore (jks) + custom artifact name second time to see collisions if any
108182
envs:
109183
- KEYSTORE_URL: $STUDIO_GEN_ANDROID_KEYSTORE_URL
@@ -112,9 +186,11 @@ workflows:
112186
- KEY_PASSWORD: $STUDIO_GEN_ANDROID_KEY_PASSWORD
113187
- OUTPUT_NAME: test-artifact-name
114188
after_run:
115-
- _run
189+
- _setup_signer_tool_env_var
190+
- _sign_app
191+
- _reset_signer_tool_env_var
116192

117-
_run:
193+
_sign_app:
118194
steps:
119195
- set-java-version:
120196
inputs:
@@ -135,81 +211,24 @@ workflows:
135211
- keystore_alias: $KEYSTORE_ALIAS
136212
- private_key_password: $KEY_PASSWORD
137213
- output_name: $OUTPUT_NAME
138-
- use_apk_signer: $APK_SIGNER
214+
- signer_tool: $SIGNER_TOOL
139215

140-
_run_collection:
216+
_setup_signer_tool_env_var:
141217
steps:
142-
- set-java-version:
143-
inputs:
144-
- set_java_version: 17
145-
- script:
146-
inputs:
147-
- content: |-
148-
#!/usr/bin/env bash
149-
set -ex
150-
rm -rf ./_tmp
151-
- change-workdir:
152-
title: Switch working dir to test/_tmp dir
153-
inputs:
154-
- path: ./_tmp
155-
- is_create_path: true
156-
- git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git:
157-
inputs:
158-
- repository_url: $TEST_APP_REPO
159-
- clone_into_dir: .
160-
- branch: $TEST_APP_BRANCH
161-
- install-missing-android-tools:
162-
inputs:
163-
- gradlew_path: $TEST_APP_GRADLE_WRAPPER_PATH
164-
- ndk_revision: 16
165-
run_if: .IsCI
166218
- script:
167219
inputs:
168220
- content: |-
169221
#!/usr/bin/env bash
170222
set -ex
171-
envman unset --key BITRISE_APK_PATH
172-
envman unset --key BITRISE_AAB_PATH
173-
- gradle-runner:
174-
inputs:
175-
- gradle_task: $TEST_APP_GRADLE_TASK
176-
- gradlew_path: $TEST_APP_GRADLE_WRAPPER_PATH
177-
- app_file_include_filter: $APK_FILE_INCLUDE_FILTER
178-
- script:
179-
inputs:
180-
- content: |-
181-
#!/usr/bin/env bash
182-
set -ex
183-
if [ -n "$BITRISE_APK_PATH" ]; then
184-
envman add --key ORIG_BITRISE_APK_PATH --value ${BITRISE_APK_PATH}
223+
if [ -z "$SIGNER_TOOL" ]; then
224+
envman add --key SIGNER_TOOL --value "$ORIG_SIGNER_TOOL"
185225
fi
186-
after_run:
187-
- _jarsigner_all_tests
188-
- _apksigner_all_tests
189-
_jarsigner_all_tests:
190-
steps:
191-
- script:
192-
inputs:
193-
- content: |-
194-
echo "jarsigner"
195-
envman add --key APK_SIGNER --value "false"
196-
after_run:
197-
- _all_keystore_tests
198226
199-
_apksigner_all_tests:
227+
_reset_signer_tool_env_var:
200228
steps:
201229
- script:
202230
inputs:
203231
- content: |-
204-
echo "apksigner"
205-
envman add --key APK_SIGNER --value "true"
206-
after_run:
207-
- _all_keystore_tests
208-
209-
_all_keystore_tests:
210-
after_run:
211-
- utility_test_same_pass
212-
- utility_test_diff_pass
213-
- utility_test_default_alias
214-
- utility_test_studio_gen_keystore
215-
- utility_test_custom_artifact_name
232+
#!/usr/bin/env bash
233+
set -ex
234+
envman unset --key SIGNER_TOOL

main.go

+31-7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,20 @@ type configs struct {
3838
PageAlign string `env:"page_align,opt[automatic,true,false]"`
3939
SignerScheme string `env:"signer_scheme,opt[automatic,v2,v3,v4]"`
4040
DebuggablePermitted string `env:"debuggable_permitted,opt[true,false]"`
41-
UseAPKSigner bool `env:"use_apk_signer,opt[true,false]"`
41+
SignerTool string `env:"signer_tool,opt[automatic,apksigner,jarsigner]"`
4242

4343
// Deprecated
4444
APKPath string `env:"apk_path"`
4545
}
4646

47+
type codeSignerTool string
48+
49+
const (
50+
apksignerSignerTool codeSignerTool = "apksigner"
51+
jarsignerSignerTool codeSignerTool = "jarsigner"
52+
automaticSignerTool codeSignerTool = "automatic"
53+
)
54+
4755
type pageAlignStatus int
4856

4957
const (
@@ -230,6 +238,12 @@ func validate(cfg configs) error {
230238
} else if !exist {
231239
return fmt.Errorf("BuildArtifactPath not exist at: %s", buildArtifactPath)
232240
}
241+
242+
artifactExt := path.Ext(buildArtifactPath)
243+
signAAB := strings.EqualFold(artifactExt, ".aab")
244+
if cfg.SignerTool == "apksigner" && signAAB {
245+
failf("signer tool apksigner does not support signing AABs, please use automatic or jarsigner instead")
246+
}
233247
}
234248
return nil
235249
}
@@ -338,8 +352,16 @@ func main() {
338352
}
339353

340354
signAAB := strings.EqualFold(artifactExt, ".aab")
355+
signerTool := cfg.SignerTool
356+
if signerTool == string(automaticSignerTool) {
357+
if signAAB {
358+
signerTool = string(jarsignerSignerTool)
359+
} else {
360+
signerTool = string(apksignerSignerTool)
361+
}
362+
}
341363

342-
if signAAB || !cfg.UseAPKSigner {
364+
if signerTool == string(jarsignerSignerTool) {
343365
isSigned, err := isBuildArtifactSigned(aapt, unsignedBuildArtifactPth)
344366
if err != nil {
345367
failf("Run: failed to check if build artifact is signed: %s", err)
@@ -359,14 +381,16 @@ func main() {
359381
log.Printf("Skipping removal of existing signature as apksigner can re-sign already signed apk.")
360382
}
361383

384+
var fullPath string
385+
if signerTool == string(apksignerSignerTool) {
386+
fullPath = signAPK(zipalign, unsignedBuildArtifactPth, buildArtifactDir, buildArtifactBasename, artifactExt, cfg.OutputName, apkSigner, pageAlignConfig)
387+
} else {
388+
fullPath = signJarSigner(zipalign, tmpDir, unsignedBuildArtifactPth, buildArtifactDir, buildArtifactBasename, artifactExt, cfg.PrivateKeyPassword, cfg.OutputName, keystore, pageAlignConfig)
389+
}
390+
362391
if signAAB {
363-
fullPath := signJarSigner(zipalign, tmpDir, unsignedBuildArtifactPth, buildArtifactDir, buildArtifactBasename, artifactExt, cfg.PrivateKeyPassword, cfg.OutputName, keystore, pageAlignConfig)
364392
signedAABPaths = append(signedAABPaths, fullPath)
365-
} else if cfg.UseAPKSigner {
366-
fullPath := signAPK(zipalign, unsignedBuildArtifactPth, buildArtifactDir, buildArtifactBasename, artifactExt, cfg.OutputName, apkSigner, pageAlignConfig)
367-
signedAPKPaths = append(signedAPKPaths, fullPath)
368393
} else {
369-
fullPath := signJarSigner(zipalign, tmpDir, unsignedBuildArtifactPth, buildArtifactDir, buildArtifactBasename, artifactExt, cfg.PrivateKeyPassword, cfg.OutputName, keystore, pageAlignConfig)
370394
signedAPKPaths = append(signedAPKPaths, fullPath)
371395
}
372396

step.yml

+11-5
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,20 @@ inputs:
103103
- `automatic`: Enable page alignment for .so files, unless atribute `extractNativeLibs="true"` is set in the AndroidManifest.xml
104104
- `true`: Enable memory page alignment for .so files
105105
- `false`: Disable memory page alignment for .so files
106-
- use_apk_signer: "false"
106+
- signer_tool: automatic
107107
opts:
108-
title: Enables apksigner
109-
description: Indicates if the signature should be done using `apksigner` instead of `jarsigner`.
108+
title: Signer tool
110109
is_required: true
111110
value_options:
112-
- "true"
113-
- "false"
111+
- automatic
112+
- apksigner
113+
- jarsigner
114+
description: |
115+
Indicates which tool should be used for signing the app.
116+
117+
- `automatic`: Uses the `apksigner` tool to sign an APK and `jarsigner` tool to sign an AAB file.
118+
- `apksigner`: Uses the `apksigner` tool to sign the app.
119+
- `jarsigner`: Uses the `jarsigner` tool to sign the app.
114120
- signer_scheme: automatic
115121
opts:
116122
title: APK Signature Scheme

0 commit comments

Comments
 (0)