npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gcs-cache-action

v1.0.3

Published

Cache your workload to a Google Cloud Storage bucket

Downloads

3

Readme

Banner

Google Cloud Storage Cache Action

License GitHub Issues GitHub Stars

GitHub already provides an awesome action to cache your workload to Azure's servers hosted in United States. However, if you are using self-hosted runners hosted far away from the cache location, or if you pay external network way more than internal network, you may want to host your cache elsewhere for better performance and lower costs.

This action does have the same set of inputs as the @actions/cache action from GitHub, in addition to a new bucket input which should contain your target Google Cloud Storage bucket. As simple as that.

Usage

workflow.yml

- name: Authenticate to Google Cloud
  uses: google-github-actions/auth@v0
  with:
    workload_identity_provider: projects/your-project-id/locations/global/workloadIdentityPools/your-identity-pool/providers/your-provider
    service_account: [email protected]

- name: Cache the node_modules
  id: node-modules-cache
  uses: mansagroup/gcs-cache-action@v2
  with:
    bucket: my-ci-cache
    path: node_modules
    key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
    restore-keys: |
      node-modules-${{ runner.os }}-

- name: Install dependencies
  if: steps.node-modules-cache.outputs.cache-hit == 'false'
  run: npm ci

Inputs

This GitHub action can take several inputs to configure its behaviors:

| Name | Type | Default | Example | Description | | ------------ | -------- | ------- | --------------------------------------------------------------------- | ----------------------------------------------------------------- | | bucket | String | ø | my-ci-cache | The name of the Google Cloud Storage bucket to use | | path | String[] | ø | node_modules | One or more path to store | | key | String | ø | node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | Key to use as cache name | | restore-keys | String[] | ø | node-modules-${{ runner.os }}- | Alternative keys to use when looking for the best cache available |

Note: the path and restore-keys inputs can contains multiple value separated by a new line.

Outputs

This GitHub action will output the following values:

| Name | Type | Description | | --------- | ------ | -------------------------------------------------------------------- | | cache-hit | String | A boolean string representing if the cache was successfully restored |

Examples

With multiple paths

workflow.yml

- name: Authenticate to Google Cloud
  uses: google-github-actions/auth@v0
  with:
    workload_identity_provider: projects/your-project-id/locations/global/workloadIdentityPools/your-identity-pool/providers/your-provider
    service_account: [email protected]

- name: Cache the node_modules and npm cache
  id: node-modules-cache
  uses: mansagroup/gcs-cache-action@v2
  with:
    bucket: my-ci-cache
    path: |
      node_modules
      ~/.npm
    key: npm-and-node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
    restore-keys: |
      npm-and-node-modules-${{ runner.os }}-

Compression algorithm

When compressing or decompressing the cache archive, the action will lookup for the best compression algorithm to use. If zstd is available, it will be used instead of gzip by default. The compression method will be added to the object's metadata on the Bucket. Thanks to this, when decompressing, the correct algorithm will be used.

Installing zstd on Ubuntu is simple as doing a apt install zstd.

Note that if a cache archive was compressed using one algorithm, this same algorithm should be installed to decompress it after.

Terraform

Here is a little snippet allowing you to create your cache bucket with Terraform (which you should probably use):

resource "google_storage_bucket" "ci_cache" {
  name                        = "your-ci-cache"
  location                    = "your-location" # "EUROPE-WEST1"
  uniform_bucket_level_access = true

  lifecycle_rule {
    action {
      type = "Delete"
    }

    condition {
      age = 7
    }
  }
}

resource "google_storage_bucket_iam_member" "ci_cache_write_github_ci" {
  bucket = google_storage_bucket.ci_cache.name
  role   = "roles/storage.objectCreator"
  member = "serviceAccount:[email protected]"
}

resource "google_storage_bucket_iam_member" "ci_cache_read_github_ci" {
  bucket = google_storage_bucket.ci_cache.name
  role   = "roles/storage.objectViewer"
  member = "serviceAccount:[email protected]"
}

resource "google_storage_bucket_iam_member" "ci_cache_legacy_write_github_ci" {
  bucket = google_storage_bucket.ci_cache.name
  role   = "roles/storage.legacyBucketWriter"
  member = "serviceAccount:[email protected]"
}

Q&A

Could I use this action on multiple repositories with the same bucket?

Yes you can. When storing to the bucket, this action will use the following the following path:

[repository owner]/[repository name]/[cache key].tar.gz

License

This project is MIT licensed.

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!