Skip to content

Github action to cache dependencies and build outputs to s3 bucket

License

Notifications You must be signed in to change notification settings

leroy-merlin-br/action-s3-cache

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

S3 Cache for GitHub Actions

GitHub Workflow Status GitHub go.mod Go version Codacy grade

GitHub Action that allows you to cache build artifacts to S3

Prerequisites

  • An AWS account. Sign up here.
  • AWS Access and Secret Keys. More info here.
  • An empty S3 bucket.

Usage

Set up the following AWS credentials as secrets in your repository, AWS_ACCESS_KEY_ID and AWS_ACCESS_KEY_ID

S3 Cache for GitHub Actions supports builds on Linux, Windows and MacOS.

Archiving artifacts

- name: Save cache
  uses: leroy-merlin-br/action-s3-cache@v1
  with:
    action: put
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: us-east-1 # Or whatever region your bucket was created
    bucket: your-bucket
    s3-class: ONEZONE_IA # It's STANDARD by default. It can be either STANDARD, 
    # REDUCED_REDUDANCY, ONEZONE_IA, INTELLIGENT_TIERING, GLACIER, DEEP_ARCHIVE or STANDARD_IA.
    key: ${{ hashFiles('yarn.lock') }}
    artifacts: |
      node_modules*

Retrieving artifacts

- name: Retrieve cache
  uses: leroy-merlin-br/action-s3-cache@v1
  with:
    action: get
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: us-east-1
    bucket: your-bucket
    key: ${{ hashFiles('yarn.lock') }}

Clear cache

- name: Clear cache
  uses: leroy-merlin-br/action-s3-cache@v1
  with:
    action: delete
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: us-east-1
    bucket: your-bucket
    key: ${{ hashFiles('yarn.lock') }}

Example

The following example shows a simple pipeline using S3 Cache GitHub Action:

- name: Checkout
  uses: actions/checkout@v2

- name: Retrieve cache
  uses: leroy-merlin-br/action-s3-cache@v1
  with:
    action: get
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: us-east-1
    bucket: your-bucket
    key: ${{ hashFiles('yarn.lock') }}

- name: Install dependencies
  run: yarn

- name: Save cache
  uses: leroy-merlin-br/action-s3-cache@v1
  with:
    action: put
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: us-east-1
    bucket: your-bucket
    s3-class: STANDARD_IA
    key: ${{ hashFiles('yarn.lock') }}
    artifacts: |
      node_modules/*