Skip to content

Commit

Permalink
chore: project scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard committed Feb 23, 2024
1 parent 2ce81c2 commit e3ba99d
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: jaredallard
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
!!!! README !!!! Please fill this out.
Please follow conventional commit naming conventions:
https://www.conventionalcommits.org/en/v1.0.0/#summary
-->

<!-- A short description of what your PR does and what it solves. -->
## What this PR does / why we need it


<!-- Notes that may be helpful for anyone reviewing this PR -->
## Notes for your reviewers
54 changes: 54 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: tests
on:
push:
branches:
- main
pull_request:

permissions:
contents: read

concurrency:
group: stencil-build-${{ github.head_ref }}
cancel-in-progress: true

jobs:
gotest:
name: go test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
with:
experimental: true
env:
GH_TOKEN: ${{ github.token }}
- name: Run go test
run: |
gotestsum -f github-actions -- -coverprofile=cover.out ./...
- name: Upload test coverage
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./cover.out
fail_ci_if_error: true

golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
with:
experimental: true
env:
GH_TOKEN: ${{ github.token }}
- name: Retrieve golangci-lint version
run: |
echo "version=$(mise current golangci-lint)" >> "$GITHUB_OUTPUT"
id: golangci_lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v${{ steps.golangci_lint.outputs.version }}
args: --timeout=30m
46 changes: 46 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: goreleaser

on:
push:
# Run only on tags
tags:
- "*"

permissions:
contents: write
packages: write

concurrency:
group: stencil-release-${{ github.head_ref }}
cancel-in-progress: true

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: jdx/mise-action@v2
with:
experimental: true
env:
GH_TOKEN: ${{ github.token }}
- name: Retrieve goreleaser version
run: |
echo "version=$(mise current goreleaser)" >> "$GITHUB_OUTPUT"
id: goreleaser
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: v${{ steps.goreleaser.outputs.version }}
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin
*.out
.DS_Store
16 changes: 16 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
[tools]
golang = "1.22"
golangci-lint = "1.56.2"
"go:gotest.tools/gotestsum" = "v1.11.0"
"go:golang.org/x/tools/cmd/goimports" = "latest"

[tasks.tests]
description = "Run tests"
run = ["gotestsum", "golangci-lint run --allow-parallel-runners --fast"]

[tasks.fmt]
alias = "format"
description = "Format code"
run = ["goimports -w ."]

[tasks.build]
description = "Build the project"
run = ["go mod download", "go build -trimpath -o bin/ ./cmd/..."]
22 changes: 8 additions & 14 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package parser

import (
"bufio"
"errors"
"fmt"
"io"
"reflect"
Expand Down Expand Up @@ -57,18 +56,13 @@ func parseColonDocuments(r io.Reader) ([]map[string]string, error) {
cur[parts[0]] = parts[1]
}
if scanner.Err() != nil {
if errors.Is(scanner.Err(), io.EOF) {
// Last entry, if cur is not empty (already had a newline?) append
// it.
if len(cur) > 0 {
out = append(out, cur)
}
return out, nil
}

return nil, scanner.Err()
}

// If we ended with a non-empty document, append it to the output now.
if len(cur) > 0 {
out = append(out, cur)
}
return out, nil
}

Expand Down Expand Up @@ -153,6 +147,7 @@ func (pkg *Package) EncodeInto(w io.Writer) error {
return nil
}

// ParsePackages parses the provided reader into a slice of packages.
func ParsePackages(r io.Reader) (Packages, error) {
docs, err := parseColonDocuments(r)
if err != nil {
Expand Down Expand Up @@ -202,13 +197,12 @@ func ParsePackages(r io.Reader) (Packages, error) {

// Remove the field from the map so we can check for missing
// fields later.
delete(tagToField, k)

delete(doc, k)
}

// Check for missing fields
if len(tagToField) > 0 {
return nil, fmt.Errorf("unknown fields: %v", tagToField)
if len(doc) > 0 {
return nil, fmt.Errorf("unknown fields: %v", doc)
}

pkgs = append(pkgs, pkg)
Expand Down

0 comments on commit e3ba99d

Please sign in to comment.