Skip to content

Commit b326040

Browse files
Chore - Updating Docs (#4)
* chore: reorganizing docs (#1) * Feature - Core Hooks + Tests (#2) * feat: creation of core hooks + update docs * feat: tests added * chore: increasing percentage of test coverage * docs: update changelog with testing and hooks implementation * Feature - Setup CI/CD (#3) * feat: creating develop and main flows * feat: adding documentation of CICD and project structure * chore: renaming repo on all docs, adding user prefix * chore: renaming package on example app + some docs + yml
1 parent be3faf7 commit b326040

37 files changed

+5759
-432
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ on:
33
push:
44
branches:
55
- main
6+
- develop
67
pull_request:
78
branches:
89
- main
10+
- develop
911
merge_group:
1012
types:
1113
- checks_requested

.github/workflows/prerelease.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Pre-release to NPM
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
prerelease:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: write
18+
id-token: write
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
with:
24+
fetch-depth: 0
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Setup
28+
uses: ./.github/actions/setup
29+
30+
- name: Configure Git
31+
run: |
32+
git config --global user.name 'github-actions[bot]'
33+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
34+
35+
- name: Setup NPM Authentication
36+
run: |
37+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
38+
39+
- name: Generate pre-release version
40+
id: version
41+
run: |
42+
CURRENT_VERSION=$(node -p "require('./package.json').version")
43+
COMMIT_SHA=${GITHUB_SHA::7}
44+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
45+
46+
# Remove any existing pre-release tag and add beta
47+
BASE_VERSION=$(echo $CURRENT_VERSION | sed 's/-.*$//')
48+
PRERELEASE_VERSION="${BASE_VERSION}-beta.${TIMESTAMP}.${COMMIT_SHA}"
49+
50+
echo "version=$PRERELEASE_VERSION" >> $GITHUB_OUTPUT
51+
echo "Generated pre-release version: $PRERELEASE_VERSION"
52+
53+
# Update package.json version
54+
npm version $PRERELEASE_VERSION --no-git-tag-version
55+
56+
- name: Build package
57+
run: yarn prepare
58+
59+
- name: Run tests
60+
run: yarn test --maxWorkers=2
61+
62+
- name: Publish to NPM (beta tag)
63+
run: |
64+
npm publish --access public --tag beta --provenance
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
67+
68+
- name: Create Pre-release Tag
69+
run: |
70+
VERSION="${{ steps.version.outputs.version }}"
71+
git add package.json
72+
git commit -m "chore: pre-release $VERSION [skip ci]"
73+
git tag -a "v$VERSION" -m "Pre-release v$VERSION"
74+
git push origin "v$VERSION"
75+
76+
- name: Create GitHub Pre-release
77+
uses: actions/github-script@v7
78+
with:
79+
github-token: ${{ secrets.GITHUB_TOKEN }}
80+
script: |
81+
const version = '${{ steps.version.outputs.version }}';
82+
const tagName = `v${version}`;
83+
84+
await github.rest.repos.createRelease({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
tag_name: tagName,
88+
name: `Pre-release ${tagName}`,
89+
body: `🚀 Pre-release version ${version}\n\n` +
90+
`This is a beta release from the develop branch.\n\n` +
91+
`Install with: \`npm install @gabriel-sisjr/react-native-background-location@beta\`\n\n` +
92+
`Commit: ${context.sha}`,
93+
draft: false,
94+
prerelease: true
95+
});
96+
97+
- name: Comment on related PRs
98+
uses: actions/github-script@v7
99+
with:
100+
github-token: ${{ secrets.GITHUB_TOKEN }}
101+
script: |
102+
const version = '${{ steps.version.outputs.version }}';
103+
104+
// Find PRs that were just merged
105+
const { data: prs } = await github.rest.pulls.list({
106+
owner: context.repo.owner,
107+
repo: context.repo.repo,
108+
state: 'closed',
109+
base: 'develop',
110+
sort: 'updated',
111+
direction: 'desc',
112+
per_page: 5
113+
});
114+
115+
const recentlyMergedPRs = prs.filter(pr => {
116+
const mergedAt = new Date(pr.merged_at);
117+
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
118+
return pr.merged_at && mergedAt > fiveMinutesAgo;
119+
});
120+
121+
for (const pr of recentlyMergedPRs) {
122+
await github.rest.issues.createComment({
123+
owner: context.repo.owner,
124+
repo: context.repo.repo,
125+
issue_number: pr.number,
126+
body: `🚀 A pre-release version has been published: **v${version}**\n\n` +
127+
`You can install it with:\n` +
128+
`\`\`\`bash\n` +
129+
`npm install @gabriel-sisjr/react-native-background-location@beta\n` +
130+
`# or\n` +
131+
`yarn add @gabriel-sisjr/react-native-background-location@beta\n` +
132+
`\`\`\`\n\n` +
133+
`This version includes your changes and is available for testing!`
134+
});
135+
}
136+

.github/workflows/publish.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Publish to NPM
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: write
18+
id-token: write
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
with:
24+
fetch-depth: 0
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Setup
28+
uses: ./.github/actions/setup
29+
30+
- name: Configure Git
31+
run: |
32+
git config --global user.name 'github-actions[bot]'
33+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
34+
35+
- name: Setup NPM Authentication
36+
run: |
37+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
38+
39+
- name: Check if version changed
40+
id: version-check
41+
run: |
42+
CURRENT_VERSION=$(node -p "require('./package.json').version")
43+
44+
# Get the last published version from npm
45+
PUBLISHED_VERSION=$(npm view @gabriel-sisjr/react-native-background-location version 2>/dev/null || echo "0.0.0")
46+
47+
echo "Current version: $CURRENT_VERSION"
48+
echo "Published version: $PUBLISHED_VERSION"
49+
50+
if [ "$CURRENT_VERSION" = "$PUBLISHED_VERSION" ]; then
51+
echo "version_changed=false" >> $GITHUB_OUTPUT
52+
echo "Version has not changed. Skipping publish."
53+
else
54+
echo "version_changed=true" >> $GITHUB_OUTPUT
55+
echo "New version detected. Proceeding with publish."
56+
fi
57+
58+
- name: Build package
59+
if: steps.version-check.outputs.version_changed == 'true'
60+
run: yarn prepare
61+
62+
- name: Run tests
63+
if: steps.version-check.outputs.version_changed == 'true'
64+
run: yarn test --maxWorkers=2
65+
66+
- name: Publish to NPM
67+
if: steps.version-check.outputs.version_changed == 'true'
68+
run: |
69+
npm publish --access public --provenance
70+
env:
71+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
72+
73+
- name: Create Git Tag
74+
if: steps.version-check.outputs.version_changed == 'true'
75+
run: |
76+
VERSION=$(node -p "require('./package.json').version")
77+
git tag -a "v$VERSION" -m "Release v$VERSION"
78+
git push origin "v$VERSION"
79+
80+
- name: Create GitHub Release
81+
if: steps.version-check.outputs.version_changed == 'true'
82+
uses: actions/github-script@v7
83+
with:
84+
github-token: ${{ secrets.GITHUB_TOKEN }}
85+
script: |
86+
const version = require('./package.json').version;
87+
const tagName = `v${version}`;
88+
89+
// Generate release notes from commits since last tag
90+
let releaseNotes = '';
91+
try {
92+
const { data: tags } = await github.rest.repos.listTags({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
per_page: 2
96+
});
97+
98+
if (tags.length > 0) {
99+
const latestTag = tags[0].name;
100+
const { data: comparison } = await github.rest.repos.compareCommits({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
base: tags[1]?.name || tags[0].commit.sha,
104+
head: latestTag
105+
});
106+
107+
releaseNotes = comparison.commits
108+
.map(commit => `- ${commit.commit.message.split('\n')[0]} (${commit.sha.substring(0, 7)})`)
109+
.join('\n');
110+
}
111+
} catch (error) {
112+
console.log('Could not generate release notes:', error.message);
113+
releaseNotes = 'See CHANGELOG.md for details.';
114+
}
115+
116+
await github.rest.repos.createRelease({
117+
owner: context.repo.owner,
118+
repo: context.repo.repo,
119+
tag_name: tagName,
120+
name: `Release ${tagName}`,
121+
body: releaseNotes || `Release version ${version}`,
122+
draft: false,
123+
prerelease: false
124+
});
125+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ android/generated
8484

8585
# React Native Nitro Modules
8686
nitrogen/
87+
88+
# Jest
89+
coverage/

0 commit comments

Comments
 (0)