-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactoring s3 cache action #59
Conversation
WalkthroughThe recent updates encompass improvements to GitHub Actions workflows and the introduction of a new S3 caching mechanism. These changes refine existing workflows by correcting versions and syntax while also introducing a new action for efficient artifact management through S3. Updates include version adjustments, script refinements, and documentation enhancements to ensure streamlined operations and optimized resource utilization. Changes
Poem
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional Context UsedLanguageTool (8)
Additional comments not posted (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
# S3 / Cache | ||
|
||
This GitHub Action allows you to save and restore cache artifacts from an S3 bucket. It provides a convenient way to cache dependencies, build artifacts, or any other files that can be reused across multiple workflow runs, helping to speed up your CI/CD pipeline. | ||
|
||
<br> | ||
|
||
## 📋 Features | ||
|
||
- Save cache to an S3 bucket | ||
- Restore cache from an S3 bucket | ||
- Specify custom cache keys and restore keys | ||
- Compress cache files using tar and gzip for efficient storage and transfer | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure consistent list formatting in the features section.
- * `cache-action`
+ - `cache-action`
- * `cache-path`
+ - `cache-path`
- * `s3-bucket-name`
+ - `s3-bucket-name`
- * `cache-key`
+ - `cache-key`
- * `restore-keys`
+ - `restore-keys`
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
# S3 / Cache | |
This GitHub Action allows you to save and restore cache artifacts from an S3 bucket. It provides a convenient way to cache dependencies, build artifacts, or any other files that can be reused across multiple workflow runs, helping to speed up your CI/CD pipeline. | |
<br> | |
## 📋 Features | |
- Save cache to an S3 bucket | |
- Restore cache from an S3 bucket | |
- Specify custom cache keys and restore keys | |
- Compress cache files using tar and gzip for efficient storage and transfer | |
# S3 / Cache | |
This GitHub Action allows you to save and restore cache artifacts from an S3 bucket. It provides a convenient way to cache dependencies, build artifacts, or any other files that can be reused across multiple workflow runs, helping to speed up your CI/CD pipeline. | |
<br> | |
## 📋 Features | |
- Save cache to an S3 bucket | |
- Restore cache from an S3 bucket | |
- Specify custom cache keys and restore keys | |
- Compress cache files using tar and gzip for efficient storage and transfer |
* `cache-action` | ||
|
||
Specify what to do with the cache: save to a s3 bucket or restore from the s3 bucket into `cache_path`. | ||
|
||
- Type: string | ||
- Required | ||
- Possible values: save, restore | ||
|
||
* `cache-path` | ||
|
||
Absolute or relative path to a folder with cache. When `cache-action` is `save` the path itself will not be saved, only the contents of the directory (including all subdirectories). When `cache-action` is `restore` all folders in `cache_path` will be created first and cache will be restored from the S3 bucket into this folder. | ||
|
||
- Type: string | ||
- Required | ||
- Default: . | ||
|
||
* `s3-bucket-name` | ||
|
||
AWS S3 bucket name which will be used to save cache to and restore it from. | ||
|
||
- Type: string | ||
- Required | ||
|
||
* `cache-key` | ||
|
||
A cache key which is used only to save cache to S3 bucket | ||
|
||
- Type: string | ||
- Required only when `cache-action` is `save` | ||
|
||
* `restore-keys` | ||
|
||
An ordered list of keys to use for restoring cache from the s3 bucket | ||
|
||
- Type: list of strings | ||
- Required only when `cache-action` is `restore` | ||
|
||
You can specify multiple keys by putting each key on its own line: | ||
```yaml | ||
restore-keys: |- | ||
${{ runner.os }}-cache-${{ hashfiles('**/.package-lock.json') }} | ||
${{ runner.os }}-cache | ||
``` | ||
The first matching key will be restored. | ||
|
||
<br> | ||
|
||
## 🌎 Environment Variables | ||
|
||
The action requires the following environment variables to be set: | ||
|
||
- `AWS_ACCESS_KEY_ID`: The AWS access key ID with permissions to access the S3 bucket. | ||
- `AWS_SECRET_ACCESS_KEY`: The AWS secret access key associated with the access key ID. | ||
- `AWS_REGION`: The AWS region where the S3 bucket is located. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct punctuation and ensure consistent list formatting in the inputs section.
- * `cache-action`
+ - `cache-action`
- * `cache-path`
+ - `cache-path`
- * `s3-bucket-name`
+ - `s3-bucket-name`
- * `cache-key`
+ - `cache-key`
- * `restore-keys`
+ - `restore-keys`
- `AWS_ACCESS_KEY_ID`: The AWS access key ID with permissions to access the S3 bucket.
+ `AWS_ACCESS_KEY_ID`: The AWS access key ID with permissions to access the S3 bucket.
- `AWS_SECRET_ACCESS_KEY`: The AWS secret access key associated with the access key ID.
+ `AWS_SECRET_ACCESS_KEY`: The AWS secret access key associated with the access key ID.
- `AWS_REGION`: The AWS region where the S3 bucket is located.
+ `AWS_REGION`: The AWS region where the S3 bucket is located.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
* `cache-action` | |
Specify what to do with the cache: save to a s3 bucket or restore from the s3 bucket into `cache_path`. | |
- Type: string | |
- Required | |
- Possible values: save, restore | |
* `cache-path` | |
Absolute or relative path to a folder with cache. When `cache-action` is `save` the path itself will not be saved, only the contents of the directory (including all subdirectories). When `cache-action` is `restore` all folders in `cache_path` will be created first and cache will be restored from the S3 bucket into this folder. | |
- Type: string | |
- Required | |
- Default: . | |
* `s3-bucket-name` | |
AWS S3 bucket name which will be used to save cache to and restore it from. | |
- Type: string | |
- Required | |
* `cache-key` | |
A cache key which is used only to save cache to S3 bucket | |
- Type: string | |
- Required only when `cache-action` is `save` | |
* `restore-keys` | |
An ordered list of keys to use for restoring cache from the s3 bucket | |
- Type: list of strings | |
- Required only when `cache-action` is `restore` | |
You can specify multiple keys by putting each key on its own line: | |
```yaml | |
restore-keys: |- | |
${{ runner.os }}-cache-${{ hashfiles('**/.package-lock.json') }} | |
${{ runner.os }}-cache | |
``` | |
The first matching key will be restored. | |
<br> | |
## 🌎 Environment Variables | |
The action requires the following environment variables to be set: | |
- `AWS_ACCESS_KEY_ID`: The AWS access key ID with permissions to access the S3 bucket. | |
- `AWS_SECRET_ACCESS_KEY`: The AWS secret access key associated with the access key ID. | |
- `AWS_REGION`: The AWS region where the S3 bucket is located. | |
- `cache-action` | |
Specify what to do with the cache: save to a s3 bucket or restore from the s3 bucket into `cache_path`. | |
- Type: string | |
- Required | |
- Possible values: save, restore | |
- `cache-path` | |
Absolute or relative path to a folder with cache. When `cache-action` is `save` the path itself will not be saved, only the contents of the directory (including all subdirectories). When `cache-action` is `restore` all folders in `cache_path` will be created first and cache will be restored from the S3 bucket into this folder. | |
- Type: string | |
- Required | |
- Default: . | |
- `s3-bucket-name` | |
AWS S3 bucket name which will be used to save cache to and restore it from. | |
- Type: string | |
- Required | |
- `cache-key` | |
A cache key which is used only to save cache to S3 bucket | |
- Type: string | |
- Required only when `cache-action` is `save` | |
- `restore-keys` | |
An ordered list of keys to use for restoring cache from the s3 bucket | |
- Type: list of strings | |
- Required only when `cache-action` is `restore` | |
You can specify multiple keys by putting each key on its own line: | |
```yaml | |
restore-keys: |- | |
${{ runner.os }}-cache-${{ hashfiles('**/.package-lock.json') }} | |
${{ runner.os }}-cache | |
``` | |
The first matching key will be restored. | |
<br> | |
## 🌎 Environment Variables | |
The action requires the following environment variables to be set: | |
`AWS_ACCESS_KEY_ID`: The AWS access key ID with permissions to access the S3 bucket. | |
`AWS_SECRET_ACCESS_KEY`: The AWS secret access key associated with the access key ID. | |
`AWS_REGION`: The AWS region where the S3 bucket is located. |
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 📦 Check out the codebase | ||
uses: actions/checkout@v4 | ||
|
||
- name: 📤 Save cache | ||
uses: wayofdev/gh-actions/actions/s3/cache@v3.0.0 | ||
with: | ||
cache-action: save | ||
cache-path: ./node_modules | ||
s3-bucket-name: my-cache-bucket | ||
cache-key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }} | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_REGION: ${{ secrets.AWS_REGION }} | ||
|
||
... | ||
``` | ||
|
||
### → Restoring Cache | ||
|
||
```yaml | ||
--- | ||
|
||
name: 🔍 Continuous integration | ||
|
||
on: # yamllint disable-line rule:truthy | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 📦 Check out the codebase | ||
uses: actions/checkout@v4 | ||
|
||
- name: ♻️ Restore cache | ||
uses: wayofdev/gh-actions/actions/s3/cache@v3.0.0 | ||
with: | ||
cache-action: restore | ||
cache-path: ${GITHUB_WORKSPACE}/.cache | ||
s3-bucket-name: my_s3_bucket | ||
restore-keys: | | ||
${{ runner.os }}-cache-${{ hashfiles('**/.package-lock.json') }} | ||
${{ runner.os }}-cache | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_REGION: ${{ secrets.AWS_REGION }} | ||
|
||
... | ||
``` | ||
|
||
In the restore example, the action will attempt to restore the cache using the provided `restore-keys` in the specified order. If a cache hit occurs for a key, the restoration process will stop, and the cached files will be extracted to the `cache-path`. | ||
### → Error Handling | ||
|
||
The action will fail if any of the required inputs or environment variables are missing or if an invalid `cache-action` is provided. Appropriate error messages will be logged to help troubleshoot the issue. | ||
|
||
### → Creating a Cache Key | ||
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions. | ||
|
||
For example, using the `hashFiles` function allows you to create a new cache when dependencies change. The `hashFiles` function is specific to GitHub Actions. | ||
|
||
```yaml | ||
cache-key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} | ||
``` | ||
|
||
Additionally, you can use arbitrary command output in a cache key, such as a date or software version: | ||
|
||
|
||
```yaml | ||
--- | ||
|
||
name: 🔍 Continuous integration | ||
|
||
on: # yamllint disable-line rule:truthy | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get current timestamp | ||
id: get-date | ||
run: | | ||
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT | ||
shell: bash | ||
|
||
- name: 📤 Save cache | ||
uses: wayofdev/gh-actions/actions/s3-cache@v1 | ||
with: | ||
cache-action: save | ||
cache-path: ${GITHUB_WORKSPACE}/.cache | ||
s3-bucket-name: my_s3_bucket | ||
cache-key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }} | ||
|
||
... | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce consecutive blank lines in the YAML examples.
-
-
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
### → Saving Cache | |
```yaml | |
--- | |
name: 🔍 Continuous integration | |
on: # yamllint disable-line rule:truthy | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 📦 Check out the codebase | |
uses: actions/checkout@v4 | |
- name: 📤 Save cache | |
uses: wayofdev/gh-actions/actions/s3/cache@v3.0.0 | |
with: | |
cache-action: save | |
cache-path: ./node_modules | |
s3-bucket-name: my-cache-bucket | |
cache-key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
... | |
``` | |
### → Restoring Cache | |
```yaml | |
--- | |
name: 🔍 Continuous integration | |
on: # yamllint disable-line rule:truthy | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 📦 Check out the codebase | |
uses: actions/checkout@v4 | |
- name: ♻️ Restore cache | |
uses: wayofdev/gh-actions/actions/s3/cache@v3.0.0 | |
with: | |
cache-action: restore | |
cache-path: ${GITHUB_WORKSPACE}/.cache | |
s3-bucket-name: my_s3_bucket | |
restore-keys: | | |
${{ runner.os }}-cache-${{ hashfiles('**/.package-lock.json') }} | |
${{ runner.os }}-cache | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
... | |
``` | |
In the restore example, the action will attempt to restore the cache using the provided `restore-keys` in the specified order. If a cache hit occurs for a key, the restoration process will stop, and the cached files will be extracted to the `cache-path`. | |
### → Error Handling | |
The action will fail if any of the required inputs or environment variables are missing or if an invalid `cache-action` is provided. Appropriate error messages will be logged to help troubleshoot the issue. | |
### → Creating a Cache Key | |
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions. | |
For example, using the `hashFiles` function allows you to create a new cache when dependencies change. The `hashFiles` function is specific to GitHub Actions. | |
```yaml | |
cache-key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} | |
``` | |
Additionally, you can use arbitrary command output in a cache key, such as a date or software version: | |
```yaml | |
--- | |
name: 🔍 Continuous integration | |
on: # yamllint disable-line rule:truthy | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get current timestamp | |
id: get-date | |
run: | | |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: 📤 Save cache | |
uses: wayofdev/gh-actions/actions/s3-cache@v1 | |
with: | |
cache-action: save | |
cache-path: ${GITHUB_WORKSPACE}/.cache | |
s3-bucket-name: my_s3_bucket | |
cache-key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }} | |
... | |
``` | |
### → Saving Cache | |
```yaml | |
--- | |
name: 🔍 Continuous integration | |
on: # yamllint disable-line rule:truthy | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 📦 Check out the codebase | |
uses: actions/checkout@v4 | |
- name: 📤 Save cache | |
uses: wayofdev/gh-actions/actions/s3/cache@v3.0.0 | |
with: | |
cache-action: save | |
cache-path: ./node_modules | |
s3-bucket-name: my-cache-bucket | |
cache-key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
... |
→ Restoring Cache
---
name: 🔍 Continuous integration
on: # yamllint disable-line rule:truthy
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 📦 Check out the codebase
uses: actions/checkout@v4
- name: ♻️ Restore cache
uses: wayofdev/gh-actions/actions/s3/cache@v3.0.0
with:
cache-action: restore
cache-path: ${GITHUB_WORKSPACE}/.cache
s3-bucket-name: my_s3_bucket
restore-keys: |
${{ runner.os }}-cache-${{ hashfiles('**/.package-lock.json') }}
${{ runner.os }}-cache
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
...
In the restore example, the action will attempt to restore the cache using the provided restore-keys
in the specified order. If a cache hit occurs for a key, the restoration process will stop, and the cached files will be extracted to the cache-path
.
→ Error Handling
The action will fail if any of the required inputs or environment variables are missing or if an invalid cache-action
is provided. Appropriate error messages will be logged to help troubleshoot the issue.
→ Creating a Cache Key
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
For example, using the hashFiles
function allows you to create a new cache when dependencies change. The hashFiles
function is specific to GitHub Actions.
cache-key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
Additionally, you can use arbitrary command output in a cache key, such as a date or software version:
---
name: 🔍 Continuous integration
on: # yamllint disable-line rule:truthy
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get current timestamp
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: 📤 Save cache
uses: wayofdev/gh-actions/actions/s3-cache@v1
with:
cache-action: save
cache-path: ${GITHUB_WORKSPACE}/.cache
s3-bucket-name: my_s3_bucket
cache-key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
...
Summary by CodeRabbit
Documentation
New Features
Chores