Skip to content

Commit

Permalink
Use node 16
Browse files Browse the repository at this point in the history
  • Loading branch information
e committed Nov 5, 2022
1 parent cc3f382 commit 1184386
Show file tree
Hide file tree
Showing 8 changed files with 610 additions and 439 deletions.
40 changes: 19 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 12.x
node-version: 16.x

- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Output info
id: info
run: |
if [ '${{ github.event_name }}' = 'pull_request' ]; then
echo '::set-output name=commit_message::'
echo "commit_message=" >> $GITHUB_OUTPUT
exit 0
fi
echo '::set-output name=commit_message::[auto]'
echo "commit_message=[auto]" >> $GITHUB_OUTPUT
- uses: satackey/[email protected].0-beta3
- uses: jpribyl/[email protected].3
with:
commit-message: ${{ steps.info.outputs.commit_message }}
push-branch: '{branch}-release'

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: github.event_name != 'delete'
with:
name: built
path: ./

- name: Output matrix
id: set_matrix
uses: actions/github-script@v2
uses: actions/github-script@v6
with:
script: |
return {
Expand All @@ -69,12 +69,12 @@ jobs:
}, {
inspect_image: 'nothing',
os: 'ubuntu-latest',
prepare_command: 'docker tag node:12 nothing',
prepare_command: 'docker tag node:16 nothing',
build_command: ':',
}, {
inspect_image: 'nothing',
os: 'windows-latest',
prepare_command: 'docker tag mcr.microsoft.com/windows/nanoserver:1809 nothing',
prepare_command: 'docker pull mcr.microsoft.com/windows/nanoserver:1809; docker tag mcr.microsoft.com/windows/nanoserver:1809 nothing',
build_command: ':',
}, {
branch: process.env.GITHUB_REF.replace('refs/heads/', '')
Expand All @@ -99,18 +99,17 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- run: ${{ matrix.prepare_command }}

- name: Download action
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: built
path: action-dlc

- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
name: Run jpribyl/action-docker-layer-caching@${{ matrix.branch }}
with:
key: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}

Expand All @@ -123,23 +122,22 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- run: ${{ matrix.prepare_command }}

- name: Extract
id: extract
run: |
echo "##[set-output name=branch;]${GITHUB_REF#refs/heads/}"
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT

- name: Download action
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: built
path: action-dlc

- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
name: Run jpribyl/action-docker-layer-caching@${{ matrix.branch }}
with:
key: never-restored-docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
Expand All @@ -149,7 +147,7 @@ jobs:
run: docker inspect ${{ matrix.inspect_image }}

- name: Get cached image ID
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
run: echo id=$(docker image ls -q ${{ matrix.inspect_image }}) >> $GITHUB_OUTPUT
id: cached

- run: ${{ matrix.build_command }}
Expand All @@ -158,7 +156,7 @@ jobs:
run: docker inspect ${{ matrix.inspect_image }}

- name: Show built image ID
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
run: echo id=$(docker image ls -q ${{ matrix.inspect_image }}) >> $GITHUB_OUTPUT
id: latest

- name: Compare cached ID and after build ID
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test_readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:

- run: ${{ matrix.prepare_command }}

- uses: satackey/action-docker-layer-caching@master-release
- uses: jpribyl/action-docker-layer-caching@master-release
with:
key: docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: ''
Expand All @@ -95,7 +95,7 @@ jobs:

- run: ${{ matrix.prepare_command }}

- uses: satackey/action-docker-layer-caching@master-release
- uses: jpribyl/action-docker-layer-caching@master-release
with:
key: never-restored-docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
Expand All @@ -105,7 +105,7 @@ jobs:
run: docker inspect ${{ matrix.inspect_image }}

- name: Get cached image ID
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
run: echo id=$(docker image ls -q ${{ matrix.inspect_image }}) >> $GITHUB_OUTPUT
id: cached

- run: ${{ matrix.build_command }}
Expand All @@ -114,7 +114,7 @@ jobs:
run: docker inspect ${{ matrix.inspect_image }}

- name: Show built image ID
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
run: echo id=$(docker image ls -q ${{ matrix.inspect_image }}) >> $GITHUB_OUTPUT
id: latest

- name: Compare cached ID and after build ID
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Layer Caching
name: Docker Layer Caching2
description: Cache images created between main run and post run

branding:
Expand All @@ -24,6 +24,6 @@ inputs:
default: 'false'

runs:
using: node12
using: node16
main: main.ts
post: post.ts
61 changes: 39 additions & 22 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
import * as core from '@actions/core'
import * as exec from 'actions-exec-listener'
import { LayerCache } from './src/LayerCache'
import { ImageDetector } from './src/ImageDetector'
import * as core from "@actions/core";
import * as exec from "actions-exec-listener";
import { LayerCache } from "./src/LayerCache";
import { ImageDetector } from "./src/ImageDetector";

