Skip to content

Commit

Permalink
add ci (#3)
Browse files Browse the repository at this point in the history
* use gh's temp dir

* upload logs

* respond to push only on main

* use gh token env var

* update cache dep path

* don't make git error fatal

* change emoji

* git config test

* fix syntax error

* start on golden path test case

* check node version

* add test for node

* fix syntax

* yarn source check

* try run yarn

* fix command usage

* add multiple yarns test

* try organizing tests

* build before running tests

* try moving yarn bin

* debug log the exec env and add mv to ci

* try upgrading direct deps

* try removing patch version

* use version file over version

* correctly order go action and build

* add needs

* expect failures

---------

Co-authored-by: Dominic Saadi <[email protected]>
Co-authored-by: Josh GM Walker <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2024
1 parent 990bcc1 commit 560a094
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 43 deletions.
153 changes: 149 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: 🔄 CI
on:
pull_request:
push:
branches: [main]
workflow_dispatch:

# Cancel in-progress runs of this workflow.
Expand All @@ -11,18 +12,162 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
RW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
ci:
name: 🔄 CI
go:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version-file: ./cli/go.mod
cache-dependency-path: ./cli/go.sum

- run: make smoke-test

- run: ./rw create $TMPDIR/rw-test
git:
runs-on: ubuntu-latest
needs: go

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: ./cli/go.mod
cache-dependency-path: ./cli/go.sum

- run: make build

- uses: actions/setup-node@v4
with:
node-version: 20

- run: corepack enable

- name: Move runners default yarn bin
run: mv /usr/local/bin/yarn /usr/local/bin/yarn-moved

- name: Doesn't require git config
run: ./rw create ${{ runner.temp }}/rw-test-no-git-config

- name: Works with git config
run: |
git config --global user.email "[email protected]"
git config --global user.name "test"
./rw create ${{ runner.temp }}/rw-test-git-config
- uses: actions/upload-artifact@v4
if: always()
with:
name: git-logs
path: ~/.rw/debug.json

node:
runs-on: ubuntu-latest
needs: go

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: ./cli/go.mod
cache-dependency-path: ./cli/go.sum

- run: make build

- name: Errors if the node version is too low
run: |
# Disable immediate exit on error
set +e
./rw create ${{ runner.temp }}/rw-test-node-version-unmet
result=$?
set -e
if [ $result -eq 0 ]; then
echo "Command succeeded when it was expected to fail."
exit 1
else
echo "Command failed as expected."
exit 0
fi
- uses: actions/setup-node@v4
with:
node-version: 21
- run: corepack enable

- name: Move runners default yarn bin
run: mv /usr/local/bin/yarn /usr/local/bin/yarn-moved

- name: Allows node versions >= 20
run: |
./rw create ${{ runner.temp }}/rw-test-node-version-met
- uses: actions/upload-artifact@v4
if: always()
with:
name: node-logs
path: ~/.rw/debug.json

yarn:
runs-on: ubuntu-latest
needs: go

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: ./cli/go.mod
cache-dependency-path: ./cli/go.sum

- run: make build

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Errors if yarn is not used via corepack
run: |
# Disable immediate exit on error
set +e
./rw create ${{ runner.temp }}/rw-test-yarn-not-corepack
result=$?
set -e
if [ $result -eq 0 ]; then
echo "Command succeeded when it was expected to fail."
exit 1
else
echo "Command failed as expected."
exit 0
fi
- name: Errors if not all yarns are via corepack
run: |
corepack enable
# Disable immediate exit on error
set +e
./rw create ${{ runner.temp }}/rw-test-yarn-not-all-corepack
result=$?
set -e
if [ $result -eq 0 ]; then
echo "Command succeeded when it was expected to fail."
exit 1
else
echo "Command failed as expected."
exit 0
fi
- uses: actions/upload-artifact@v4
if: always()
with:
name: yarn-logs
path: ~/.rw/debug.json
38 changes: 32 additions & 6 deletions cli/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"strings"
"time"

"golang.org/x/mod/semver"

"github.com/charmbracelet/lipgloss"
"github.com/go-git/go-git/v5"
"github.com/google/go-github/v58/github"
Expand Down Expand Up @@ -286,9 +288,10 @@ func runCreate(cmd *cobra.Command, args []string) error {
err = setupGit(cmd, vTDir)
if err != nil {
slog.Error("failed to setup git", slog.String("error", err.Error()))
return err
fmt.Println(" ✋ Failed to complete git setup")
} else {
slog.Debug("git setup complete")
}
slog.Debug("git setup complete")
}

if yarnInstallFlag {
Expand Down Expand Up @@ -322,16 +325,19 @@ func checkNode() error {
slog.Debug("node found", slog.String("path", node))
}

// TODO(jgmw): Check node installation source

// Check node version
nodeVer, err := exec.Command("node", "-v").Output()
if err != nil {
return err
}
slog.Debug("node version", slog.String("version", string(nodeVer)))

// TODO(jgmw): Check node version against minimum version
// We require node 20
nodeReqVer := "v20.0.0"
if semver.Compare(nodeReqVer, strings.TrimSpace(string(nodeVer))) > 0 {
slog.Error("node version is too low", slog.String("version", string(nodeVer)), slog.String("required", nodeReqVer))
return fmt.Errorf("node version is too low")
}

return nil
}
Expand All @@ -342,11 +348,31 @@ func checkYarn() error {
return fmt.Errorf("yarn not found")
}
slog.Debug("yarn found", slog.Int("count", len(yarns)))
allCorepack := true
for _, yarn := range yarns {
slog.Debug("yarn found", slog.String("path", yarn))

// Run `exec env | grep COREPACK_ROOT`
out, err := exec.Command(yarn, "exec", "env").Output()
if err != nil {
slog.Error("failed to run yarn exec env", slog.String("error", err.Error()))
return err
}
sOut := string(out)
found := false
for _, line := range strings.Split(sOut, "\n") {
if strings.Contains(line, "COREPACK_ROOT=") {
slog.Debug("yarn is used via corepack", slog.String("line", line))
found = true
}
}
allCorepack = allCorepack && found
}

// TODO(jgmw): Check yarn installation source
if !allCorepack {
slog.Error("yarn is not used via corepack", slog.Bool("all", allCorepack))
return fmt.Errorf("yarn is not used via corepack")
}

return nil
}
Expand Down
23 changes: 12 additions & 11 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ module github.com/redwoodjs/rw-cli/cli
go 1.21.6

require (
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/term v0.15.0
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/term v0.16.0
)

require golang.org/x/mod v0.14.0

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
Expand All @@ -26,12 +28,11 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/rivo/uniseg v0.4.6 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

Expand All @@ -42,10 +43,10 @@ require (
github.com/hairyhenderson/go-which v0.2.0
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/spf13/afero v1.3.3 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
Loading

0 comments on commit 560a094

Please sign in to comment.