Skip to content

Commit

Permalink
Golang get version from env
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcat committed Jun 20, 2022
1 parent 4181125 commit 705a656
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get Branch Name
run: echo "branch_name=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: Get Version
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: Echo Branch Name
run: echo '${{ env.branch_name }}'
- name: Find and Replace
uses: jacobtomlinson/gha-find-replace@v2
if: startsWith(github.ref, 'refs/tags/')
with:
find: "@@VERSION@@"
replace: ${{ env.branch_name }}
include: main.go
regex: false
- name: gitignore main.go after version injection
run: echo "\nmain.go" >> .gitignore
run: echo '${{ env.VERSION }}'
- name: Set up Go
uses: actions/setup-go@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"goreleaser",
"hasher",
"jacobtomlinson",
"ldflags",
"manifoldco",
"obsstudio",
"promptui"
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var mainScript string
//go:embed js/body.js
var bodyScript string

var VERSION = "@@VERSION@@" // Used with github action string replace to inject release version here
var version = "DEV"

// UserAnswers holds config answers from command line prompt ui
type UserAnswers struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ var (
)

func main() {
fmt.Printf("OBS Random Video: %s\n\n", VERSION);
fmt.Printf("OBS Random Video: %s\n\n", version);
mainDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatalf("Failed to get current directory path: %v", err)
Expand All @@ -85,7 +85,7 @@ func main() {
answers.MediaFiles = removeTransitionVideo(answers.TransitionVideo, answers.MediaFiles)
}

templateHTML = "<!--\nOBS Random Videos: "+VERSION+"\nAUTO GENERATED FILE\nDON'T TOUCH\n-->\n" + templateHTML
templateHTML = "<!--\nOBS Random Videos: "+version+"\nAUTO GENERATED FILE\nDON'T TOUCH\n-->\n" + templateHTML
var outputHTML bytes.Buffer
t := template.Must(template.New("HTML").Parse(templateHTML))
err = t.Execute(&outputHTML, scripts)
Expand Down Expand Up @@ -257,4 +257,4 @@ func showQuestion(message string, defaultValueFlag bool) bool {
result = strings.ToLower(result)
time.Sleep(promptDelay)
return result == "y" || result == "yes"
}
}

0 comments on commit 705a656

Please sign in to comment.