Add support for changing the GITHUB_ACTOR (#229)
This adds the `-a` flag when running `act` to change the username of the GITHUB_ACTOR environment variable Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
a149cf8ca2
commit
a5e86bd024
4 changed files with 11 additions and 1 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
// Input contains the input for the root command
|
// Input contains the input for the root command
|
||||||
type Input struct {
|
type Input struct {
|
||||||
|
actor string
|
||||||
workdir string
|
workdir string
|
||||||
workflowsPath string
|
workflowsPath string
|
||||||
eventPath string
|
eventPath string
|
||||||
|
|
|
@ -41,6 +41,7 @@ func Execute(ctx context.Context, version string) {
|
||||||
rootCmd.Flags().BoolVarP(&input.bindWorkdir, "bind", "b", false, "bind working directory to container, rather than copy")
|
rootCmd.Flags().BoolVarP(&input.bindWorkdir, "bind", "b", false, "bind working directory to container, rather than copy")
|
||||||
rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", false, "pull docker image(s) if already present")
|
rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", false, "pull docker image(s) if already present")
|
||||||
rootCmd.Flags().StringVarP(&input.eventPath, "eventpath", "e", "", "path to event JSON file")
|
rootCmd.Flags().StringVarP(&input.eventPath, "eventpath", "e", "", "path to event JSON file")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&input.actor, "actor", "a", "nektos/act", "user that triggered the event")
|
||||||
rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow files")
|
rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow files")
|
||||||
rootCmd.PersistentFlags().StringVarP(&input.workdir, "directory", "C", ".", "working directory")
|
rootCmd.PersistentFlags().StringVarP(&input.workdir, "directory", "C", ".", "working directory")
|
||||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
|
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
|
||||||
|
@ -156,6 +157,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
|
||||||
|
|
||||||
// run the plan
|
// run the plan
|
||||||
config := &runner.Config{
|
config := &runner.Config{
|
||||||
|
Actor: input.actor,
|
||||||
EventName: eventName,
|
EventName: eventName,
|
||||||
EventPath: input.EventPath(),
|
EventPath: input.EventPath(),
|
||||||
ForcePull: input.forcePull,
|
ForcePull: input.forcePull,
|
||||||
|
|
|
@ -355,13 +355,19 @@ func (rc *RunContext) getGithubContext() *githubContext {
|
||||||
Workflow: rc.Run.Workflow.Name,
|
Workflow: rc.Run.Workflow.Name,
|
||||||
RunID: "1",
|
RunID: "1",
|
||||||
RunNumber: "1",
|
RunNumber: "1",
|
||||||
Actor: "nektos/act",
|
Actor: rc.Config.Actor,
|
||||||
EventName: rc.Config.EventName,
|
EventName: rc.Config.EventName,
|
||||||
Token: token,
|
Token: token,
|
||||||
Workspace: "/github/workspace",
|
Workspace: "/github/workspace",
|
||||||
Action: rc.CurrentStep,
|
Action: rc.CurrentStep,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backwards compatibility for configs that require
|
||||||
|
// a default rather than being run as a cmd
|
||||||
|
if ghc.Actor == "" {
|
||||||
|
ghc.Actor = "nektos/act"
|
||||||
|
}
|
||||||
|
|
||||||
repoPath := rc.Config.Workdir
|
repoPath := rc.Config.Workdir
|
||||||
repo, err := common.FindGithubRepo(repoPath)
|
repo, err := common.FindGithubRepo(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -17,6 +17,7 @@ type Runner interface {
|
||||||
|
|
||||||
// Config contains the config for a new runner
|
// Config contains the config for a new runner
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Actor string // the user that triggered the event
|
||||||
Workdir string // path to working directory
|
Workdir string // path to working directory
|
||||||
BindWorkdir bool // bind the workdir to the job container
|
BindWorkdir bool // bind the workdir to the job container
|
||||||
EventName string // name of event to run
|
EventName string // name of event to run
|
||||||
|
|
Loading…
Reference in a new issue