From 59ababd476ea082d260bd1e0da5cfb9673454e66 Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:12:22 +0200 Subject: [PATCH 01/17] Initial commit --- .github/workflows/test.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..85969f9 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,14 @@ +# The "display name", shown in the GitHub UI +name: Build and test + +# Trigger, run on push on any branch +on: + push: + +jobs: + test: # The 'build' job + name: "Build application" + runs-on: 'ubuntu-latest' + steps: + # Step to print a simple message + - run: echo "Hello world" \ No newline at end of file From 9396a29314610ab7ac6880dafe3f4862f5f5b85e Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:15:48 +0200 Subject: [PATCH 02/17] Setup go --- .github/workflows/test.yaml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 85969f9..5bf83df 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,5 +10,14 @@ jobs: name: "Build application" runs-on: 'ubuntu-latest' steps: - # Step to print a simple message - - run: echo "Hello world" \ No newline at end of file + # Checkout code + - uses: actions/checkout@v4 + + # Install go 1.21 + - name: Setup go + uses: actions/setup-go@v4 + with: # Specify input variables to the action + go-version: '1.21.x' + + # Shell script to print the version + - run: go version \ No newline at end of file From d2eb92a9fc970d66de3a382904e057b8f2e08b65 Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:18:44 +0200 Subject: [PATCH 03/17] Add build and test steps --- .github/workflows/test.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5bf83df..fb3a680 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -20,4 +20,10 @@ jobs: go-version: '1.21.x' # Shell script to print the version - - run: go version \ No newline at end of file + - run: go version + + - name: Build + run: go buil -v ./... + + - name: Test + run: go test ./... \ No newline at end of file From fd0391942f60096c8f7b97da0229acafb4ba591c Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:18:57 +0200 Subject: [PATCH 04/17] Simulate build error --- internal/greeting/greet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/greeting/greet.go b/internal/greeting/greet.go index 68dc637..9e20a54 100644 --- a/internal/greeting/greet.go +++ b/internal/greeting/greet.go @@ -7,7 +7,7 @@ import ( func Greet(names []string) (string, error) { if len(names) == 0 { - return "", errors.New("at least one name must be specified") + retur "", errors.New("at least one name must be specified") } greeting := fmt.Sprintf("Hello %s", names[0]) From 419f432980825b40efce1ea9ae47fe877f68f6fa Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:19:59 +0200 Subject: [PATCH 05/17] Fix typo --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fb3a680..ba0c549 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,7 +23,7 @@ jobs: - run: go version - name: Build - run: go buil -v ./... + run: go build -v ./... - name: Test run: go test ./... \ No newline at end of file From 624eed0ffadd219ac9b4a5da901881d0a1dea38f Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:23:41 +0200 Subject: [PATCH 06/17] Fix build error --- internal/greeting/greet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/greeting/greet.go b/internal/greeting/greet.go index 9e20a54..68dc637 100644 --- a/internal/greeting/greet.go +++ b/internal/greeting/greet.go @@ -7,7 +7,7 @@ import ( func Greet(names []string) (string, error) { if len(names) == 0 { - retur "", errors.New("at least one name must be specified") + return "", errors.New("at least one name must be specified") } greeting := fmt.Sprintf("Hello %s", names[0]) From 806984865754f52f32be0c520423ee3b0925e714 Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:24:34 +0200 Subject: [PATCH 07/17] Simulate test error --- internal/greeting/greet_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/greeting/greet_test.go b/internal/greeting/greet_test.go index 620f53e..cd80eaa 100644 --- a/internal/greeting/greet_test.go +++ b/internal/greeting/greet_test.go @@ -5,7 +5,7 @@ import "testing" func TestGreetOneName(t *testing.T) { name := "Espen Askeladd" names := []string{name} - want := "Hello Espen Askeladd" + want := "Hello Espn Askeladd" got, err := Greet(names) if err != nil { From aad23e44b50b9cc9647520c9624c0a61e68d6492 Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:25:09 +0200 Subject: [PATCH 08/17] Fix test error --- internal/greeting/greet_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/greeting/greet_test.go b/internal/greeting/greet_test.go index cd80eaa..620f53e 100644 --- a/internal/greeting/greet_test.go +++ b/internal/greeting/greet_test.go @@ -5,7 +5,7 @@ import "testing" func TestGreetOneName(t *testing.T) { name := "Espen Askeladd" names := []string{name} - want := "Hello Espn Askeladd" + want := "Hello Espen Askeladd" got, err := Greet(names) if err != nil { From 02af7da27f09826ab6ef437b7d8e86682a0e5573 Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:27:58 +0200 Subject: [PATCH 09/17] Add build workflow --- .github/workflows/build.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..3933fe3 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,16 @@ +on: + push + +jobs: + build: + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + push: false + tags: ghcr.io/${{ github.repository }}:latest \ No newline at end of file From 789ba5b4eabb7c9ff11255351bf963e5f42cd29c Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:32:37 +0200 Subject: [PATCH 10/17] Push image to ghcr --- .github/workflows/build.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3933fe3..f6f9f09 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,14 +3,24 @@ on: jobs: build: + permissions: + packages: write + # ... runs-on, steps runs-on: 'ubuntu-latest' steps: - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Build and push Docker image uses: docker/build-push-action@v5 with: - push: false + push: true tags: ghcr.io/${{ github.repository }}:latest \ No newline at end of file From 30b077fb44fda427f34e0f9d10e9a6a25c747997 Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:38:36 +0200 Subject: [PATCH 11/17] Add linting --- .github/workflows/test.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ba0c549..3db6e82 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -6,6 +6,14 @@ on: push: jobs: + lint: + name: "Lint application" + runs-on: "ubuntu-latest" + steps: + - name: Verify formatting + run: | + no_unformatted_files="$(gofmt -l $(git ls-files '*.go') | wc -l)" + exit "$no_unformatted_files" test: # The 'build' job name: "Build application" runs-on: 'ubuntu-latest' From 12ad6c324733cf871002c797aef1d6cd31afa13e Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:41:34 +0200 Subject: [PATCH 12/17] Simulate lint error --- internal/greeting/greet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/greeting/greet.go b/internal/greeting/greet.go index 68dc637..51d54aa 100644 --- a/internal/greeting/greet.go +++ b/internal/greeting/greet.go @@ -7,7 +7,7 @@ import ( func Greet(names []string) (string, error) { if len(names) == 0 { - return "", errors.New("at least one name must be specified") + return "", errors.New("at least one name must be specified") } greeting := fmt.Sprintf("Hello %s", names[0]) From 03167b2d39b278be109c3955575014c3bce20da0 Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:43:48 +0200 Subject: [PATCH 13/17] Add checkout to lint job --- .github/workflows/test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3db6e82..3155dc1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,6 +10,8 @@ jobs: name: "Lint application" runs-on: "ubuntu-latest" steps: + - uses: actions/checkout@v4 + - name: Verify formatting run: | no_unformatted_files="$(gofmt -l $(git ls-files '*.go') | wc -l)" From 9d67754fae020c1ec207eea0018682f62819e8ea Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:44:36 +0200 Subject: [PATCH 14/17] Fix formatting --- internal/greeting/greet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/greeting/greet.go b/internal/greeting/greet.go index 51d54aa..68dc637 100644 --- a/internal/greeting/greet.go +++ b/internal/greeting/greet.go @@ -7,7 +7,7 @@ import ( func Greet(names []string) (string, error) { if len(names) == 0 { - return "", errors.New("at least one name must be specified") + return "", errors.New("at least one name must be specified") } greeting := fmt.Sprintf("Hello %s", names[0]) From 7691e49d91aaad78c90daf5c80ba350f1354028e Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:47:01 +0200 Subject: [PATCH 15/17] Run build workflow only on main --- .github/workflows/build.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f6f9f09..9bb0b1f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,5 +1,7 @@ on: - push + push: + branches: + - main jobs: build: From 134085f56cdeb70823e5243cfaeedc7a7c32980a Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:47:46 +0200 Subject: [PATCH 16/17] Only run test workflow on PRs --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3155dc1..3e51145 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,7 +3,7 @@ name: Build and test # Trigger, run on push on any branch on: - push: + pull_request: jobs: lint: From 6ed57b316afeba211d099340e65b45c607c2d53e Mon Sep 17 00:00:00 2001 From: Endre Waatevik Date: Fri, 7 Jun 2024 13:48:18 +0200 Subject: [PATCH 17/17] Add dummy change --- internal/greeting/greet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/greeting/greet.go b/internal/greeting/greet.go index 68dc637..e8a8788 100644 --- a/internal/greeting/greet.go +++ b/internal/greeting/greet.go @@ -7,7 +7,7 @@ import ( func Greet(names []string) (string, error) { if len(names) == 0 { - return "", errors.New("at least one name must be specified") + return "", errors.New("at least one name must be specified.") } greeting := fmt.Sprintf("Hello %s", names[0])