Skip to content

Commit f67fb14

Browse files
authored
feat: Skip restore cache action if SKIP_S3_CACHE env variable set to true (#36)
* Skip restore cache action if SKIP_S3_CACHE env variable set to `true` * Update checkout & setup Github actions * Run make build * Adjust readme
1 parent 59f6777 commit f67fb14

File tree

6 files changed

+74
-18
lines changed

6 files changed

+74
-18
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
permissions:
3131
contents: read
3232
steps:
33-
- uses: actions/checkout@v3
34-
- uses: actions/setup-node@v2
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-node@v4
3535
with:
36-
node-version: '16.x'
36+
node-version: '20.x'
3737
registry-url: 'https://registry.npmjs.org'
3838
cache: 'yarn'
3939

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ that's the case.
3636
Note that the action requires `actions/checkout` to be run before it is invoked. This is required in
3737
order to determine the repo state.
3838

39+
### Skipping S3 cache restore action
40+
41+
When debugging CI runs, it is sometimes handy to skip the S3 cache so that you can re-run the same
42+
workflow without making significant code changes to your workflow.
43+
44+
You can skip checking S3 cache using the `SKIP_S3_CACHE` env. variable.
45+
46+
```yml
47+
- uses: pleo-io/s3-cache-action@v3
48+
env:
49+
SKIP_S3_CACHE: true
50+
```
51+
52+
When the cache is skipped, `processed` output is automatically set to `false`.
53+
54+
Additionally you can set this env. variable using a custom PR label. This way you can skip the
55+
restore action without making any code changes at all.
56+
57+
```yml
58+
env:
59+
SKIP_S3_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'skip-s3-cache') }}
60+
```
61+
3962
<!-- action-docs-inputs -->
4063

4164
## Inputs

dist/restore/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

port-component.yaml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@ steward: team-web-core
1111

1212
# Any tags relevant to your components and/or mandated by platform teams
1313
tags:
14-
15-
# Describes type of component the repository defines.
16-
#
17-
# Use:
18-
# - `type: service` for web services (moons)
19-
# - `type: application` for downloadable software (such as an iOS/Android app,
20-
# CLI tool, standalone executable). This also includes e.g. web apps.
21-
# - `type: library` for software used by other components
22-
# - `type: configuration` for repos that contain pure configuration (such as
23-
# setup of DangerJS or Renovate).
24-
# - `type: documentation` for repos that mostly contain documentation.
25-
# - `type: hiring-challenge` for our hiring challenges.
26-
type: library
27-
14+
# Describes type of component the repository defines.
15+
#
16+
# Use:
17+
# - `type: service` for web services (moons)
18+
# - `type: application` for downloadable software (such as an iOS/Android app,
19+
# CLI tool, standalone executable). This also includes e.g. web apps.
20+
# - `type: library` for software used by other components
21+
# - `type: configuration` for repos that contain pure configuration (such as
22+
# setup of DangerJS or Renovate).
23+
# - `type: documentation` for repos that mostly contain documentation.
24+
# - `type: hiring-challenge` for our hiring challenges.
25+
type: library
2826
# (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.
2927
# Example: Terraform folder which hosts the architecture definition for a backend service (moon)
3028
# related_repositories:

src/restore.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,30 @@ describe(`S3 Cache Action - Restore cache`, () => {
9898
expect(output.treeHash).toBe(customHash)
9999
}
100100
)
101+
102+
test(
103+
strip`
104+
When a SKIP_S3_CACHE env variable is present
105+
Then it should return a "false" processed flag
106+
And request to S3 is not called
107+
`,
108+
async () => {
109+
process.env.SKIP_S3_CACHE = 'true'
110+
const treeHash = 'cba2d570993b9c21e3de282e5ba56d1638fb32de'
111+
mockedUtils.getCurrentRepoTreeHash.mockResolvedValue(treeHash)
112+
mockedUtils.fileExistsInS3.mockResolvedValue(true)
113+
114+
const output = await restoreS3Cache({
115+
bucket: 'my-other-bucket',
116+
keyPrefix: 'horse',
117+
repo: {owner: 'my-org', repo: 'my-repo'},
118+
awsOptions
119+
})
120+
121+
expect(output.processed).toBe(false)
122+
expect(mockedUtils.fileExistsInS3).not.toBeCalled()
123+
124+
process.env.SKIP_S3_CACHE = undefined
125+
}
126+
)
101127
})

src/restore.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ export async function restoreS3Cache({
5050
}: RestoreS3CacheActionArgs) {
5151
const currentRepoTreeHash = await getCurrentRepoTreeHash()
5252
const treeHash = customHash || currentRepoTreeHash
53-
5453
const key = `cache/${repo.owner}/${repo.repo}/${keyPrefix}/${treeHash}`
54+
55+
if (process.env.SKIP_S3_CACHE === 'true') {
56+
info('Env variable SKIP_S3_CACHE set to `true`, skipping S3 cache.')
57+
return {processed: false, treeHash, key}
58+
}
59+
5560
const fileExists = await fileExistsInS3({key, bucket, awsOptions})
5661

5762
if (fileExists) {

0 commit comments

Comments
 (0)