-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19 | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v -coverprofile=coverage.txt -covermode=atomic ./... | ||
|
||
- shell: bash | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
run: | | ||
# Replace `linux` below with the appropriate OS | ||
# Options are `alpine`, `linux`, `macos`, `windows` | ||
# You will need to setup the environment variables below in github | ||
# and the project in codecov.io | ||
curl -Os https://uploader.codecov.io/latest/linux/codecov | ||
chmod +x codecov | ||
CODECOV_TOKEN=$CODECOV_TOKEN ./codecov |
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 |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# go-module-template | ||
[![go.dev reference](https://pkg.go.dev/badge/github.com/soypat/go-module-template)](https://pkg.go.dev/github.com/soypat/go-module-template) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/soypat/go-module-template)](https://goreportcard.com/report/github.com/soypat/go-module-template) | ||
<!--[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) --> | ||
[![codecov](https://codecov.io/gh/soypat/go-module-template/branch/main/graph/badge.svg)](https://codecov.io/gh/soypat/go-module-template) | ||
|
||
Go module template with instructions on how to make your code importable and setting up codecov CI. | ||
|
||
## First steps | ||
Fix `go.mod` file by replacing `github.com/YOURUSER/YOURREPONAME` with your corresponding project repository link. | ||
|
||
## Setting up codecov CI | ||
This instructive will allow for tests to run on pull requests and pushes to your repository. | ||
|
||
1. Create an account on [codecov.io](https://app.codecov.io/) | ||
|
||
2. Setup repository on codecov and obtain the CODECOV_TOKEN token, which is a string of base64 characters. | ||
|
||
3. Open up the github repository for this project and go to `Settings -> Secrets and variables -> Actions`. Once there create a New Repository Secret. Name it `CODECOV_TOKEN` and copy paste the token obtained in the previous step in the `secret` input box. Click "Add secret". | ||
|
||
|
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,3 @@ | ||
module github.com/YOURUSER/YOURREPONAME | ||
|
||
go 1.20 |
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,10 @@ | ||
package gomoduletemplate | ||
|
||
// Fibonacci returns the nth number in the Fibonacci sequence. | ||
func Fibonacci(n int) int { | ||
a, b := 0, 1 | ||
for i := 0; i < n; i++ { | ||
a, b = b, a+b | ||
} | ||
return a | ||
} |
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,21 @@ | ||
package gomoduletemplate_test | ||
|
||
import ( | ||
"testing" | ||
|
||
gomoduletemplate "github.com/YOURUSER/YOURREPONAME" | ||
) | ||
|
||
func TestWorkingGoInstall(t *testing.T) { | ||
t.Log("Your go installation works!") | ||
} | ||
|
||
func TestFibonacci(t *testing.T) { | ||
var sequence = []int{0, 1, 1, 2, 3, 5, 8, 13, 21, 34} | ||
for nth, expected := range sequence { | ||
got := gomoduletemplate.Fibonacci(nth) | ||
if got != expected { | ||
t.Errorf("Fibonacci(%d) = %d, expected %d", nth, got, expected) | ||
} | ||
} | ||
} |