Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #910 from mmlb/export-github-actions
Add GitHub Actions export only shell
- Loading branch information
Showing
4 changed files
with
80 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type gha struct{} | ||
|
||
// GitHubActions shell instance | ||
var GitHubActions Shell = gha{} | ||
|
||
func (sh gha) Hook() (string, error) { | ||
return "", fmt.Errorf("Hook not implemented for GitHub Actions shell") | ||
} | ||
|
||
func (sh gha) Export(e ShellExport) string { | ||
var b strings.Builder | ||
for key, value := range e { | ||
if value == nil { | ||
sh.unset(&b, key) | ||
} else { | ||
sh.export(&b, key, *value) | ||
} | ||
} | ||
return b.String() | ||
} | ||
|
||
const ghaDelim = "DIRENV_GITHUB_ACTIONS_EOV\n" | ||
|
||
func (sh gha) Dump(env Env) string { | ||
var b strings.Builder | ||
|
||
for key, value := range env { | ||
sh.export(&b, key, value) | ||
} | ||
return b.String() | ||
} | ||
|
||
func (sh gha) export(b *strings.Builder, key, value string) { | ||
b.WriteString(key) | ||
b.WriteString("<<") | ||
b.WriteString(ghaDelim) | ||
b.WriteString(value) | ||
if value != "" && !strings.HasSuffix(value, "\n") { | ||
b.WriteByte('\n') | ||
} | ||
b.WriteString(ghaDelim) | ||
} | ||
|
||
func (sh gha) unset(b *strings.Builder, key string) { | ||
sh.export(b, key, "") | ||
} |
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 @@ | ||
export TEST_EXPORT_DIRENV_GITHUB_ACTIONS="${GITHUB_SHA:-MISSING_GITHUB_SHA}"$'\n'"${GITHUB_RUN_ID:MISSING_GITHUB_RUN_ID}"$'\n'"${GITHUB_RUN_NUMBER:-MISSING_GITHUB_RUN_NUMBER}" |