Skip to content

Commit

Permalink
feat!: rewrite in TypeScript with CacheMap support
Browse files Browse the repository at this point in the history
BREAKING `cache-source` and `cache-target` are removed in favour of `cache-map` that expects a JSON string

Signed-off-by: Amin Yahyaabadi <[email protected]>
  • Loading branch information
aminya committed Mar 29, 2024
1 parent e2c919a commit d8b37a6
Show file tree
Hide file tree
Showing 17 changed files with 3,138 additions and 138 deletions.
37 changes: 17 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@ jobs:
id: meta
with:
images: test
- name: Cache var-cache-apt
id: cache-var-cache-apt
uses: actions/cache@v3

- name: Cache
uses: actions/cache@v4
id: cache
with:
path: var-cache-apt
key: var-cache-apt-${{ hashFiles('.github/workflows/test/Dockerfile') }}
- name: Cache var-lib-apt
id: cache-var-lib-apt
uses: actions/cache@v3
with:
path: var-lib-apt
key: var-lib-apt-${{ hashFiles('.github/workflows/test/Dockerfile') }}
- name: inject var-cache-apt into docker
uses: ./
with:
cache-source: var-cache-apt
cache-target: /var/cache/apt
- name: inject var-lib-apt into docker
path: |
var-cache-apt
var-lib-apt
key: cache-${{ hashFiles('.github/workflows/test/Dockerfile') }}

- name: inject cache into docker
uses: ./
with:
cache-source: var-lib-apt
cache-target: /var/lib/apt
skip-extraction: ${{ steps.cache-var-lib-apt.outputs.cache-hit }}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
cache-map: |
{
"var-cache-apt": "/var/cache/apt",
"var-lib-apt": "/var/lib/apt"
}
- name: Build and push
uses: docker/build-push-action@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.parcel-cache/
47 changes: 22 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,39 @@ Action:
```yaml
---
name: Build
on: push
on:
push:

jobs:
build:
name: Build
Build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: YOUR_IMAGE
- name: Cache var-cache-apt
id: cache-var-cache-apt
uses: actions/cache@v3
with:
path: var-cache-apt
key: var-cache-apt-${{ hashFiles('Dockerfile') }}
- name: Cache var-lib-apt
id: cache-var-lib-apt
images: Build

- name: Cache
uses: actions/cache@v3
id: cache
with:
path: var-lib-apt
key: var-lib-apt-${{ hashFiles('Dockerfile') }}
- name: inject var-cache-apt into docker
uses: reproducible-containers/[email protected]
with:
cache-source: var-cache-apt
cache-target: /var/cache/apt
skip-extraction: ${{ steps.cache-var-cache-apt.outputs.cache-hit }}
- name: inject var-lib-apt into docker
uses: reproducible-containers/[email protected]
path: |
var-cache-apt
var-lib-apt
key: cache-${{ hashFiles('.github/workflows/test/Dockerfile') }}

- name: inject cache into docker
uses: reproducible-containers/[email protected]
with:
cache-source: var-lib-apt
cache-target: /var/lib/apt
skip-extraction: ${{ steps.cache-var-lib-apt.outputs.cache-hit }}
cache-map: |
{
"var-cache-apt": "/var/cache/apt",
"var-lib-apt": "/var/lib/apt"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

- name: Build and push
uses: docker/build-push-action@v5
with:
Expand All @@ -79,6 +75,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

```

Real-world examples:
Expand Down
13 changes: 5 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name: Inject/Extract Cache
description: "Injects the cached data into the docker build(x|kit) process"
inputs:
cache-source:
default: cache
description: "Where the cache is stored in the calling workspace. Default: `cache`"
cache-target:
default: /root/.cache/go-build
description: "Where the cache is stored in the docker container. Default: `/root/.cache/go-build`"
cache-map:
required: true
description: "The map of actions source to container destination paths for the cache paths"
scratch-dir:
default: scratch
description: "Where the action is stores some temporary files for its processing. Default: `scratch`"
Expand All @@ -15,5 +12,5 @@ inputs:
description: "Skip the extraction of the cache from the docker container"
runs:
using: 'node20'
main: 'entrypoint.js'
post: 'entrypoint.js'
main: 'dist/index.js'
post: 'dist/index.js'
Loading

0 comments on commit d8b37a6

Please sign in to comment.