Skip to content

feat: official support for custom remote cache providers - #331

Merged
thymikee merged 16 commits into
mainfrom
feat/remote-cache-rework
May 17, 2025
Merged

thymikee merged 16 commits into
mainfrom
feat/remote-cache-rework

Conversation

@thymikee

@thymikee thymikee commented May 14, 2025 •

Copy link
Copy Markdown
Member

Summary

This diff adds support for writing your own custom remote providers, which was quasi-supported previously.

Notable changes:

  • Changed the remote cache interface to:
    /**
     * Interface for implementing remote build cache providers.
     * Remote cache providers allow storing and retrieving native build artifacts (e.g. APK, IPA)
     * from remote storage like S3, GitHub Artifacts etc.
     */
    export interface RemoteBuildCache {
      /** Unique identifier for this cache provider, will be displayed in logs */
      name: string;
    
      /**
       * List available artifacts matching the given name pattern
       * @param artifactName - Passed after fingerprinting the build, e.g. `rnef-android-debug-1234567890` for android in debug variant
       * @param limit - Optional maximum number of artifacts to return
       * @returns Array of matching remote artifacts, or empty array if none found
       */
      list({
        artifactName,
        limit,
      }: {
        artifactName: string | undefined;
        limit?: number;
      }): Promise<RemoteArtifact[]>;
    
      /**
       * Download a remote artifact to local storage
       * @param artifactName - Name of the artifact to download, e.g. `rnef-android-debug-1234567890` for android in debug variant
       * @returns Response object from fetch, which will be used to download the artifact
       */
      download({ artifactName }: { artifactName: string }): Promise<Response>;
    
      /**
       * Delete a remote artifact
       * @param artifact - Remote artifact to delete, as returned by `list` method
       * Throws if artifact is not found or deletion fails
       */
      delete({ artifactName }: { artifactName: string }): Promise<RemoteArtifact[]>;
    
      /**
       * Upload a local artifact stored in build cache to remote storage
       * @param artifactName - Name of the artifact to upload, e.g. `rnef-android-debug-1234567890` for android in debug variant
       * @returns Remote artifact info if upload successful, throws otherwise
       */
      upload({ artifactName }: { artifactName: string }): Promise<RemoteArtifact>;
    }
  • made remoteCacheProvider to accept a function that returns a class that implements RemoteBuildCache, so that we can configure input parameters, such as auth data, or repo information
    // rnef.config.mjs
    export default {
      // ...
      remoteCacheProvider: pluginGitHubBuildCache({
        owner: 'callstack-internal',
        repository: 'rnef-remote-build-test',
        token: '<token>',
      }),
    }
  • Added docs with a dummy remote cache that works (previously it would fail with wrong schema type).
  • Implemented delete method for GitHub provider that deletes all matching artifacts (there can be many with the same name)
  • changed query to list that returns a list of artifacts

Test plan

Added unit test for creating and using remote cache provider.

@vercel

vercel Bot commented May 14, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rnef ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2025 10:22am

@thymikee thymikee changed the title feat: add missing methods to remote cache provider feat: official support for custom remote cache providers May 15, 2025
Comment thread packages/tools/src/lib/build-cache/common.ts Outdated
Comment thread packages/tools/src/lib/build-cache/common.ts Outdated
Comment thread packages/tools/src/lib/build-cache/common.ts Outdated
* Upload a local artifact to remote storage
* @param artifact - Local artifact to upload, as returned by `download` method
* @param loader - Optional progress indicator
* @returns Remote artifact info if upload successful, null otherwise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"otherwise" implies error or a different case (e.g. no support)?

maybe better to throw error instead or return an object with additional info that the CLI could display?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upload is something I haven't given too much thought yet, as GitHub API doesn't support it. I'll make it return RemoteArtifact or throw

Comment thread packages/tools/src/lib/build-cache/common.ts Outdated
Comment thread packages/tools/src/lib/build-cache/common.ts Outdated
Comment thread packages/tools/src/lib/build-cache/common.ts Outdated
}: {
artifactName: string;
}): Promise<RemoteArtifact | null>;
artifactName: string | undefined;

@satya164 satya164 May 15, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would artifact name be needed to list artifacts 🤔

@thymikee thymikee May 15, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for listing matching artifacts to your local fingerprint. Could make it optional though

Comment thread packages/tools/src/lib/build-cache/common.ts
Comment thread packages/tools/src/lib/build-cache/common.ts Outdated
Comment thread packages/tools/src/lib/build-cache/fetchCachedBuild.ts
Comment thread packages/tools/src/lib/build-cache/github/GitHubBuildCache.ts Outdated
Comment thread packages/tools/src/lib/build-cache/github/GitHubBuildCache.ts
Comment thread packages/tools/src/lib/build-cache/remoteBuildCache.ts
Comment thread website/docs/docs/configuration.md
Comment thread website/docs/docs/configuration.md
Comment thread website/docs/docs/configuration.md Outdated
@szymonrybczak

Copy link
Copy Markdown
Contributor

Now it's time to implement this spec for the 3rd party provider and validate it in the wild 😁

@thymikee
thymikee merged commit 184cc74 into main May 17, 2025
@thymikee
thymikee deleted the feat/remote-cache-rework branch May 17, 2025 10:25
thymikee added a commit that referenced this pull request May 17, 2025
* origin/main:
  feat: official support for custom remote cache providers (#331)

This branch was successfully deployed

1 active deployment
Preview — 4735fc10 Deployed May 17, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants