Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies flagged by dependabot #12

Merged
merged 5 commits into from Dec 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -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/action-docker-layer-caching@v0.1.0
- uses: jpribyl/action-docker-layer-caching@v0.1.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/action-docker-layer-caching@v0.1.0",
# Finally, "Post Run jpribyl/action-docker-layer-caching@v0.1.1",
# which is the process of saving the cache, will be executed.
```

Expand All @@ -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/action-docker-layer-caching@v0.1.0
- uses: jpribyl/action-docker-layer-caching@v0.1.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/action-docker-layer-caching@v0.1.0",
# Finally, "Post Run jpribyl/action-docker-layer-caching@v0.1.1",
# which is the process of saving the cache, will be executed.
```

Expand All @@ -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/action-docker-layer-caching@v0.1.0
- uses: jpribyl/action-docker-layer-caching@v0.1.1
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true
with:
Expand Down
14 changes: 7 additions & 7 deletions package.json
@@ -1,12 +1,12 @@
{
"name": "action-docker-layer-cache",
"version": "0.0.0",
"version": "0.1.1",
"main": "index.ts",
"repository": "https://github.com/satackey/action-docker-layer-caching.git",
"author": "satackey <21271711+satackey@users.noreply.github.com>",
"repository": "https://github.com/jpribyl/action-docker-layer-caching.git",
"author": "jpribyl <jpribyl@users.noreply.github.com>",
"license": "MIT",
"dependencies": {
"@actions/cache": "^1.0.6",
"@actions/cache": "^3.0.6",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@types/recursive-readdir": "^2.2.0",
Expand All @@ -18,11 +18,11 @@
"typescript-is": "^0.19.0"
},
"devDependencies": {
"@types/node": "^14.14.14",
"@types/node": "18.11.10",
"@types/string-format": "^2.0.0",
"@vercel/ncc": "^0.34.0",
"ts-node": "^9.1.1",
"ts-node": "10.9.1",
"ttypescript": "^1.5.13",
"typescript": ">=4.1.5 <4.7.2"
"typescript": "4.9.3"
}
}
83 changes: 54 additions & 29 deletions post.ts
@@ -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);
});
6 changes: 3 additions & 3 deletions src/LayerCache.ts
Expand Up @@ -347,9 +347,9 @@ class LayerCache {
async getLayerTarFiles(): Promise<string[]> {
const getTarFilesFromManifest = (manifest: Manifest) => manifest.Layers;

const tarFilesThatMayDuplicate = (await this.getManifests()).flatMap(
getTarFilesFromManifest
);
const tarFilesThatMayDuplicate: string = (
await this.getManifests()
).flatMap(getTarFilesFromManifest);
const tarFiles = [...new Set(tarFilesThatMayDuplicate)];
return tarFiles;
}
Expand Down
26 changes: 10 additions & 16 deletions src/Tar.ts
@@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, and looks like the builds are happy with it too. This work is satisfactory 馃槅

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, I'll go ahead and merge it in- lmk if any issues come up- I'm not actively using this project a ton at the moment so you would likely find them before me 馃挭

return manifests;
}