-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3965728
commit 88dfbed
Showing
7 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package condition | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
type GitHubActions struct { | ||
} | ||
|
||
func (gha *GitHubActions) Name() string { | ||
return "GitHub Actions" | ||
} | ||
|
||
func (gha *GitHubActions) GetCurrentBranch() string { | ||
return os.Getenv("GITHUB_REF") | ||
} | ||
|
||
func (gha *GitHubActions) GetCurrentSHA() string { | ||
return os.Getenv("GITHUB_SHA") | ||
} | ||
|
||
func (gha *GitHubActions) IsBranchRef() bool { | ||
if val := os.Getenv("GITHUB_REF"); val != "" { | ||
return strings.HasPrefix(val, "refs/heads/") | ||
} | ||
return false | ||
} | ||
|
||
func (gha *GitHubActions) RunCondition(config CIConfig) error { | ||
if !gha.IsBranchRef() { | ||
return fmt.Errorf("not running on a branch") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package condition | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGithubValid(t *testing.T) { | ||
os.Setenv("GITHUB_REF", "") | ||
gha := GitHubActions{} | ||
err := gha.RunCondition(CIConfig{}) | ||
if err == nil { | ||
t.Fail() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters