Skip to content

Commit

Permalink
fix gha scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Nov 30, 2023
1 parent 6c89572 commit 85cf65e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Specify `--github-add-build-cache` at the `up` command to add [GitHub cache](htt
This will add the following directives to all services with a `build` section:

```yaml
cache_to: type=gha,mode=max
cache_from: type=gha
cache_to: type=gha,scope=<project>/<service>,mode=max
cache_from: type=gha,scope=<project>/<service>
```
## Configuration
Expand Down
24 changes: 16 additions & 8 deletions packages/plugin-github/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,22 @@ export const userModelFilter: HookFactory<'userModelFilter'> = async ({ argv })
return {
...userModel,
services: {
...mapValues(userModel.services ?? {}, (({ build, ...rest }) => ({
...rest,
build: build && {
...build,
cache_from: (build.cache_from ?? []).concat('type=gha'),
cache_to: (build.cache_to ?? []).concat('type=gha,mode=max'),
},
}))),
...mapValues(userModel.services ?? {}, (({ build, ...rest }, serviceName) => {
if (!build) {
return rest
}

const scope = [userModel.name, serviceName].join('/')

return ({
...rest,
build: {
...build,
cache_from: (build.cache_from ?? []).concat(`type=gha,scope=${scope}`),
cache_to: (build.cache_to ?? []).concat(`type=gha,scope=${scope},mode=max`),
},
})
})),
},
}
}
Expand Down

0 comments on commit 85cf65e

Please sign in to comment.