Added option to configure the source and target branch
This commit is contained in:
parent
7999a86f58
commit
ec773bc57d
|
@ -5,7 +5,7 @@ Action to push a remote repository to Dokku.
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
uses: https://lmika.dev/actions/push-to-dokku@v1
|
uses: https://lmika.dev/actions/push-to-dokku@v1.1
|
||||||
with:
|
with:
|
||||||
app: dokku-app-name
|
app: dokku-app-name
|
||||||
host: dokku-host
|
host: dokku-host
|
||||||
|
@ -17,6 +17,8 @@ Parameters are:
|
||||||
- `host`: hostname of the Dokku instance to push the application to.
|
- `host`: hostname of the Dokku instance to push the application to.
|
||||||
- `app`: the Dokku application name.
|
- `app`: the Dokku application name.
|
||||||
- `private-key`: the private SSH key
|
- `private-key`: the private SSH key
|
||||||
|
- `source-branch`: the code branch to push (default = `main`)
|
||||||
|
- `target-branch`: the Dokku branch to push to (default = same as source-branch)
|
||||||
|
|
||||||
This action requires Go 1.22.4 or later.
|
This action requires Go 1.22.4 or later.
|
||||||
|
|
||||||
|
|
16
config.go
16
config.go
|
@ -3,15 +3,19 @@ package main
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
HostName string
|
HostName string
|
||||||
AppName string
|
AppName string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
LocalBranch string
|
||||||
|
RemoteBranch string
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfig() config {
|
func readConfig() config {
|
||||||
return config{
|
return config{
|
||||||
HostName: os.Getenv("INPUT_HOST"),
|
HostName: os.Getenv("INPUT_HOST"),
|
||||||
AppName: os.Getenv("INPUT_APP"),
|
AppName: os.Getenv("INPUT_APP"),
|
||||||
PrivateKey: os.Getenv("INPUT_PRIVATE-KEY"),
|
PrivateKey: os.Getenv("INPUT_PRIVATE-KEY"),
|
||||||
|
LocalBranch: os.Getenv("INPUT_SOURCE-BRANCH"),
|
||||||
|
RemoteBranch: os.Getenv("INPUT_REMOTE-BRANCH"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
services.go
16
services.go
|
@ -67,7 +67,21 @@ func (s *Services) PushRepository() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runCmd("git", "push", "dokku", "main"); err != nil {
|
sourceBranch := s.cfg.LocalBranch
|
||||||
|
if sourceBranch == "" {
|
||||||
|
sourceBranch = "main"
|
||||||
|
}
|
||||||
|
remoteBranch := s.cfg.RemoteBranch
|
||||||
|
if remoteBranch == "" {
|
||||||
|
remoteBranch = sourceBranch
|
||||||
|
}
|
||||||
|
|
||||||
|
branchArg := sourceBranch
|
||||||
|
if sourceBranch != remoteBranch {
|
||||||
|
branchArg = fmt.Sprintf("%v:%v", sourceBranch, remoteBranch)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := runCmd("git", "push", "dokku", branchArg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue