Skip to content

Commit d11ee30

Browse files
chore - Incrementing Workflows (#8)
* chore(workflows): updating workflows to allows coverage and badges * chore(docs): updating docs
1 parent 953fff9 commit d11ee30

File tree

3 files changed

+174
-43
lines changed

3 files changed

+174
-43
lines changed

.github/workflows/prerelease.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
permissions:
1717
contents: write
1818
id-token: write
19+
issues: write
20+
pull-requests: write
1921

2022
steps:
2123
- name: Checkout
@@ -57,7 +59,39 @@ jobs:
5759
run: yarn prepare
5860

5961
- name: Run tests
60-
run: yarn test --maxWorkers=2
62+
run: yarn test --coverage --coverageReporters=json-summary,lcov,text --maxWorkers=2
63+
64+
- name: Upload coverage artifact
65+
if: always()
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: coverage-prerelease
69+
path: |
70+
coverage/**
71+
if-no-files-found: warn
72+
73+
- name: Publish coverage summary
74+
if: always()
75+
run: |
76+
if [ -f coverage/coverage-summary.json ]; then
77+
echo "### Test Coverage" >> $GITHUB_STEP_SUMMARY
78+
node -e '
79+
const fs = require("fs");
80+
const s = JSON.parse(fs.readFileSync("coverage/coverage-summary.json", "utf8"));
81+
const t = s.total;
82+
const row = (k,v)=>`| ${k} | ${v.pct}% | ${v.covered}/${v.total} |`;
83+
console.log("| Metric | % | Covered/Total |\n|---|---:|---:|\n" +
84+
[
85+
row("Statements", t.statements),
86+
row("Branches", t.branches),
87+
row("Functions", t.functions),
88+
row("Lines", t.lines)
89+
].join("\n")
90+
);
91+
' >> $GITHUB_STEP_SUMMARY
92+
else
93+
echo "No coverage summary found." >> $GITHUB_STEP_SUMMARY
94+
fi
6195
6296
- name: Publish to NPM (beta tag)
6397
run: |

.github/workflows/publish.yml

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
permissions:
1717
contents: write
1818
id-token: write
19+
issues: write
20+
pull-requests: write
1921

2022
steps:
2123
- name: Checkout
@@ -61,7 +63,39 @@ jobs:
6163

6264
- name: Run tests
6365
if: steps.version-check.outputs.version_changed == 'true'
64-
run: yarn test --maxWorkers=2
66+
run: yarn test --coverage --coverageReporters=json-summary,lcov,text --maxWorkers=2
67+
68+
- name: Upload coverage artifact
69+
if: always()
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: coverage-release
73+
path: |
74+
coverage/**
75+
if-no-files-found: warn
76+
77+
- name: Publish coverage summary
78+
if: always()
79+
run: |
80+
if [ -f coverage/coverage-summary.json ]; then
81+
echo "### Test Coverage" >> $GITHUB_STEP_SUMMARY
82+
node -e '
83+
const fs = require("fs");
84+
const s = JSON.parse(fs.readFileSync("coverage/coverage-summary.json", "utf8"));
85+
const t = s.total;
86+
const row = (k,v)=>`| ${k} | ${v.pct}% | ${v.covered}/${v.total} |`;
87+
console.log("| Metric | % | Covered/Total |\n|---|---:|---:|\n" +
88+
[
89+
row("Statements", t.statements),
90+
row("Branches", t.branches),
91+
row("Functions", t.functions),
92+
row("Lines", t.lines)
93+
].join("\n")
94+
);
95+
' >> $GITHUB_STEP_SUMMARY
96+
else
97+
echo "No coverage summary found." >> $GITHUB_STEP_SUMMARY
98+
fi
6599
66100
- name: Publish to NPM
67101
if: steps.version-check.outputs.version_changed == 'true'
@@ -123,3 +157,43 @@ jobs:
123157
prerelease: false
124158
});
125159
160+
- name: Comment on related PRs
161+
if: steps.version-check.outputs.version_changed == 'true'
162+
uses: actions/github-script@v7
163+
with:
164+
github-token: ${{ secrets.GITHUB_TOKEN }}
165+
script: |
166+
const version = require('./package.json').version;
167+
// Find PRs that were just merged into main
168+
const { data: prs } = await github.rest.pulls.list({
169+
owner: context.repo.owner,
170+
repo: context.repo.repo,
171+
state: 'closed',
172+
base: 'main',
173+
sort: 'updated',
174+
direction: 'desc',
175+
per_page: 5
176+
});
177+
178+
const recentlyMergedPRs = prs.filter(pr => {
179+
const mergedAt = new Date(pr.merged_at);
180+
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
181+
return pr.merged_at && mergedAt > fiveMinutesAgo;
182+
});
183+
184+
for (const pr of recentlyMergedPRs) {
185+
await github.rest.issues.createComment({
186+
owner: context.repo.owner,
187+
repo: context.repo.repo,
188+
issue_number: pr.number,
189+
body: `🎉 A release has been published: **v${version}**\n\n` +
190+
`Install with:\n` +
191+
"```bash\n" +
192+
`npm install @gabriel-sisjr/react-native-background-location@${version}\n` +
193+
`# or\n` +
194+
`yarn add @gabriel-sisjr/react-native-background-location@${version}\n` +
195+
"```\n\n" +
196+
`This version includes your changes and is available for installation!`
197+
});
198+
}
199+

README.md

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
# @gabriel-sisjr/react-native-background-location
22

3+
[![NPM Version](https://img.shields.io/npm/v/%40gabriel-sisjr%2Freact-native-background-location)](https://www.npmjs.com/package/@gabriel-sisjr/react-native-background-location)
4+
[![NPM Beta](https://img.shields.io/npm/v/%40gabriel-sisjr%2Freact-native-background-location/beta)](https://www.npmjs.com/package/@gabriel-sisjr/react-native-background-location/v/beta)
5+
[![NPM Downloads](https://img.shields.io/npm/dm/%40gabriel-sisjr%2Freact-native-background-location)](https://www.npmjs.com/package/@gabriel-sisjr/react-native-background-location)
6+
[![NPM Total Downloads](https://img.shields.io/npm/dt/%40gabriel-sisjr%2Freact-native-background-location)](https://www.npmjs.com/package/@gabriel-sisjr/react-native-background-location)
7+
[![Pre-release CI](https://github.com/gabriel-sisjr/react-native-background-location/actions/workflows/prerelease.yml/badge.svg?branch=develop&label=Pre-release)](https://github.com/gabriel-sisjr/react-native-background-location/actions/workflows/prerelease.yml)
8+
[![Release CI](https://github.com/gabriel-sisjr/react-native-background-location/actions/workflows/publish.yml/badge.svg?branch=main&label=Release)](https://github.com/gabriel-sisjr/react-native-background-location/actions/workflows/publish.yml)
9+
[![GitHub Stars](https://img.shields.io/github/stars/gabriel-sisjr/react-native-background-location)](https://github.com/gabriel-sisjr/react-native-background-location/stargazers)
10+
[![License](https://img.shields.io/github/license/gabriel-sisjr/react-native-background-location)](https://github.com/gabriel-sisjr/react-native-background-location/blob/develop/LICENSE)
11+
[
12+
![Bundlephobia](https://img.shields.io/bundlephobia/minzip/%40gabriel-sisjr%2Freact-native-background-location?label=size)
13+
](https://bundlephobia.com/package/@gabriel-sisjr/react-native-background-location)
14+
![Platform](https://img.shields.io/badge/platform-Android-green)
15+
![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)
16+
317
A React Native library for tracking location in the background using TurboModules (New Architecture). Track user location even when the app is minimized or in the background.
418

519
<video src="docs/assets/tracking.mp4" controls muted playsinline loop width="100%"></video>
620

7-
821
## Features
922

1023
-**Background location tracking** - Continues tracking when app is in background
@@ -32,14 +45,14 @@ yarn add @gabriel-sisjr/react-native-background-location
3245

3346
```xml
3447
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
35-
48+
3649
<!-- Location permissions -->
3750
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
3851
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
39-
52+
4053
<!-- Background location for Android 10+ -->
4154
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
42-
55+
4356
<!-- Foreground service permissions -->
4457
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
4558
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
@@ -173,14 +186,17 @@ See the [Real-Time Updates Guide](docs/getting-started/REAL_TIME_UPDATES.md) for
173186
You can also use the module API directly:
174187

175188
```typescript
176-
import BackgroundLocation, { type Coords } from '@gabriel-sisjr/react-native-background-location';
189+
import BackgroundLocation, {
190+
type Coords,
191+
} from '@gabriel-sisjr/react-native-background-location';
177192

178193
// Recommended: Let the library generate a unique trip ID
179194
const tripId = await BackgroundLocation.startTracking();
180195

181196
// Optional: Resume tracking with an existing trip ID (for crash recovery)
182197
// Only use this to resume a previously interrupted tracking session
183-
const resumedTripId = await BackgroundLocation.startTracking('existing-trip-123');
198+
const resumedTripId =
199+
await BackgroundLocation.startTracking('existing-trip-123');
184200

185201
// Check if tracking is active
186202
const status = await BackgroundLocation.isTracking();
@@ -189,8 +205,8 @@ console.log(status.tripId); // current trip ID if active
189205

190206
// Get all locations for a trip
191207
const locations: Coords[] = await BackgroundLocation.getLocations(tripId);
192-
locations.forEach(location => {
193-
console.log(location.latitude); // string
208+
locations.forEach((location) => {
209+
console.log(location.latitude); // string
194210
console.log(location.longitude); // string
195211
console.log(location.timestamp); // number (Unix timestamp in ms)
196212
});
@@ -210,31 +226,32 @@ Starts location tracking in background for a new or existing trip.
210226

211227
- **Parameters:**
212228
- `tripId` (optional): Existing trip identifier to resume tracking. If omitted, a new UUID will be generated.
213-
229+
214230
**⚠️ Important:** Only provide a `tripId` when resuming an interrupted tracking session (e.g., after app crash, battery drain, etc.). For new trips, always omit this parameter to let the library generate a unique UUID. This prevents data overwriting and ensures each trip has a unique identifier.
215231

216232
- **Returns:** Promise resolving to the effective trip ID being used.
217233

218-
- **Behavior:**
234+
- **Behavior:**
219235
- If tracking is already active, returns the current trip ID (idempotent).
220236
- Starts a foreground service on Android with a persistent notification.
221237
- Requires location permissions to be granted.
222238
- **New trips:** Generates a unique UUID to prevent collisions.
223239
- **Resuming trips:** Continues collecting locations to the existing trip data.
224240

225-
- **Best Practice:**
241+
- **Best Practice:**
242+
226243
```typescript
227244
// ✅ Good: Start a new trip
228245
const newTripId = await startTracking();
229-
246+
230247
// ✅ Good: Resume after interruption
231248
const resumedTripId = await startTracking(previousTripId);
232-
249+
233250
// ❌ Avoid: Don't create new trips with custom IDs
234251
const badTripId = await startTracking('my-custom-id');
235252
```
236253

237-
- **Throws:**
254+
- **Throws:**
238255
- `PERMISSION_DENIED` if location permissions are not granted.
239256
- `START_TRACKING_ERROR` if unable to start the service.
240257

@@ -268,15 +285,17 @@ Retrieves all stored location points for a specific trip.
268285
- `tripId`: The trip identifier.
269286

270287
- **Returns:** Promise resolving to array of location coordinates:
288+
271289
```typescript
272290
{
273-
latitude: string; // Latitude as string
274-
longitude: string; // Longitude as string
275-
timestamp: number; // Unix timestamp in milliseconds
276-
}[]
291+
latitude: string; // Latitude as string
292+
longitude: string; // Longitude as string
293+
timestamp: number; // Unix timestamp in milliseconds
294+
}
295+
[];
277296
```
278297

279-
- **Throws:**
298+
- **Throws:**
280299
- `INVALID_TRIP_ID` if trip ID is empty.
281300
- `GET_LOCATIONS_ERROR` if unable to retrieve data.
282301

@@ -333,6 +352,7 @@ On Android, some manufacturers (Xiaomi, Huawei, etc.) have aggressive battery op
333352
## Simulator/Emulator Support
334353

335354
When the native module is not available (e.g., running in simulator without proper setup), all methods will:
355+
336356
- Log a warning to the console
337357
- Return safe fallback values
338358
- Not crash the app
@@ -349,10 +369,10 @@ Manages location permissions including background permissions.
349369

350370
```typescript
351371
const {
352-
permissionStatus, // Current permission state
353-
requestPermissions, // Request all permissions
354-
checkPermissions, // Check without requesting
355-
isRequesting, // Loading state
372+
permissionStatus, // Current permission state
373+
requestPermissions, // Request all permissions
374+
checkPermissions, // Check without requesting
375+
isRequesting, // Loading state
356376
} = useLocationPermissions();
357377
```
358378

@@ -362,21 +382,21 @@ Complete hook for managing tracking, locations, and state.
362382

363383
```typescript
364384
const {
365-
isTracking, // Whether tracking is active
366-
tripId, // Current trip ID
367-
locations, // Array of locations
368-
isLoading, // Loading state
369-
error, // Last error
370-
startTracking, // Start tracking
371-
stopTracking, // Stop tracking
372-
refreshLocations, // Refresh locations
373-
clearCurrentTrip, // Clear trip data
374-
clearError, // Clear error
385+
isTracking, // Whether tracking is active
386+
tripId, // Current trip ID
387+
locations, // Array of locations
388+
isLoading, // Loading state
389+
error, // Last error
390+
startTracking, // Start tracking
391+
stopTracking, // Stop tracking
392+
refreshLocations, // Refresh locations
393+
clearCurrentTrip, // Clear trip data
394+
clearError, // Clear error
375395
} = useBackgroundLocation({
376-
autoStart: false, // Auto-start on mount
377-
onTrackingStart: (id) => {}, // Callback
378-
onTrackingStop: () => {}, // Callback
379-
onError: (err) => {}, // Callback
396+
autoStart: false, // Auto-start on mount
397+
onTrackingStart: (id) => {}, // Callback
398+
onTrackingStop: () => {}, // Callback
399+
onError: (err) => {}, // Callback
380400
});
381401
```
382402

@@ -386,10 +406,10 @@ Lightweight hook for monitoring tracking status.
386406

387407
```typescript
388408
const {
389-
isTracking, // Whether tracking is active
390-
tripId, // Current trip ID
391-
refresh, // Refresh status
392-
isLoading, // Loading state
409+
isTracking, // Whether tracking is active
410+
tripId, // Current trip ID
411+
refresh, // Refresh status
412+
isLoading, // Loading state
393413
} = useLocationTracking(true);
394414
```
395415

@@ -418,12 +438,14 @@ See the **[Hooks Guide](docs/getting-started/hooks.md)** for complete documentat
418438
## Documentation
419439

420440
### Getting Started
441+
421442
- **[Quick Start Guide](docs/getting-started/QUICKSTART.md)** - Get up and running in 5 minutes
422443
- **[Integration Guide](docs/getting-started/INTEGRATION_GUIDE.md)** - Detailed integration steps for existing apps
423444
- **[Hooks Guide](docs/getting-started/hooks.md)** - Complete hooks documentation
424445
- **[Real-Time Updates Guide](docs/getting-started/REAL_TIME_UPDATES.md)** - Automatic location watching with useLocationUpdates
425446

426447
### Development
448+
427449
- **[Publishing Guide](docs/development/PUBLISHING.md)** - How to publish updates to npm
428450
- **[Implementation Summary](docs/development/IMPLEMENTATION_SUMMARY.md)** - Technical overview of the implementation
429451
- **[Testing Guide](docs/development/TESTING.md)** - Testing structure and guidelines
@@ -464,6 +486,7 @@ yarn ios
464486
### TypeScript errors
465487

466488
Make sure your `tsconfig.json` includes:
489+
467490
```json
468491
{
469492
"compilerOptions": {

0 commit comments

Comments
 (0)