Skip to content

Commit

Permalink
ci: #90 add CI workflow (#132)
Browse files Browse the repository at this point in the history
* ci: add build CI job

* fix spotless with: ./gradlew spotlessApply

* rename workflow

* split build into individual tasks

* fix concurrency

* spotless apply

* java version into variable

* add provider test

* env variable for java distribution

* add descriptions and remove duplicated tasks
  • Loading branch information
miquelbeltran authored Jan 14, 2025
1 parent d690e7e commit 1302ff6
Show file tree
Hide file tree
Showing 28 changed files with 406 additions and 372 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "CI"

on: [push]

# Cancel running job if a new push is made to the same branch
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
JAVA_VERSION: 17
# See https://github.com/actions/setup-java?tab=readme-ov-file#supported-distributions
JAVA_DISTRIBUTION: 'adopt'

jobs:
spotless:
name: "Spotless"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- run: ./gradlew spotlessCheck

app-lint:
name: "app:lint"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- run: ./gradlew app:lint

provider-lint:
name: "provider:lint"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- run: ./gradlew provider:lint

app-assemble-debug:
name: "app:assembleDebug"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- run: ./gradlew app:assembleDebug

provider-assemble-debug:
name: "provider:assembleDebug"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- run: ./gradlew provider:assembleDebug

provider-test:
name: "provider:test"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- run: ./gradlew provider:test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.ComponentName;
import android.content.Intent;
import android.os.Build;

import com.google.gson.Gson;
import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage;
Expand All @@ -13,7 +12,6 @@
import com.raygun.raygun4android.utils.RaygunFileFilter;
import com.raygun.raygun4android.utils.RaygunFileUtils;
import com.raygun.raygun4android.utils.RaygunUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -70,7 +68,7 @@ static void clearBreadcrumbs() {
}

private static RaygunBreadcrumbMessage processBreadcrumbLocation(
RaygunBreadcrumbMessage breadcrumb, boolean shouldProcessBreadcrumbLocation) {
RaygunBreadcrumbMessage breadcrumb, boolean shouldProcessBreadcrumbLocation) {

if (shouldProcessBreadcrumbLocation && breadcrumb.getClassName() == null) {

Expand All @@ -83,7 +81,7 @@ private static RaygunBreadcrumbMessage processBreadcrumbLocation(
StackTraceElement nextFrame = trace[i + 1];

if (thisFrame.getClassName().contains("com.raygun.raygun4android.")
&& !nextFrame.getClassName().contains("com.raygun.raygun4android.")) {
&& !nextFrame.getClassName().contains("com.raygun.raygun4android.")) {
frame = nextFrame;
break;
}
Expand All @@ -92,13 +90,13 @@ private static RaygunBreadcrumbMessage processBreadcrumbLocation(

if (frame != null) {
return new RaygunBreadcrumbMessage.Builder(breadcrumb.getMessage())
.category(breadcrumb.getCategory())
.customData(breadcrumb.getCustomData())
.level(breadcrumb.getLevel())
.className(frame.getClassName())
.methodName(frame.getMethodName())
.lineNumber(frame.getLineNumber())
.build();
.category(breadcrumb.getCategory())
.customData(breadcrumb.getCustomData())
.level(breadcrumb.getLevel())
.className(frame.getClassName())
.methodName(frame.getMethodName())
.lineNumber(frame.getLineNumber())
.build();
}
}

Expand Down Expand Up @@ -141,23 +139,23 @@ static void send(Throwable throwable, List tags, Map customData) {
postCachedMessages();
} else {
RaygunLogger.w(
"Crash Reporting is not enabled, please enable to use the send() function");
"Crash Reporting is not enabled, please enable to use the send() function");
}
}

private static RaygunMessage buildMessage(Throwable throwable) {
try {
RaygunMessage msg =
RaygunMessageBuilder.instance()
.setEnvironmentDetails(RaygunClient.getApplicationContext())
.setMachineName(Build.MODEL)
.setExceptionDetails(throwable)
.setClientDetails()
.setAppContext(RaygunClient.getAppContextIdentifier())
.setVersion(RaygunClient.getVersion())
.setNetworkInfo(RaygunClient.getApplicationContext())
.setBreadcrumbs(breadcrumbs)
.build();
RaygunMessageBuilder.instance()
.setEnvironmentDetails(RaygunClient.getApplicationContext())
.setMachineName(Build.MODEL)
.setExceptionDetails(throwable)
.setClientDetails()
.setAppContext(RaygunClient.getAppContextIdentifier())
.setVersion(RaygunClient.getVersion())
.setNetworkInfo(RaygunClient.getApplicationContext())
.setBreadcrumbs(breadcrumbs)
.build();

if (RaygunClient.getVersion() != null) {
msg.getDetails().setVersion(RaygunClient.getVersion());
Expand Down Expand Up @@ -187,24 +185,24 @@ static void attachExceptionHandler() {
static void postCachedMessages() {
if (RaygunNetworkUtils.hasInternetConnection(RaygunClient.getApplicationContext())) {
File[] fileList =
RaygunClient.getApplicationContext()
.getCacheDir()
.listFiles(new RaygunFileFilter());
RaygunClient.getApplicationContext()
.getCacheDir()
.listFiles(new RaygunFileFilter());
if (fileList != null) {
for (File f : fileList) {
try {
if (RaygunFileUtils.getExtension(f.getName())
.equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) {
.equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(f));
SerializedMessage serializedMessage =
(SerializedMessage) ois.readObject();
(SerializedMessage) ois.readObject();
enqueueWorkForCrashReportingService(
RaygunClient.getApiKey(), serializedMessage.message);
RaygunClient.getApiKey(), serializedMessage.message);
if (!f.delete()) {
RaygunLogger.w(
"Couldn't delete cached report (" + f.getName() + ")");
"Couldn't delete cached report (" + f.getName() + ")");
}
} finally {
if (ois != null) {
Expand All @@ -214,33 +212,33 @@ static void postCachedMessages() {
}
} catch (FileNotFoundException e) {
RaygunLogger.e(
"Error loading cached message from filesystem - " + e.getMessage());
"Error loading cached message from filesystem - " + e.getMessage());
} catch (IOException e) {
RaygunLogger.e(
"Error reading cached message from filesystem - " + e.getMessage());
"Error reading cached message from filesystem - " + e.getMessage());
} catch (ClassNotFoundException e) {
RaygunLogger.e(
"Error in handling cached message from filesystem - "
+ e.getMessage());
"Error in handling cached message from filesystem - "
+ e.getMessage());
}
}
} else {
RaygunLogger.e(
"Error in handling cached message from filesystem - could not get a list of"
+ " files from cache dir");
"Error in handling cached message from filesystem - could not get a list of"
+ " files from cache dir");
}
}
}

private static void enqueueWorkForCrashReportingService(String apiKey, String jsonPayload) {
Intent intent =
new Intent(RaygunClient.getApplicationContext(), CrashReportingPostService.class);
new Intent(RaygunClient.getApplicationContext(), CrashReportingPostService.class);
intent.setAction(
"com.raygun.raygun4android.intent.action.LAUNCH_CRASHREPORTING_POST_SERVICE");
"com.raygun.raygun4android.intent.action.LAUNCH_CRASHREPORTING_POST_SERVICE");
intent.setPackage("com.raygun.raygun4android");
intent.setComponent(
new ComponentName(
RaygunClient.getApplicationContext(), CrashReportingPostService.class));
new ComponentName(
RaygunClient.getApplicationContext(), CrashReportingPostService.class));

intent.putExtra("msg", jsonPayload);
intent.putExtra("apikey", apiKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.raygun.raygun4android;

import android.content.Context;

import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage;
import com.raygun.raygun4android.messages.crashreporting.RaygunMessage;

import java.util.List;
import java.util.Map;

Expand Down
Loading

0 comments on commit 1302ff6

Please sign in to comment.