Skip to content

Commit de37f75

Browse files
authored
feat: add option to bypass GHE for actions checkout (#1162)
* feat(#1161): add --through-action to assigned actions from GitHub * docs(flags): add --through-action and --through-action-token flags description * test(action, remote): add test case for ThroughAction * refactor(command): rename command from --through-action to --actions-from-github * refactor(command): rename command from --actions-from-github to --replace-ghe-action-with-github.lhy31512.workers.dev
1 parent 9d7595a commit de37f75

File tree

6 files changed

+286
-127
lines changed

6 files changed

+286
-127
lines changed

README.md

+38-36
Original file line numberDiff line numberDiff line change
@@ -159,42 +159,44 @@ It will save that information to `~/.actrc`, please refer to [Configuration](#co
159159
# Flags
160160

161161
```none
162-
-a, --actor string user that triggered the event (default "nektos/act")
163-
--artifact-server-path string Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start.
164-
--artifact-server-port string Defines the port where the artifact server listens (will only bind to localhost). (default "34567")
165-
-b, --bind bind working directory to container, rather than copy
166-
--container-architecture string Architecture which should be used to run containers, e.g.: linux/amd64. If not specified, will use host default architecture. Requires Docker server API Version 1.41+. Ignored on earlier Docker server platforms.
167-
--container-cap-add stringArray kernel capabilities to add to the workflow containers (e.g. --container-cap-add SYS_PTRACE)
168-
--container-cap-drop stringArray kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE)
169-
--container-daemon-socket string Path to Docker daemon socket which will be mounted to containers (default "/var/run/docker.sock")
170-
--defaultbranch string the name of the main branch
171-
--detect-event Use first event type from workflow as event that triggered the workflow
172-
-C, --directory string working directory (default ".")
173-
-n, --dryrun dryrun mode
174-
--env stringArray env to make available to actions with optional value (e.g. --env myenv=foo or --env myenv)
175-
--env-file string environment file to read and use as env in the containers (default ".env")
176-
-e, --eventpath string path to event JSON file
177-
--github-instance string GitHub instance to use. Don't use this if you are not using GitHub Enterprise Server. (default "github.com")
178-
-g, --graph draw workflows
179-
-h, --help help for act
180-
--insecure-secrets NOT RECOMMENDED! Doesn't hide secrets while printing logs.
181-
-j, --job string run job
182-
-l, --list list workflows
183-
--no-recurse Flag to disable running workflows from subdirectories of specified path in '--workflows'/'-W' flag
184-
-P, --platform stringArray custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)
185-
--privileged use privileged mode
186-
-p, --pull pull docker image(s) even if already present
187-
-q, --quiet disable logging of output from steps
188-
--rebuild rebuild local action docker image(s) even if already present
189-
-r, --reuse don't remove container(s) on successfully completed workflow(s) to maintain state between runs
190-
--rm automatically remove container(s)/volume(s) after a workflow(s) failure
191-
-s, --secret stringArray secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)
192-
--secret-file string file with list of secrets to read from (e.g. --secret-file .secrets) (default ".secrets")
193-
--use-gitignore Controls whether paths specified in .gitignore should be copied into container (default true)
194-
--userns string user namespace to use
195-
-v, --verbose verbose output
196-
-w, --watch watch the contents of the local repo and run when files change
197-
-W, --workflows string path to workflow file(s) (default "./.github/workflows/")
162+
-a, --actor string user that triggered the event (default "nektos/act")
163+
--replace-ghe-action-with-github.lhy31512.workers.dev If you are using GitHub Enterprise Server and allow specified actions from GitHub (github.com), you can set actions on this. (e.g. --replace-ghe-action-with-github.lhy31512.workers.dev=github/super-linter)
164+
--replace-ghe-action-token-with-github.lhy31512.workers.dev If you are using replace-ghe-action-with-github.lhy31512.workers.dev and you want to use private actions on GitHub, you have to set personal access token
165+
--artifact-server-path string Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start.
166+
--artifact-server-port string Defines the port where the artifact server listens (will only bind to localhost). (default "34567")
167+
-b, --bind bind working directory to container, rather than copy
168+
--container-architecture string Architecture which should be used to run containers, e.g.: linux/amd64. If not specified, will use host default architecture. Requires Docker server API Version 1.41+. Ignored on earlier Docker server platforms.
169+
--container-cap-add stringArray kernel capabilities to add to the workflow containers (e.g. --container-cap-add SYS_PTRACE)
170+
--container-cap-drop stringArray kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE)
171+
--container-daemon-socket string Path to Docker daemon socket which will be mounted to containers (default "/var/run/docker.sock")
172+
--defaultbranch string the name of the main branch
173+
--detect-event Use first event type from workflow as event that triggered the workflow
174+
-C, --directory string working directory (default ".")
175+
-n, --dryrun dryrun mode
176+
--env stringArray env to make available to actions with optional value (e.g. --env myenv=foo or --env myenv)
177+
--env-file string environment file to read and use as env in the containers (default ".env")
178+
-e, --eventpath string path to event JSON file
179+
--github-instance string GitHub instance to use. Don't use this if you are not using GitHub Enterprise Server. (default "github.com")
180+
-g, --graph draw workflows
181+
-h, --help help for act
182+
--insecure-secrets NOT RECOMMENDED! Doesn't hide secrets while printing logs.
183+
-j, --job string run job
184+
-l, --list list workflows
185+
--no-recurse Flag to disable running workflows from subdirectories of specified path in '--workflows'/'-W' flag
186+
-P, --platform stringArray custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)
187+
--privileged use privileged mode
188+
-p, --pull pull docker image(s) even if already present
189+
-q, --quiet disable logging of output from steps
190+
--rebuild rebuild local action docker image(s) even if already present
191+
-r, --reuse don't remove container(s) on successfully completed workflow(s) to maintain state between runs
192+
--rm automatically remove container(s)/volume(s) after a workflow(s) failure
193+
-s, --secret stringArray secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)
194+
--secret-file string file with list of secrets to read from (e.g. --secret-file .secrets) (default ".secrets")
195+
--use-gitignore Controls whether paths specified in .gitignore should be copied into container (default true)
196+
--userns string user namespace to use
197+
-v, --verbose verbose output
198+
-w, --watch watch the contents of the local repo and run when files change
199+
-W, --workflows string path to workflow file(s) (default "./.github/workflows/")
198200
```
199201

200202
## `GITHUB_TOKEN`

cmd/input.go

+35-33
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,41 @@ import (
88

99
// Input contains the input for the root command
1010
type Input struct {
11-
actor string
12-
workdir string
13-
workflowsPath string
14-
autodetectEvent bool
15-
eventPath string
16-
reuseContainers bool
17-
bindWorkdir bool
18-
secrets []string
19-
envs []string
20-
platforms []string
21-
dryrun bool
22-
forcePull bool
23-
forceRebuild bool
24-
noOutput bool
25-
envfile string
26-
secretfile string
27-
insecureSecrets bool
28-
defaultBranch string
29-
privileged bool
30-
usernsMode string
31-
containerArchitecture string
32-
containerDaemonSocket string
33-
noWorkflowRecurse bool
34-
useGitIgnore bool
35-
githubInstance string
36-
containerCapAdd []string
37-
containerCapDrop []string
38-
autoRemove bool
39-
artifactServerPath string
40-
artifactServerPort string
41-
jsonLogger bool
42-
noSkipCheckout bool
43-
remoteName string
11+
actor string
12+
workdir string
13+
workflowsPath string
14+
autodetectEvent bool
15+
eventPath string
16+
reuseContainers bool
17+
bindWorkdir bool
18+
secrets []string
19+
envs []string
20+
platforms []string
21+
dryrun bool
22+
forcePull bool
23+
forceRebuild bool
24+
noOutput bool
25+
envfile string
26+
secretfile string
27+
insecureSecrets bool
28+
defaultBranch string
29+
privileged bool
30+
usernsMode string
31+
containerArchitecture string
32+
containerDaemonSocket string
33+
noWorkflowRecurse bool
34+
useGitIgnore bool
35+
githubInstance string
36+
containerCapAdd []string
37+
containerCapDrop []string
38+
autoRemove bool
39+
artifactServerPath string
40+
artifactServerPort string
41+
jsonLogger bool
42+
noSkipCheckout bool
43+
remoteName string
44+
replaceGheActionWithGithubCom []string
45+
replaceGheActionTokenWithGithubCom string
4446
}
4547

4648
func (i *Input) resolve(path string) string {

cmd/root.go

+33-29
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func Execute(ctx context.Context, version string) {
6161
rootCmd.Flags().StringArrayVarP(&input.containerCapAdd, "container-cap-add", "", []string{}, "kernel capabilities to add to the workflow containers (e.g. --container-cap-add SYS_PTRACE)")
6262
rootCmd.Flags().StringArrayVarP(&input.containerCapDrop, "container-cap-drop", "", []string{}, "kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE)")
6363
rootCmd.Flags().BoolVar(&input.autoRemove, "rm", false, "automatically remove container(s)/volume(s) after a workflow(s) failure")
64+
rootCmd.Flags().StringArrayVarP(&input.replaceGheActionWithGithubCom, "replace-ghe-action-with-github.lhy31512.workers.dev", "", []string{}, "If you are using GitHub Enterprise Server and allow specified actions from GitHub (github.com), you can set actions on this. (e.g. --replace-ghe-action-with-github.lhy31512.workers.dev =github/super-linter)")
65+
rootCmd.Flags().StringVar(&input.replaceGheActionTokenWithGithubCom, "replace-ghe-action-token-with-github.lhy31512.workers.dev", "", "If you are using replace-ghe-action-with-github.lhy31512.workers.dev and you want to use private actions on GitHub, you have to set personal access token")
6466
rootCmd.PersistentFlags().StringVarP(&input.actor, "actor", "a", "nektos/act", "user that triggered the event")
6567
rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow file(s)")
6668
rootCmd.PersistentFlags().BoolVarP(&input.noWorkflowRecurse, "no-recurse", "", false, "Flag to disable running workflows from subdirectories of specified path in '--workflows'/'-W' flag")
@@ -370,35 +372,37 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
370372

371373
// run the plan
372374
config := &runner.Config{
373-
Actor: input.actor,
374-
EventName: eventName,
375-
EventPath: input.EventPath(),
376-
DefaultBranch: defaultbranch,
377-
ForcePull: input.forcePull,
378-
ForceRebuild: input.forceRebuild,
379-
ReuseContainers: input.reuseContainers,
380-
Workdir: input.Workdir(),
381-
BindWorkdir: input.bindWorkdir,
382-
LogOutput: !input.noOutput,
383-
JSONLogger: input.jsonLogger,
384-
Env: envs,
385-
Secrets: secrets,
386-
Token: secrets["GITHUB_TOKEN"],
387-
InsecureSecrets: input.insecureSecrets,
388-
Platforms: input.newPlatforms(),
389-
Privileged: input.privileged,
390-
UsernsMode: input.usernsMode,
391-
ContainerArchitecture: input.containerArchitecture,
392-
ContainerDaemonSocket: input.containerDaemonSocket,
393-
UseGitIgnore: input.useGitIgnore,
394-
GitHubInstance: input.githubInstance,
395-
ContainerCapAdd: input.containerCapAdd,
396-
ContainerCapDrop: input.containerCapDrop,
397-
AutoRemove: input.autoRemove,
398-
ArtifactServerPath: input.artifactServerPath,
399-
ArtifactServerPort: input.artifactServerPort,
400-
NoSkipCheckout: input.noSkipCheckout,
401-
RemoteName: input.remoteName,
375+
Actor: input.actor,
376+
EventName: eventName,
377+
EventPath: input.EventPath(),
378+
DefaultBranch: defaultbranch,
379+
ForcePull: input.forcePull,
380+
ForceRebuild: input.forceRebuild,
381+
ReuseContainers: input.reuseContainers,
382+
Workdir: input.Workdir(),
383+
BindWorkdir: input.bindWorkdir,
384+
LogOutput: !input.noOutput,
385+
JSONLogger: input.jsonLogger,
386+
Env: envs,
387+
Secrets: secrets,
388+
Token: secrets["GITHUB_TOKEN"],
389+
InsecureSecrets: input.insecureSecrets,
390+
Platforms: input.newPlatforms(),
391+
Privileged: input.privileged,
392+
UsernsMode: input.usernsMode,
393+
ContainerArchitecture: input.containerArchitecture,
394+
ContainerDaemonSocket: input.containerDaemonSocket,
395+
UseGitIgnore: input.useGitIgnore,
396+
GitHubInstance: input.githubInstance,
397+
ContainerCapAdd: input.containerCapAdd,
398+
ContainerCapDrop: input.containerCapDrop,
399+
AutoRemove: input.autoRemove,
400+
ArtifactServerPath: input.artifactServerPath,
401+
ArtifactServerPort: input.artifactServerPort,
402+
NoSkipCheckout: input.noSkipCheckout,
403+
RemoteName: input.remoteName,
404+
ReplaceGheActionWithGithubCom: input.replaceGheActionWithGithubCom,
405+
ReplaceGheActionTokenWithGithubCom: input.replaceGheActionTokenWithGithubCom,
402406
}
403407
r, err := runner.New(config)
404408
if err != nil {

0 commit comments

Comments
 (0)