Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test workflows #16

Closed
wants to merge 17 commits into from
28 changes: 28 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
push:
branches:
- main

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: true
tags: ghcr.io/${{ github.repository }}:latest
39 changes: 39 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# The "display name", shown in the GitHub UI
name: Build and test

# Trigger, run on push on any branch
on:
pull_request:

jobs:
lint:
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)"
exit "$no_unformatted_files"
test: # The 'build' job
name: "Build application"
runs-on: 'ubuntu-latest'
steps:
# 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

- name: Build
run: go build -v ./...

- name: Test
run: go test ./...
2 changes: 1 addition & 1 deletion internal/greeting/greet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Loading