const main = async () => {
const primaryKey = core.getInput(`key`, { required: true })
const restoreKeys = core.getInput(`restore-keys`, { required: false }).split(`\n`).filter(key => key !== ``)
const primaryKey = core.getInput(`key`, { required: true });
const restoreKeys = core
.getInput(`restore-keys`, { required: false })
.split(`\n`)
.filter((key) => key !== ``);

const imageDetector = new ImageDetector()
const imageDetector = new ImageDetector();

const alreadyExistingImages = await imageDetector.getExistingImages()
core.saveState(`already-existing-images`, JSON.stringify(alreadyExistingImages))
const alreadyExistingImages = await imageDetector.getExistingImages();
core.saveState(
`already-existing-images`,
JSON.stringify(alreadyExistingImages)
);

const layerCache = new LayerCache([])
layerCache.concurrency = parseInt(core.getInput(`concurrency`, { required: true }), 10)
const restoredKey = await layerCache.restore(primaryKey, restoreKeys)
await layerCache.cleanUp()
const layerCache = new LayerCache([]);
layerCache.concurrency = parseInt(
core.getInput(`concurrency`, { required: true }),
10
);
const restoredKey = await layerCache.restore(primaryKey, restoreKeys);
await layerCache.cleanUp();

core.saveState(`restored-key`, JSON.stringify(restoredKey !== undefined ? restoredKey : ''))
core.saveState(`restored-images`, JSON.stringify(await imageDetector.getImagesShouldSave(alreadyExistingImages)))
}
core.saveState(
`restored-key`,
JSON.stringify(restoredKey !== undefined ? restoredKey : "")
);
core.saveState(
`restored-images`,
JSON.stringify(
await imageDetector.getImagesShouldSave(alreadyExistingImages)
)
);
};

main().catch(e => {
console.error(e)
core.setFailed(e)
main().catch((e) => {
console.error(e);
core.setFailed(e);

core.saveState(`restored-key`, JSON.stringify(``))
core.saveState(`restored-images`, JSON.stringify([]))
})
core.saveState(`restored-key`, JSON.stringify(``));
core.saveState(`restored-images`, JSON.stringify([]));
});
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"native-promise-pool": "^3.16.0",
"recursive-readdir": "^2.2.2",
"string-format": "^2.0.0",
"typescript-is": "^0.17.1"
"typescript-is": "^0.19.0"
},
"devDependencies": {
"@types/node": "^14.14.14",
"@types/string-format": "^2.0.0",
"@zeit/ncc": "^0.22.3",
"@vercel/ncc": "^0.34.0",
"ts-node": "^9.1.1",
"ttypescript": "^1.5.12",
"typescript": "^4.2.3"
"ttypescript": "^1.5.13",
"typescript": ">=4.1.5 <4.7.2"
}
}
43 changes: 31 additions & 12 deletions src/ImageDetector.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import * as exec from 'actions-exec-listener'
import * as core from '@actions/core'
import * as exec from "actions-exec-listener";
import * as core from "@actions/core";

export class ImageDetector {
async getExistingImages(): Promise<string[]> {
const existingSet = new Set<string>([])
const ids = (await exec.exec(`docker image ls -q`, [], { silent: true, listeners: { stderr: console.warn }})).stdoutStr.split(`\n`).filter(id => id !== ``)
const repotags = (await exec.exec(`docker`, `image ls --format {{.Repository}}:{{.Tag}} --filter dangling=false`.split(' '), { silent: true, listeners: { stderr: console.warn }})).stdoutStr.split(`\n`).filter(id => id !== ``);
const existingSet = new Set<string>([]);
const ids = (
await exec.exec(`docker image ls -q`, [], {
silent: true,
listeners: { stderr: console.warn },
})
).stdoutStr
.split(`\n`)
.filter((id) => id !== ``);
const repotags = (
await exec.exec(
`docker`,
`image ls --format {{.Repository}}:{{.Tag}} --filter dangling=false`.split(
" "
),
{ silent: true, listeners: { stderr: console.warn } }
)
).stdoutStr
.split(`\n`)
.filter((id) => id !== ``);
core.debug(JSON.stringify({ log: "getExistingImages", ids, repotags }));
([...ids, ...repotags]).forEach(image => existingSet.add(image))
core.debug(JSON.stringify({ existingSet }))
return Array.from(existingSet)
[...ids, ...repotags].forEach((image) => existingSet.add(image));
core.debug(JSON.stringify({ existingSet }));
return Array.from(existingSet);
}

async getImagesShouldSave(alreadRegisteredImages: string[]): Promise<string[]> {
const resultSet = new Set(await this.getExistingImages())
alreadRegisteredImages.forEach(image => resultSet.delete(image))
return Array.from(resultSet)
async getImagesShouldSave(
alreadRegisteredImages: string[]
): Promise<string[]> {
const resultSet = new Set(await this.getExistingImages());
alreadRegisteredImages.forEach((image) => resultSet.delete(image));
return Array.from(resultSet);
}
}
Loading

0 comments on commit 1184386

Please sign in to comment.