Skip to content

Commit

Permalink
Initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
n-g committed Dec 12, 2023
1 parent 9edfc4a commit cd52ad8
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: example
on: [push, workflow_dispatch]

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
run_nscloud_action:
runs-on: nscloud
name: Sample CI workflow
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Test
run: go test ./...
30 changes: 30 additions & 0 deletions .github/workflows/with-cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: example-with-cache
on: [push, workflow_dispatch]

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
run-with-cache:
runs-on:
- namespace-profile-amd64-with-caching
name: Sample with cache
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
cache: false

- name: Set up cache
uses: namespacelabs/nscloud-cache-action@v1
with:
cache: go

- name: Test
run: |
go test ./...
23 changes: 23 additions & 0 deletions .github/workflows/without-cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: example-without-cache
on: [push, workflow_dispatch]

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
run-with-cache:
runs-on:
- nscloud-ubuntu-22.04-staging-amd64-2x4
name: Sample without cache
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Test
run: go test ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# go-cache
# Example repo leveraging nscloud runners in GitHub Actions
10 changes: 10 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"google.golang.org/grpc/codes"
"namespacelabs.dev/foundation/framework/rpcerrors"
)

func WrapError(errMsg error) error {
return rpcerrors.Errorf(codes.Internal, "%w", errMsg)
}
20 changes: 20 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"errors"
"strings"
"testing"
)

func TestGrpcError(t *testing.T) {
inputs := map[error]error{
errors.New("hello"): errors.New("hello"),
errors.New("world"): errors.New("world"),
}

for s, expected := range inputs {
if c := WrapError(s); !strings.Contains(c.Error(), expected.Error()) {
t.Errorf("Expected %v error is %v.", c, expected)
}
}
}
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/nscloud-demo/runner-example

go 1.20

require (
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
google.golang.org/grpc v1.57.0
namespacelabs.dev/foundation v0.0.276
)

require (
github.com/go-errors/errors v1.4.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
namespacelabs.dev/foundation v0.0.276 h1:OTJjqLi8vR5giAG/0Sm1HtSA7bpgkiA2UvdgeMz+S6w=
namespacelabs.dev/foundation v0.0.276/go.mod h1:Fi2Nx0i4b55j2O0cX5+lctT1oik1rm6/hZ0yB32FKLw=
18 changes: 18 additions & 0 deletions vowels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"golang.org/x/exp/slices"
)

var vowels = []byte{'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}

func CountVowels(s string) int {
var vowelsCount int
for i := range s {
if slices.Contains(vowels, s[i]) {
vowelsCount++
}
}

return vowelsCount
}
17 changes: 17 additions & 0 deletions vowels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import "testing"

func TestCountVowels(t *testing.T) {

inputs := map[string]int{
"hello": 2,
"world": 1,
}

for s, expected := range inputs {
if c := CountVowels(s); c != expected {
t.Errorf("Expected %d vowels, counted %d.", expected, c)
}
}
}

0 comments on commit cd52ad8

Please # to comment.