Detect Android projects
What does this MR do and why?
This MR implements Programmatically collect is_creating_android_app (gitlab-org/growth/team-tasks#574)
It updates Projects::RecordTargetPlatformsWorker
introduced in !80361 (merged) to handle projects that use Java and Kotlin programming languages. If a project uses Java or Kotlin, the worker executes an instance of a new service (Projects::AndroidTargetPlatformDetectorService
) to determine if the project is an Android project by checking if the file AndroidManifest.xml
is present in the project's repository.
This detection is done so we can run experiments on Android projects in gitlab.com (e.g. suggest to project members to use `.gitlab-ci.yml specific for Android projects).
Feature flag
The changes in this MR are behind the detect_android_projects
feature flag with Project
as the actor.
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
Start GDK
Start your GDK simulating gitlab.com
$ export GITLAB_SIMULATE_SAAS=1
gdk start
Enable required feature flags
Feature.enable(:record_projects_target_platforms)
Feature.enable(:detect_android_projects)
Detect target platforms after branch push
-
Create a new project and clone it locally
-
Push a
.java
file to the repo. This will trigger language detection which is required by the android platform detection workerJava code
import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { // Creates a reader instance which takes // input from standard input - keyboard Scanner reader = new Scanner(System.in); System.out.print("Enter a number: "); // nextInt() reads the next integer from the keyboard int number = reader.nextInt(); // println() prints the following line to the output screen System.out.println("You entered: " + number); } }
-
Commit the change and push:
$ git add -A; git commit -m 'add a java file';git push
-
Wait for the language detection to finish
-
Push an
AndroidManifest.xml
file to the repoFile contents
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
# create the dirs $ mkdir app/src/main/ # create the file $ touch app/src/main/AndroidManifest.xml # paste the file contents then save it
-
Commit the change and push:
$ git add -A; git commit -m 'add android manifest file';git push
-
Wait a while for background jobs to finish (you can check by searching
Projects::RecordTargetPlatformsWorker
while runninggdk tail rails-background-jobs
) -
In Rails console, Verify that a
ProjectSetting
record is created withtarget_platforms
value of["android"]
ProjectSetting.find_by_project_id(Project.last.id).target_platforms => ["android"]
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.