Use gh auth token for default GITHUB_TOKEN secret (#2651)

* initial version
This commit is contained in:
ChristopherHX
2025-02-09 04:24:32 +01:00
committed by GitHub
parent 101132dc86
commit cb26fd8670
3 changed files with 61 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ import (
"github.com/nektos/act/pkg/artifacts"
"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/container"
"github.com/nektos/act/pkg/gh"
"github.com/nektos/act/pkg/model"
"github.com/nektos/act/pkg/runner"
)
@@ -412,6 +413,15 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
log.Debugf("Loading secrets from %s", input.Secretfile())
secrets := newSecrets(input.secrets)
_ = readEnvs(input.Secretfile(), secrets)
hasGitHubToken := false
for k := range secrets {
if strings.EqualFold(k, "GITHUB_TOKEN") {
hasGitHubToken = true
}
}
if !hasGitHubToken {
secrets["GITHUB_TOKEN"], _ = gh.GetToken(ctx, "")
}
log.Debugf("Loading vars from %s", input.Varfile())
vars := newSecrets(input.vars)