forked from satackey/action-docker-layer-caching
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump dependencies flagged by dependabot (#12)
* Bump dependencies flagged by dependabot * Update author, repo, version * Remove ttsc from post.ts * Remove manifest check * Update manifest check to use 'satisfies' operator
- Loading branch information
Showing
6 changed files
with
169 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,13 +40,13 @@ jobs: | |
# In this step, this action saves a list of existing images, | ||
# the cache is created without them in the post run. | ||
# It also restores the cache if it exists. | ||
- uses: jpribyl/[email protected].0 | ||
- uses: jpribyl/[email protected].1 | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
|
||
- run: docker-compose up --build | ||
|
||
# Finally, "Post Run jpribyl/[email protected].0", | ||
# Finally, "Post Run jpribyl/[email protected].1", | ||
# which is the process of saving the cache, will be executed. | ||
``` | ||
|
||
|
@@ -67,14 +67,14 @@ jobs: | |
# In this step, this action saves a list of existing images, | ||
# the cache is created without them in the post run. | ||
# It also restores the cache if it exists. | ||
- uses: jpribyl/[email protected].0 | ||
- uses: jpribyl/[email protected].1 | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
|
||
- name: Build the Docker image | ||
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) | ||
|
||
# Finally, "Post Run jpribyl/[email protected].0", | ||
# Finally, "Post Run jpribyl/[email protected].1", | ||
# which is the process of saving the cache, will be executed. | ||
``` | ||
|
||
|
@@ -86,7 +86,7 @@ By default, the cache is separated by the workflow name. | |
You can also set the cache key manually, like the official [actions/cache](https://github.com/actions/cache#usage) action. | ||
|
||
```yaml | ||
- uses: jpribyl/[email protected].0 | ||
- uses: jpribyl/[email protected].1 | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,68 @@ | ||
import * as core from '@actions/core' | ||
import * as core from "@actions/core"; | ||
|
||
import { LayerCache } from './src/LayerCache' | ||
import { ImageDetector } from './src/ImageDetector' | ||
import { assertType } from 'typescript-is' | ||
import { LayerCache } from "./src/LayerCache"; | ||
import { ImageDetector } from "./src/ImageDetector"; | ||
|
||
const main = async () => { | ||
if (JSON.parse(core.getInput('skip-save', { required: true }))) { | ||
core.info('Skipping save.') | ||
return | ||
if (JSON.parse(core.getInput("skip-save", { required: true }))) { | ||
core.info("Skipping save."); | ||
return; | ||
} | ||
|
||
const primaryKey = core.getInput('key', { required: true }) | ||
const primaryKey = core.getInput("key", { required: true }); | ||
|
||
const restoredKey = JSON.parse(core.getState(`restored-key`)) | ||
const alreadyExistingImages = JSON.parse(core.getState(`already-existing-images`)) | ||
const restoredImages = JSON.parse(core.getState(`restored-images`)) | ||
const restoredKey = JSON.parse(core.getState(`restored-key`)); | ||
const alreadyExistingImages = JSON.parse( | ||
core.getState(`already-existing-images`) | ||
); | ||
const restoredImages = JSON.parse(core.getState(`restored-images`)); | ||
|
||
assertType<string>(restoredKey) | ||
assertType<string[]>(alreadyExistingImages) | ||
assertType<string[]>(restoredImages) | ||
if (typeof restoredKey !== "string") { | ||
throw Error( | ||
`restoredKey is not of type string, instead it is of type ${typeof restoredKey}` | ||
); | ||
} | ||
alreadyExistingImages.map((image: string) => { | ||
if (typeof image !== "string") { | ||
throw Error( | ||
`alreadyExistingImage is not of type string, instead it is of type ${typeof image}` | ||
); | ||
} | ||
}); | ||
restoredImages.map((image: string) => { | ||
if (typeof image !== "string") { | ||
throw Error( | ||
`restoredImage is not of type string, instead it is of type ${typeof image}` | ||
); | ||
} | ||
}); | ||
|
||
const imageDetector = new ImageDetector() | ||
const imageDetector = new ImageDetector(); | ||
|
||
const existingAndRestoredImages = alreadyExistingImages.concat(restoredImages) | ||
const newImages = await imageDetector.getImagesShouldSave(existingAndRestoredImages) | ||
const existingAndRestoredImages = | ||
alreadyExistingImages.concat(restoredImages); | ||
const newImages = await imageDetector.getImagesShouldSave( | ||
existingAndRestoredImages | ||
); | ||
if (newImages.length < 1) { | ||
core.info(`There is no image to save.`) | ||
return | ||
core.info(`There is no image to save.`); | ||
return; | ||
} | ||
|
||
const imagesToSave = await imageDetector.getImagesShouldSave(alreadyExistingImages) | ||
const layerCache = new LayerCache(imagesToSave) | ||
layerCache.concurrency = parseInt(core.getInput(`concurrency`, { required: true }), 10) | ||
const imagesToSave = await imageDetector.getImagesShouldSave( | ||
alreadyExistingImages | ||
); | ||
const layerCache = new LayerCache(imagesToSave); | ||
layerCache.concurrency = parseInt( | ||
core.getInput(`concurrency`, { required: true }), | ||
10 | ||
); | ||
|
||
await layerCache.store(primaryKey) | ||
await layerCache.cleanUp() | ||
} | ||
await layerCache.store(primaryKey); | ||
await layerCache.cleanUp(); | ||
}; | ||
|
||
main().catch(e => { | ||
console.error(e) | ||
core.setFailed(e) | ||
}) | ||
main().catch((e) => { | ||
console.error(e); | ||
core.setFailed(e); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,20 @@ | ||
import { assertType } from 'typescript-is' | ||
import { promises as fs } from 'fs' | ||
import * as path from 'path' | ||
import { promises as fs } from "fs"; | ||
import * as path from "path"; | ||
|
||
export interface Manifest { | ||
Config: string | ||
RepoTags: string[] | null | ||
Layers: string[] | ||
Config: string; | ||
RepoTags: string[] | null; | ||
Layers: string[]; | ||
} | ||
|
||
export type Manifests = Manifest[] | ||
|
||
export function assertManifests(x: unknown): asserts x is Manifests { | ||
assertType<Manifests>(x) | ||
} | ||
export type Manifests = Manifest[]; | ||
|
||
export async function loadRawManifests(rootPath: string) { | ||
return (await fs.readFile(path.join(rootPath, `manifest.json`))).toString() | ||
return (await fs.readFile(path.join(rootPath, `manifest.json`))).toString(); | ||
} | ||
|
||
export async function loadManifests(path: string) { | ||
const raw = await loadRawManifests(path) | ||
const manifests = JSON.parse(raw.toString()) | ||
assertManifests(manifests) | ||
return manifests | ||
const raw = await loadRawManifests(path); | ||
const manifests = JSON.parse(raw.toString()) satisfies Manifests; | ||
return manifests; | ||
} |
Oops, something went wrong.