Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '16.x'
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'

Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ that's the case.
Note that the action requires `actions/checkout` to be run before it is invoked. This is required in
order to determine the repo state.

### Skipping S3 cache restore action

When debugging CI runs, it is sometimes handy to skip the S3 cache so that you can re-run the same
workflow without making significant code changes to your workflow.

You can skip checking S3 cache using the `SKIP_S3_CACHE` env. variable.

```yml
- uses: pleo-io/s3-cache-action@v3
env:
SKIP_S3_CACHE: true
```
When the cache is skipped, `processed` output is automatically set to `false`.

Additionally you can set this env. variable using a custom PR label. This way you can skip the
restore action without making any code changes at all.

```yml
env:
SKIP_S3_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'skip-s3-cache') }}
```

<!-- action-docs-inputs -->

## Inputs
Expand Down
4 changes: 4 additions & 0 deletions dist/restore/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions port-component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ steward: team-web-core

# Any tags relevant to your components and/or mandated by platform teams
tags:

# Describes type of component the repository defines.
#
# Use:
# - `type: service` for web services (moons)
# - `type: application` for downloadable software (such as an iOS/Android app,
# CLI tool, standalone executable). This also includes e.g. web apps.
# - `type: library` for software used by other components
# - `type: configuration` for repos that contain pure configuration (such as
# setup of DangerJS or Renovate).
# - `type: documentation` for repos that mostly contain documentation.
# - `type: hiring-challenge` for our hiring challenges.
type: library

# Describes type of component the repository defines.
#
# Use:
# - `type: service` for web services (moons)
# - `type: application` for downloadable software (such as an iOS/Android app,
# CLI tool, standalone executable). This also includes e.g. web apps.
# - `type: library` for software used by other components
# - `type: configuration` for repos that contain pure configuration (such as
# setup of DangerJS or Renovate).
# - `type: documentation` for repos that mostly contain documentation.
# - `type: hiring-challenge` for our hiring challenges.
type: library
# (optional) Relevant repositories which are relevant to this component excluding the repository hosting this file. The current repository will be linked by default in Port.
# Example: Terraform folder which hosts the architecture definition for a backend service (moon)
# related_repositories:
Expand Down
26 changes: 26 additions & 0 deletions src/restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,30 @@ describe(`S3 Cache Action - Restore cache`, () => {
expect(output.treeHash).toBe(customHash)
}
)

test(
strip`
When a SKIP_S3_CACHE env variable is present
Then it should return a "false" processed flag
And request to S3 is not called
`,
async () => {
process.env.SKIP_S3_CACHE = 'true'
const treeHash = 'cba2d570993b9c21e3de282e5ba56d1638fb32de'
mockedUtils.getCurrentRepoTreeHash.mockResolvedValue(treeHash)
mockedUtils.fileExistsInS3.mockResolvedValue(true)

const output = await restoreS3Cache({
bucket: 'my-other-bucket',
keyPrefix: 'horse',
repo: {owner: 'my-org', repo: 'my-repo'},
awsOptions
})

expect(output.processed).toBe(false)
expect(mockedUtils.fileExistsInS3).not.toBeCalled()

process.env.SKIP_S3_CACHE = undefined
}
)
})
7 changes: 6 additions & 1 deletion src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ export async function restoreS3Cache({
}: RestoreS3CacheActionArgs) {
const currentRepoTreeHash = await getCurrentRepoTreeHash()
const treeHash = customHash || currentRepoTreeHash

const key = `cache/${repo.owner}/${repo.repo}/${keyPrefix}/${treeHash}`

if (process.env.SKIP_S3_CACHE === 'true') {
info('Env variable SKIP_S3_CACHE set to `true`, skipping S3 cache.')
return {processed: false, treeHash, key}
}

const fileExists = await fileExistsInS3({key, bucket, awsOptions})

if (fileExists) {
Expand Down
Loading