react-native-cache-build-gitlab 1.0.5 → 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 +60 -18
- package/dist/provider-gitlab/artifacts.d.ts +1 -1
- package/dist/provider-gitlab/artifacts.js +6 -6
- package/dist/provider-gitlab/config.d.ts +1 -1
- package/dist/provider-gitlab/config.js +2 -2
- package/dist/provider-gitlab/providerGitlab.d.ts +3 -3
- package/dist/provider-gitlab/providerGitlab.js +1 -1
- package/package.json +1 -1
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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,6 +21,48 @@ 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
|
+

|
|
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`:
|
|
@@ -34,11 +80,13 @@ export default {
|
|
|
34
80
|
android: platformAndroid(),
|
|
35
81
|
},
|
|
36
82
|
remoteCacheProvider: providerGitLab({
|
|
37
|
-
packageName: "mobile-artifacts",
|
|
38
|
-
|
|
83
|
+
packageName: "mobile-artifacts",
|
|
84
|
+
registryServer: "https://your-gitlab-instance.com",
|
|
39
85
|
projectId: 1234,
|
|
40
|
-
|
|
41
|
-
|
|
86
|
+
/*
|
|
87
|
+
* token: default is process.env.CI_JOB_TOKEN
|
|
88
|
+
* tokenHeader: default is process.env.CI ? "JOB-TOKEN" : "PRIVATE-TOKEN"
|
|
89
|
+
* */
|
|
42
90
|
}),
|
|
43
91
|
fingerprint: {
|
|
44
92
|
ignorePaths: [
|
|
@@ -56,11 +104,8 @@ export default {
|
|
|
56
104
|
| Option | Type | Description |
|
|
57
105
|
| ------------- | -------------------------------- |-------------------------------------------------------------------------------------------------|
|
|
58
106
|
| `packageName` | `string` | Package name in GitLab Generic Package Registry |
|
|
59
|
-
| `
|
|
107
|
+
| `registryServer` | `string` | GitLab instance URL |
|
|
60
108
|
| `projectId` | `number` | GitLab project ID |
|
|
61
|
-
| `token` | `string` | GitLab personal access token (`CI_JOB_TOKEN` on CI), You have to export `CI_JOB_TOKEN` in local |
|
|
62
|
-
| | | |
|
|
63
|
-
| `tokenHeader` | `"JOB-TOKEN" \| "PRIVATE-TOKEN"` | Token type |
|
|
64
109
|
|
|
65
110
|
## How It Works
|
|
66
111
|
|
|
@@ -68,6 +113,8 @@ export default {
|
|
|
68
113
|
|
|
69
114
|
All builds are uploaded to a **single package** with version `1.0.0` (Can change version if needed) at *Package Registry*.:
|
|
70
115
|
|
|
116
|
+
>You can use the script **upload-cache-remote.sh** from **example** to upload build cache to GitLab Package Registry.
|
|
117
|
+
|
|
71
118
|
```
|
|
72
119
|
mobile-artifacts@1.0.0/
|
|
73
120
|
├── rock-ios-simulator-Debug-{fingerprint}.zip
|
|
@@ -93,12 +140,7 @@ build_android_cache:
|
|
|
93
140
|
- CACHE_DIR="$(ls -1dt .rock/cache/remote-build/rock-android-* | head -n1)"
|
|
94
141
|
- sh scripts/upload-cache-remote.sh "${CACHE_DIR}" rock-android-devDebug-{FP}.zip android
|
|
95
142
|
```
|
|
96
|
-
|
|
97
|
-
## Differences from Official Provider
|
|
98
|
-
|
|
99
|
-
The official `@rock-js/provider-gitlab` creates **one package per fingerprint**, which can clutter the package registry.
|
|
100
|
-
|
|
101
|
-
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***
|
|
102
144
|
|
|
103
145
|
## License
|
|
104
146
|
|
|
@@ -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
|
|
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 {
|
|
27
|
-
return `${
|
|
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.
|
|
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.
|
|
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.
|
|
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 { RockError } from "@rock-js/tools";
|
|
2
2
|
export async function detectGitLabRepoDetails(override) {
|
|
3
|
-
const
|
|
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
|
-
|
|
15
|
+
registryServer,
|
|
16
16
|
projectId,
|
|
17
17
|
token,
|
|
18
18
|
tokenHeader,
|
|
@@ -4,7 +4,7 @@ export declare class GitLabBuildCache implements RemoteBuildCache {
|
|
|
4
4
|
name: string;
|
|
5
5
|
repoDetails: GitLabRepoDetails | null;
|
|
6
6
|
constructor(config?: {
|
|
7
|
-
|
|
7
|
+
registryServer: string;
|
|
8
8
|
projectId: number | string;
|
|
9
9
|
token?: string;
|
|
10
10
|
tokenHeader?: "JOB-TOKEN" | "PRIVATE-TOKEN";
|
|
@@ -24,11 +24,11 @@ export declare class GitLabBuildCache implements RemoteBuildCache {
|
|
|
24
24
|
skipLatest?: boolean;
|
|
25
25
|
}): Promise<RemoteArtifact[]>;
|
|
26
26
|
upload(): Promise<RemoteArtifact & {
|
|
27
|
-
getResponse: (buffer: Buffer | ((
|
|
27
|
+
getResponse: (buffer: Buffer | ((registryServer: string) => Buffer), contentType?: string | undefined) => Response;
|
|
28
28
|
}>;
|
|
29
29
|
}
|
|
30
30
|
export declare const providerGitLab: (options?: {
|
|
31
|
-
|
|
31
|
+
registryServer: string;
|
|
32
32
|
projectId: number;
|
|
33
33
|
token?: string;
|
|
34
34
|
tokenHeader?: "PRIVATE-TOKEN" | "JOB-TOKEN";
|