Skip to content

Commit

Permalink
website: Add deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
cbebe committed Oct 17, 2024
1 parent 62f826f commit 3db4a8a
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 14 deletions.
3 changes: 2 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
go 1.23
go 1.23.2

use (
./pkg/fyshls
./pkg/go-fysh
./pkg/web-interpreter
./pkg/website-old
./pkg/website/cmd
)
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
Expand Down
4 changes: 2 additions & 2 deletions pkg/fyshls/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ require (
github.com/tliron/kutil v0.3.24 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
)
6 changes: 2 additions & 4 deletions pkg/fyshls/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOM
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
3 changes: 3 additions & 0 deletions pkg/website-old/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ require (
)

require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/itchyny/gojq v0.12.13 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/tools v0.16.1 // indirect
mvdan.cc/sh/v3 v3.7.0 // indirect
)
9 changes: 3 additions & 6 deletions pkg/website-old/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ github.com/bitfield/script v0.22.1 h1:DphxoC5ssYciwd0ZS+N0Xae46geAD/0mVWh6a2NUxM
github.com/bitfield/script v0.22.1/go.mod h1:fv+6x4OzVsRs6qAlc7wiGq8fq1b5orhtQdtW0dwjUHI=
github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA=
github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/itchyny/gojq v0.12.13 h1:IxyYlHYIlspQHHTE0f3cJF0NKDMfajxViuhBLnHd/QU=
github.com/itchyny/gojq v0.12.13/go.mod h1:JzwzAqenfhrPUuwbmEz3nu3JQmFLlQTQMUcOdnu/Sf4=
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
Expand All @@ -16,9 +15,7 @@ github.com/plus3it/gorecurcopy v0.0.1 h1:H7AgvM0N/uIo7o1PQRlewEGQ92BNr7DqbPy5lnR
github.com/plus3it/gorecurcopy v0.0.1/go.mod h1:NvVTm4RX68A1vQbHmHunDO4OtBLVroT6CrsiqAzNyJA=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
mvdan.cc/sh/v3 v3.7.0 h1:lSTjdP/1xsddtaKfGg7Myu7DnlHItd3/M2tomOcNNBg=
mvdan.cc/sh/v3 v3.7.0/go.mod h1:K2gwkaesF/D7av7Kxl0HbF5kGOd2ArupNTX3X44+8l8=
17 changes: 17 additions & 0 deletions pkg/website/cmd/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/Fysh-Fyve/fysh/pkg/website/cmd

go 1.23.2

require (
github.com/bitfield/script v0.22.1
github.com/plus3it/gorecurcopy v0.0.1
)

require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/itchyny/gojq v0.12.13 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/tools v0.16.1 // indirect
mvdan.cc/sh/v3 v3.7.0 // indirect
)
24 changes: 24 additions & 0 deletions pkg/website/cmd/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
github.com/bitfield/script v0.22.1 h1:DphxoC5ssYciwd0ZS+N0Xae46geAD/0mVWh6a2NUxM4=
github.com/bitfield/script v0.22.1/go.mod h1:fv+6x4OzVsRs6qAlc7wiGq8fq1b5orhtQdtW0dwjUHI=
github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA=
github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/itchyny/gojq v0.12.13 h1:IxyYlHYIlspQHHTE0f3cJF0NKDMfajxViuhBLnHd/QU=
github.com/itchyny/gojq v0.12.13/go.mod h1:JzwzAqenfhrPUuwbmEz3nu3JQmFLlQTQMUcOdnu/Sf4=
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/plus3it/gorecurcopy v0.0.1 h1:H7AgvM0N/uIo7o1PQRlewEGQ92BNr7DqbPy5lnR3uJI=
github.com/plus3it/gorecurcopy v0.0.1/go.mod h1:NvVTm4RX68A1vQbHmHunDO4OtBLVroT6CrsiqAzNyJA=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
mvdan.cc/sh/v3 v3.7.0 h1:lSTjdP/1xsddtaKfGg7Myu7DnlHItd3/M2tomOcNNBg=
mvdan.cc/sh/v3 v3.7.0/go.mod h1:K2gwkaesF/D7av7Kxl0HbF5kGOd2ArupNTX3X44+8l8=
99 changes: 99 additions & 0 deletions pkg/website/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Deploy script for github pages
// Loosely based on Docusaurus Github Pages deploy script
// https://github.com/facebook/docusaurus/blob/542228ee1beb5cfddd7ba8ae088f109f164e80c5/packages/docusaurus/src/commands/deploy.ts#L43

