Skip to content

Commit

Permalink
feat: split image flag into image name and tag (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdk authored Feb 27, 2024
1 parent 63998a9 commit b3dfb90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,25 @@ jobs:
- uses: Example/example-action@a35f...b316
```
If you want your action to use a different image, then you can specify one manually in `action.yml`.
If you want your action to use a specific image tag, then you can set one manually in `action.yml`.

```diff
runs:
using: docker
image: docker://ghcr.io/joshdk/actions-docker-shim:v0.0.2
+ args:
+ - --image=ghcr.io/example/example-action:snapshot
+ - --image-tag=snapshot
```

If your image isn't named the same as your action repository, that can be overridden as well.

```diff
runs:
using: docker
image: docker://ghcr.io/joshdk/actions-docker-shim:v0.0.2
args:
- --image-tag=snapshot
+ - --image=example/some-other-image
```

### Authentication
Expand Down
16 changes: 10 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ func main() {

//nolint:forbidigo,wsl
func mainCmd() error {
var image string
flag.StringVar(&image, "image", "", "ghcr.io image to run")
var imageRepo string
flag.StringVar(&imageRepo, "image", "", "ghcr.io image to run")
var imageTag string
flag.StringVar(&imageTag, "image-tag", "", "ghcr.io image tag to run")
var tokenEnv string
flag.StringVar(&tokenEnv, "token-env", "", "env var to use for github token")
flag.Parse()

if image == "" {
repository := os.Getenv("GITHUB_ACTION_REPOSITORY")
ref := os.Getenv("GITHUB_ACTION_REF")
image = fmt.Sprintf("ghcr.io/%s:%s", strings.ToLower(repository), ref)
if imageRepo == "" {
imageRepo = os.Getenv("GITHUB_ACTION_REPOSITORY")
}
if imageTag == "" {
imageTag = os.Getenv("GITHUB_ACTION_REF")
}
image := fmt.Sprintf("ghcr.io/%s:%s", strings.ToLower(imageRepo), imageTag)

var token string
if tokenEnv != "" {
Expand Down

0 comments on commit b3dfb90

Please sign in to comment.