react-native-cache-build-gitlab 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,10 +4,14 @@ GitLab Generic Package provider for [RockJS](https://rockjs.dev) with single pac
4
4
 
5
5
  ## Features
6
6
 
7
- **Single Package Storage**: All native builds (iOS & Android) stored in one package
8
- ✅ **Fingerprint-based Lookup**: Fast artifact retrieval by filename matching
9
- **CI/CD Ready**: Works seamlessly with GitLab CI
10
- ✅ **Cost Effective**: Reduces package registry clutter
7
+ 📦 **Single Package Storage**: All native builds (iOS & Android) stored in one package.
8
+
9
+ 🧾 **Fingerprint-based Lookup**: Fast artifact retrieval by filename matching.
10
+
11
+ 🤖️ **CI/CD Ready**: Works seamlessly with GitLab CI.
12
+
13
+ 🪙 **Cost Effective**: Reduces package registry clutter.
14
+
11
15
 
12
16
  ## Installation
13
17
 
@@ -17,41 +21,91 @@ npm install react-native-cache-build-gitlab
17
21
  yarn add react-native-cache-build-gitlab
18
22
  ```
19
23
 
24
+ ## ⚠️ Important
25
+ > You must configure your project according to the [RockJS documentation](https://www.rockjs.dev/docs/cli/migrating-from-community-cli).
26
+
27
+ ## Before to use this provider, make sure you have:
28
+
29
+ Create a GitLab Personal Access Token (PAT) and expose it locally as the environment variable **CI_JOB_TOKEN**.
30
+ ### **1. Create a Personal Access Token**
31
+ * Go to **GitLab** → **Edit profile** → **Personal access tokens**.
32
+ * Click **Add new token**.
33
+ * Give the token a name and expiration date (recommended).
34
+ * Select scopes you need (commonly: read_api, read_package_registry, write_package_registry).
35
+ * Create the token and copy it now — GitLab shows it only once (**Note: You need copy it now because you won't be able to see it again**).
36
+
37
+ ![img.png](assets/example_PAT.png)
38
+
39
+ ### **2. Expose the token as an environment variable**
40
+
41
+ **⚠️ Important:** The provider expects the environment variable name to be ***CI_JOB_TOKEN***.
42
+
43
+ * #### Temporary (current shell session only)
44
+ ```bash
45
+ export CI_JOB_TOKEN=glt-abc123...
46
+ ````
47
+
48
+ ### Persist permanently (macOS with Zsh)
49
+ * Open your Zsh config:
50
+ ```bash
51
+ nano ~/.zshrc
52
+ ```
53
+ * Add the line:
54
+ ```bash
55
+ export CI_JOB_TOKEN=glt-abc123...
56
+ ```
57
+ * Reload your shell:
58
+ ```bash
59
+ source ~/.zshrc
60
+ ```
61
+ * Verify:
62
+ ```bash
63
+ echo $CI_JOB_TOKEN
64
+ ```
65
+
20
66
  ## Usage
21
67
 
22
68
  In your `rock.config.mjs`:
23
69
 
24
- ```javascript
25
- import { platformIOS } from "@rock-js/platform-ios";
26
- import { platformAndroid } from "@rock-js/platform-android";
27
- import { providerGitLab } from "react-native-cache-build-gitlab";
28
- import { pluginMetro } from "@rock-js/plugin-metro";
70
+ ```ts
71
+ import {platformIOS} from "@rock-js/platform-ios";
72
+ import {platformAndroid} from "@rock-js/platform-android";
73
+ import {providerGitLab} from "react-native-cache-build-gitlab";
74
+ import {pluginMetro} from "@rock-js/plugin-metro";
29
75
 
30
76
  export default {
31
- bundler: pluginMetro(),
32
- platforms: {
33
- ios: platformIOS(),
34
- android: platformAndroid(),
35
- },
36
- remoteCacheProvider: providerGitLab({
37
- packageName: "mobile-artifacts",
38
- baseUrl: "https://gitlab.example.com",
39
- projectId: 1234,
40
- token: process.env.CI_JOB_TOKEN,
41
- tokenHeader: process.env.CI ? "JOB-TOKEN" : "PRIVATE-TOKEN",
42
- }),
77
+ bundler: pluginMetro(),
78
+ platforms: {
79
+ ios: platformIOS(),
80
+ android: platformAndroid(),
81
+ },
82
+ remoteCacheProvider: providerGitLab({
83
+ packageName: "mobile-artifacts",
84
+ registryServer: "https://your-gitlab-instance.com",
85
+ projectId: 1234,
86
+ /*
87
+ * token: default is process.env.CI_JOB_TOKEN
88
+ * tokenHeader: default is process.env.CI ? "JOB-TOKEN" : "PRIVATE-TOKEN"
89
+ * */
90
+ }),
91
+ fingerprint: {
92
+ ignorePaths: [
93
+ "ios/Podfile.lock",
94
+ "ios/**/xcuserdata",
95
+ "ios/**/project.pbxproj",
96
+ // Add more paths to ignore as needed
97
+ ],
98
+ },
43
99
  };
44
100
  ```
45
101
 
46
102
  ## Configuration
47
103
 
48
- | Option | Type | Description |
49
- | ------------- | -------------------------------- | ----------------------------------------------- |
50
- | `packageName` | `string` | Package name in GitLab Generic Package Registry |
51
- | `baseUrl` | `string` | GitLab instance URL |
52
- | `projectId` | `number` | GitLab project ID |
53
- | `token` | `string` | GitLab access token (`CI_JOB_TOKEN` on CI) |
54
- | `tokenHeader` | `"JOB-TOKEN" \| "PRIVATE-TOKEN"` | Token type |
104
+ | Option | Type | Description |
105
+ | ------------- | -------------------------------- |-------------------------------------------------------------------------------------------------|
106
+ | `packageName` | `string` | Package name in GitLab Generic Package Registry |
107
+ | `registryServer` | `string` | GitLab instance URL |
108
+ | `projectId` | `number` | GitLab project ID |
55
109
 
56
110
  ## How It Works
57
111
 
@@ -59,6 +113,8 @@ export default {
59
113
 
60
114
  All builds are uploaded to a **single package** with version `1.0.0` (Can change version if needed) at *Package Registry*.:
61
115
 
116
+ >You can use the script **upload-cache-remote.sh** from **example** to upload build cache to GitLab Package Registry.
117
+
62
118
  ```
63
119
  mobile-artifacts@1.0.0/
64
120
  ├── rock-ios-simulator-Debug-{fingerprint}.zip
@@ -84,12 +140,7 @@ build_android_cache:
84
140
  - CACHE_DIR="$(ls -1dt .rock/cache/remote-build/rock-android-* | head -n1)"
85
141
  - sh scripts/upload-cache-remote.sh "${CACHE_DIR}" rock-android-devDebug-{FP}.zip android
86
142
  ```
87
-
88
- ## Differences from Official Provider
89
-
90
- The official `@rock-js/provider-gitlab` creates **one package per fingerprint**, which can clutter the package registry.
91
-
92
- This provider stores **all builds in one package** (version `1.0.4`), using filename-based lookup instead of version-based lookup.
143
+ > ***You can refer to the CI gitlab config in folder example***
93
144
 
94
145
  ## License
95
146
 
@@ -1,6 +1,6 @@
1
1
  import { type RemoteArtifact } from "@rock-js/tools";
2
2
  export type GitLabRepoDetails = {
3
- baseUrl: string;
3
+ registryServer: string;
4
4
  projectId: number | string;
5
5
  token: string;
6
6
  tokenHeader: "PRIVATE-TOKEN" | "JOB-TOKEN";
@@ -16,15 +16,15 @@ async function httpJson(url, repo) {
16
16
  throw new RockError(`GitLab auth failed.\nUpdate token under ${color.bold("remoteCacheProvider")} in ${colorLink("rock.config.mjs")}. Local uses ${color.bold("PRIVATE-TOKEN")}, CI uses ${color.bold("JOB-TOKEN")}.\nURL: ${colorLink(url)}\nError: ${info}`);
17
17
  }
18
18
  if (res.status === 404) {
19
- throw new RockError(`GitLab 404.\nCheck baseUrl/projectId/packageName or token perms.\nURL: ${colorLink(url)}`);
19
+ throw new RockError(`GitLab 404.\nCheck registryServer/projectId/packageName or token perms.\nURL: ${colorLink(url)}`);
20
20
  }
21
21
  throw new RockError(`GitLab request failed: ${info}`);
22
22
  }
23
23
  return (await res.json());
24
24
  }
25
25
  function genericDownloadUrl(repo, packageName, version, fileName) {
26
- const { baseUrl, projectId } = repo;
27
- return `${baseUrl}/api/v4/projects/${encodeURIComponent(String(projectId))}/packages/generic/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}/${encodeURIComponent(fileName)}`;
26
+ const { registryServer, projectId } = repo;
27
+ return `${registryServer}/api/v4/projects/${encodeURIComponent(String(projectId))}/packages/generic/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}/${encodeURIComponent(fileName)}`;
28
28
  }
29
29
  export async function fetchGitLabArtifactsByName(name, repo, limit, version) {
30
30
  if (!repo?.token) {
@@ -34,7 +34,7 @@ export async function fetchGitLabArtifactsByName(name, repo, limit, version) {
34
34
  let page = 1;
35
35
  const packages = [];
36
36
  while (true) {
37
- const url = `${repo.baseUrl}/api/v4/projects/${encodeURIComponent(String(repo.projectId))}/packages` +
37
+ const url = `${repo.registryServer}/api/v4/projects/${encodeURIComponent(String(repo.projectId))}/packages` +
38
38
  `?package_type=generic&per_page=${perPage}&page=${page}` +
39
39
  (name ? `&package_name=${encodeURIComponent(name)}` : "");
40
40
  const chunk = await httpJson(url, repo);
@@ -52,7 +52,7 @@ export async function fetchGitLabArtifactsByName(name, repo, limit, version) {
52
52
  // Don't filter by version here - we'll filter by filename later
53
53
  let fPage = 1;
54
54
  while (true) {
55
- const filesUrl = `${repo.baseUrl}/api/v4/projects/${encodeURIComponent(String(repo.projectId))}` +
55
+ const filesUrl = `${repo.registryServer}/api/v4/projects/${encodeURIComponent(String(repo.projectId))}` +
56
56
  `/packages/${pkg.id}/package_files?per_page=${PAGE_SIZE}&page=${fPage}`;
57
57
  const files = await httpJson(filesUrl, repo);
58
58
  if (!files.length)
@@ -83,7 +83,7 @@ export async function deleteGitLabArtifacts(artifacts, repo, artifactNameForLog)
83
83
  const deleted = [];
84
84
  try {
85
85
  for (const artifact of artifacts) {
86
- const url = `${repo.baseUrl}/api/v4/projects/${encodeURIComponent(String(repo.projectId))}/packages/${artifact.packageId}/package_files/${artifact.fileId}`;
86
+ const url = `${repo.registryServer}/api/v4/projects/${encodeURIComponent(String(repo.projectId))}/packages/${artifact.packageId}/package_files/${artifact.fileId}`;
87
87
  const res = await fetch(url, {
88
88
  method: "DELETE",
89
89
  headers: headersFor(repo),
@@ -1,6 +1,6 @@
1
1
  import { GitLabRepoDetails } from "./artifacts";
2
2
  export type DetectGitLabRepoInput = Partial<GitLabRepoDetails> & {
3
- baseUrl?: string;
3
+ registryServer?: string;
4
4
  projectId?: number | string;
5
5
  token?: string;
6
6
  tokenHeader?: "JOB-TOKEN" | "PRIVATE-TOKEN";
@@ -1,6 +1,6 @@
1
1
  import { RockError } from "@rock-js/tools";
2
2
  export async function detectGitLabRepoDetails(override) {
3
- const baseUrl = override?.baseUrl;
3
+ const registryServer = override?.registryServer;
4
4
  const projectId = override?.projectId;
5
5
  const token = override?.token;
6
6
  const tokenHeader = override?.tokenHeader;
@@ -12,7 +12,7 @@ export async function detectGitLabRepoDetails(override) {
12
12
  throw new RockError("Missing GitLab token. Use CI_JOB_TOKEN or GITLAB_TOKEN.");
13
13
  }
14
14
  return {
15
- baseUrl,
15
+ registryServer,
16
16
  projectId,
17
17
  token,
18
18
  tokenHeader,
@@ -4,10 +4,10 @@ export declare class GitLabBuildCache implements RemoteBuildCache {
4
4
  name: string;
5
5
  repoDetails: GitLabRepoDetails | null;
6
6
  constructor(config?: {
7
- baseUrl: string;
7
+ registryServer: string;
8
8
  projectId: number | string;
9
- token: string;
10
- tokenHeader: "JOB-TOKEN" | "PRIVATE-TOKEN";
9
+ token?: string;
10
+ tokenHeader?: "JOB-TOKEN" | "PRIVATE-TOKEN";
11
11
  packageName: string;
12
12
  });
13
13
  getRepoDetails(): Promise<GitLabRepoDetails>;
@@ -24,13 +24,13 @@ export declare class GitLabBuildCache implements RemoteBuildCache {
24
24
  skipLatest?: boolean;
25
25
  }): Promise<RemoteArtifact[]>;
26
26
  upload(): Promise<RemoteArtifact & {
27
- getResponse: (buffer: Buffer | ((baseUrl: string) => Buffer), contentType?: string | undefined) => Response;
27
+ getResponse: (buffer: Buffer | ((registryServer: string) => Buffer), contentType?: string | undefined) => Response;
28
28
  }>;
29
29
  }
30
30
  export declare const providerGitLab: (options?: {
31
- baseUrl: string;
31
+ registryServer: string;
32
32
  projectId: number;
33
- token: string;
34
- tokenHeader: "PRIVATE-TOKEN" | "JOB-TOKEN";
33
+ token?: string;
34
+ tokenHeader?: "PRIVATE-TOKEN" | "JOB-TOKEN";
35
35
  packageName: string;
36
36
  }) => () => RemoteBuildCache;
@@ -13,16 +13,17 @@ export class GitLabBuildCache {
13
13
  repoDetails = null;
14
14
  constructor(config) {
15
15
  if (config) {
16
- const token = process.env.CI_JOB_TOKEN;
16
+ const token = config.token ?? process.env.CI_JOB_TOKEN;
17
+ const tokenHeader = config.tokenHeader ?? (process.env.CI ? "JOB-TOKEN" : "PRIVATE-TOKEN");
17
18
  if (!token) {
18
19
  throw new Error("GitLab token is required. Set CI_JOB_TOKEN (CI) or GITLAB_PRIVATE_TOKEN/PRIVATE_TOKEN (local).");
19
20
  }
20
21
  this.repoDetails = {
21
22
  packageName: config.packageName,
22
- baseUrl: config.baseUrl,
23
+ registryServer: config.registryServer,
23
24
  projectId: config.projectId,
24
- token: config.token,
25
- tokenHeader: config.tokenHeader,
25
+ token,
26
+ tokenHeader,
26
27
  };
27
28
  }
28
29
  }
@@ -44,7 +45,6 @@ export class GitLabBuildCache {
44
45
  }
45
46
  async download({ artifactName, }) {
46
47
  const repo = await this.getRepoDetails();
47
- // const { name, version } = parseName(artifactName);
48
48
  const { fingerprint } = parseRockArtifact(artifactName);
49
49
  if (!fingerprint)
50
50
  throw new Error("artifactName is required");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-cache-build-gitlab",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",