package main

import (
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"

"github.com/bitfield/script"
"github.com/plus3it/gorecurcopy"
)

var buildDir = path.Join("dist", "pkg", "website")

const (
originUrl = "https://github.com/Fysh-Fyve/Fysh-Fyve.github.io"
projectName = "fysh-five.github.io"
deploymentBranch = "gh-pages"
buildCmd = ""
)

func execCmd(cmd string) error {
if cmd == "" {
return nil
}
log.Println(cmd)
p := script.Exec(cmd)
p.Stdout()
return p.Error()
}

func getCmdOutput(cmd string) string {
out, err := script.Exec(cmd).String()
if err != nil {
log.Fatalf("failed command `%s`: %v", cmd, err)
}
return strings.TrimSpace(out)
}

func mkTmpDir() (string, func()) {
dir, err := os.MkdirTemp(os.TempDir(), projectName+"-"+deploymentBranch)
if err != nil {
log.Fatalf("failed to make temp dir: %v", err)
}
return dir, func() {
if err := os.RemoveAll(dir); err != nil {
log.Printf("failed to remove dir: %v\n", err)
}
}
}

func dieIf(err error) {
if err != nil {
log.Fatal(err)
}
}

func main() {
if err := os.RemoveAll("public"); err != nil {
log.Printf("failed to remove dir: %v\n", err)
}
getCmdOutput("git config --get remote.origin.url")
latestHash := getCmdOutput("git rev-parse HEAD")

dieIf(execCmd(buildCmd))

src, err := filepath.Abs(buildDir)
dieIf(err)
gitPublish, cleanGitPublish := mkTmpDir()
defer cleanGitPublish()

os.Chdir(gitPublish)
cloneCmd := fmt.Sprintf("git clone --depth 1 --branch \"%s\" \"%s\" \"%s\"", deploymentBranch, originUrl, gitPublish)
if err := execCmd(cloneCmd); err != nil {
// Branch doesn't exist, create new branch
dieIf(execCmd("git init"))
dieIf(execCmd("git checkout -b " + deploymentBranch))
dieIf(execCmd("git remote add origin " + originUrl))
} else {
dieIf(execCmd("git rm -rf .")) // Simply remove all files
}
if err := gorecurcopy.CopyDirectory(src, gitPublish); err != nil {
log.Fatalf("failed to copy output to publish dir: %v", err)
}
os.Chdir(gitPublish)
dieIf(execCmd("git add --all"))
commitErr := execCmd(fmt.Sprintf("git commit -m \"Deploy website - based on %s\"", latestHash))
if err := execCmd("git push --force origin " + deploymentBranch); err != nil {
log.Fatalf("failed to push to origin: %v", err)
} else if commitErr == nil {
fmt.Printf("Website is live at: https://%s\n", projectName)
}
}
2 changes: 1 addition & 1 deletion pkg/website/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ sidebar_position: 1

## ⚙️ Option 2: Using Command Line

1. Install the latest version `go install github.com/Fysh-Fyve/fysh@latest`
1. Install the latest version `go install github.com/Fysh-Fyve/fysh/pkg/go-fysh/cmd@latest`
2. Execute with `fysh <filename>.fysh`.
8 changes: 8 additions & 0 deletions pkg/website/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"options": {
"port": 3000
}
},
"deploy": {
"dependsOn": ["build"],
"executor": "nx:run-commands",
"options": {
"command": "go run pkg/website/cmd/main.go",
"cwd": "{workspaceRoot}"
}
}
},
"tags": []
Expand Down

0 comments on commit 3db4a8a

Please sign in to comment.