Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup simple CI #204

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build

on:
push:
paths-ignore:
- "CONTRIB"
- "LICENSE"
- "PRIVACY"
- "README.md"
pull_request:
branches: [ "master" ]
workflow_dispatch:

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Bazel
uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true

- name: Build
run: |
chmod +x build.sh
./build.sh
- name: Test
run: bazel test :all

- name: Set environments
run: |
{
echo "commit=$(echo ${{ github.sha }} | cut -c-7)"
echo "repo=$(echo ${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/})"
echo "version=v$(grep -o 'android:versionName="[^"]*"' src/main/AndroidManifest.xml | awk -F'"' '{print $2}')"
} >> $GITHUB_ENV
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: ${{ env.repo }}-${{ env.version }}@${{ env.commit }}
path: bazel-bin/*.apk
125 changes: 57 additions & 68 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ android_library(
android_library(
name = "test_deps",
exports = [
artifact("com.google.testparameterinjector:test-parameter-injector"),
artifact("com.google.truth:truth"),
artifact("androidx.test:core"),
artifact("androidx.test:monitor"),
artifact("androidx.test:runner"),
artifact("junit:junit"),
artifact("org.hamcrest:java-hamcrest"),
artifact("org.robolectric:robolectric"),
artifact("org.robolectric:robolectric-annotations"),
artifact("org.robolectric:shadows-core"),
"@maven//:org_robolectric_robolectric",
"@robolectric//bazel:android-all",
"@maven//:org_robolectric_annotations",
"@maven//:org_robolectric_shadows_framework",
"@maven//:com_google_truth_truth",
"@maven//:androidx_test_core",
"@maven//:com_google_testparameterinjector_test_parameter_injector"
],
)

Expand Down Expand Up @@ -119,64 +115,57 @@ java_library(
srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/Utils.java"],
)

#
#android_local_test(
# name = "PermissionsHelperTest",
# srcs = ["src/test/java/com/afwsamples/testdpc/common/PermissionsHelperTest.java"],
# manifest = MANIFEST,
# deps = [
# ":test_deps",
# ":testdpc_lib",
# "@robolectric//bazel:android-all",
# ],
#)
#
#android_local_test(
# name = "AppStatesServiceTest",
# srcs = ["src/test/java/com/afwsamples/testdpc/feedback/AppStatesServiceTest.java"],
# manifest = MANIFEST,
# deps = [
# ":androidx_deps",
# ":test_deps",
# ":testdpc_lib",
# "@robolectric//bazel:android-all",
# ],
#)
#
#android_local_test(
# name = "WifiConfigUtilTest",
# srcs = ["src/test/java/com/afwsamples/testdpc/policy/wifimanagement/WifiConfigUtilTest.java"],
# manifest = MANIFEST,
# deps = [
# ":test_deps",
# ":testdpc_lib",
# "@robolectric//bazel:android-all",
# ],
#)
#
#android_local_test(
# name = "GetProvisioningModeActivityTest",
# srcs = ["src/test/java/com/afwsamples/testdpc/provision/GetProvisioningModeActivityTest.java"],
# manifest = MANIFEST,
# test_class = "com.afwsamples.testdpc.provision.GetProvisioningModeActivityTest",
# deps = [
# ":test_deps",
# ":testdpc_lib",
# ],
#)
#
#android_local_test(
# name = "GetProvisioningModeActivityTest",
# srcs = ["src/test/java/com/afwsamples/testdpc/provision/GetProvisioningModeActivityTest.java"],
# manifest = MANIFEST,
# test_class = "com.afwsamples.testdpc.provision.GetProvisioningModeActivityTest",
# deps = [
# ":test_deps",
# ":testdpc_lib",
# "@maven//:org_robolectric_robolectric",
# "@robolectric//bazel:android-all",
# ],
#)

android_local_test(
name = "PermissionsHelperTest",
srcs = ["src/test/java/com/afwsamples/testdpc/common/PermissionsHelperTest.java"],
manifest = MANIFEST,
deps = [
":test_deps",
":testdpc_lib",
"@robolectric//bazel:android-all",
],
custom_package = "com.afwsamples.testdpc.common"
)

android_local_test(
name = "AppStatesServiceTest",
srcs = ["src/test/java/com/afwsamples/testdpc/feedback/AppStatesServiceTest.java"],
manifest = MANIFEST,
deps = [
":androidx_deps",
":test_deps",
":testdpc_lib",
"@robolectric//bazel:android-all",
],
custom_package = "com.afwsamples.testdpc.feedback"
)

android_local_test(
name = "WifiConfigUtilTest",
srcs = ["src/test/java/com/afwsamples/testdpc/policy/wifimanagement/WifiConfigUtilTest.java"],
manifest = MANIFEST,
deps = [
":test_deps",
":testdpc_lib",
"@robolectric//bazel:android-all",
],
custom_package = "com.afwsamples.testdpc.policy.wifimanagement"
)

android_local_test(
name = "GetProvisioningModeActivityTest",
srcs = ["src/test/java/com/afwsamples/testdpc/provision/GetProvisioningModeActivityTest.java"],
manifest = MANIFEST,
test_class = "com.afwsamples.testdpc.provision.GetProvisioningModeActivityTest",
deps = [
":test_deps",
":testdpc_lib",
"@maven//:org_robolectric_robolectric",
"@robolectric//bazel:android-all",
],
custom_package = "com.afwsamples.testdpc.provision"
)

java_test(
name = "BooleanParserTest",
Expand Down
25 changes: 12 additions & 13 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ android_sdk_repository(
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")

http_archive(
name = "robolectric",
sha256 = "1ea1cfe67848decf959316e80dd69af2bbaa359ae2195efe1366cbdf3e968356",
strip_prefix = "robolectric-bazel-4.11.1",
urls = ["https://github.com/robolectric/robolectric-bazel/releases/download/4.11.1/robolectric-bazel-4.11.1.tar.gz"],
)

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

RULES_JVM_EXTERNAL_TAG = "4.5"

RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"
Expand All @@ -41,6 +30,16 @@ rules_jvm_external_setup()
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@rules_jvm_external//:specs.bzl", "maven")

http_archive(
name = "robolectric",
urls = ["https://github.com/robolectric/robolectric-bazel/archive/4.7.3.tar.gz"],
strip_prefix = "robolectric-bazel-4.7.3",
)

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

maven_install(
name = "maven",
artifacts = [
Expand All @@ -66,16 +65,16 @@ maven_install(
"com.google.android.material:material:1.6.1",
"com.google.guava:guava:31.1-android",
"com.google.testparameterinjector:test-parameter-injector:1.15",
"com.google.truth:truth:1.1.3",
"com.google.errorprone:error_prone_annotations:2.26.1",
"junit:junit:4.13.2",
"javax.inject:javax.inject:1",
"org.hamcrest:java-hamcrest:2.0.0.0",
"org.robolectric:robolectric:4.9.2",
"org.robolectric:robolectric-annotations:3.3.2",
"org.robolectric:shadows-core:3.3.2",
"org.bouncycastle:bcpkix-jdk15on:1.70",
"org.bouncycastle:bcprov-jdk15on:1.70",
"org.robolectric:robolectric:4.2",
"com.google.truth:truth:1.4.2"
],
repositories = [
"https://maven.google.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.os.Build.VERSION_CODES;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Test;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
Expand All @@ -38,9 +39,8 @@
@Config(minSdk = VERSION_CODES.Q)
public class PermissionsHelperTest {

private static final ComponentName TESTDPC_ADMIN =
new ComponentName("com.afwsamples.testdpc", "TestCls");
private static final ComponentName NON_TESTDPC_ADMIN = new ComponentName("TestPkg", "TestCls");
private ComponentName TESTDPC_ADMIN = null;
private ComponentName NON_TESTDPC_ADMIN = null;

private final Context mContext = ApplicationProvider.getApplicationContext();
private final DevicePolicyManager mDevicePolicyManager =
Expand All @@ -53,6 +53,12 @@ public class PermissionsHelperTest {
private static final String NORMAL_PERMISSION = permission.ACCESS_WIFI_STATE;
private static final String MISSING_INFO_PERMISSION = permission.CHANGE_WIFI_STATE;

@Before
public void initialize() {
TESTDPC_ADMIN = new ComponentName("com.afwsamples.testdpc", "TestCls");
NON_TESTDPC_ADMIN = new ComponentName("TestPkg", "TestCls");
}

@Test
public void
ensureRequiredPermissions_ifPermissionMissingFromManifest_shouldReturnFalseAndLogError() {
Expand Down