diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml new file mode 100644 index 0000000..d0b0600 --- /dev/null +++ b/.github/workflows/pr_checks.yml @@ -0,0 +1,74 @@ +name: Checks + +on: + pull_request: + +env: + GOPRIVATE: github.com/teamwork/* + GOFLAGS: -mod=readonly + LANG: en_US.UTF-8 + +jobs: + lint: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: "1.21" + + - name: Setup git + run: git config --global url."https://$GH_TOKEN@github.com/".insteadOf "https://github.com/" + + - name: Lint + uses: golangci/golangci-lint-action@v2 + with: + only-new-issues: true + args: "--out-${NO_FUTURE}format colored-line-number" + + test: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: "1.21" + + - name: Setup git + run: git config --global url."https://$GH_TOKEN@github.com/".insteadOf "https://github.com/" + + - name: Test + run: | + go mod tidy + go test -coverprofile=full.coverage -race -count=1 ./... + + - name: Generate diff + run: | + git diff origin/${{ github.base_ref }}...origin/${{ github.head_ref }} > pr.diff + + - name: Compute new code coverage + id: covdiffaction + uses: panagiotisptr/cov-diff@v1.2 + with: + path: . + coverprofile: full.coverage + diff: pr.diff + module: github.com/teamwork/mailaddress + + - name: Comment + uses: mshick/add-pr-comment@v2 + with: + message: | + Coverage on new code: ${{ steps.covdiffaction.outputs.covdiff }}% diff --git a/.github/workflows/teamwork.yml b/.github/workflows/teamwork.yml new file mode 100644 index 0000000..e067560 --- /dev/null +++ b/.github/workflows/teamwork.yml @@ -0,0 +1,18 @@ +name: teamwork + +on: + pull_request: + types: [opened, closed] + pull_request_review: + types: [submitted] + +jobs: + teamwork-sync: + runs-on: ubuntu-latest + name: Teamwork Sync + steps: + - uses: teamwork/github-sync@master + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TEAMWORK_URI: ${{ secrets.TEAMWORK_DC_URI }} + TEAMWORK_API_TOKEN: ${{ secrets.TEAMWORK_GHA_USER_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a7372ad..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: go -go: - - 1.16.x -go_import_path: github.com/teamwork/mailaddress -notifications: - email: false -cache: - directories: - - $HOME/gopath/pkg -install: - - ./bin/setup-travis -script: - - cd $HOME/gopath/src/github.com/teamwork/mailaddress - - ./bin/test - - ./bin/coverage - - ./bin/lint diff --git a/address_test.go b/address_test.go index 3563b32..6f91e08 100644 --- a/address_test.go +++ b/address_test.go @@ -55,6 +55,7 @@ func TestStringEncoded(t *testing.T) { {`martin@example.net`, `martin@example.net`}, {`Martin Tournoij `, `Martin Tournoij `}, {`"Martin Tournoij" `, `Martin Tournoij `}, + {`Martin Tour `, `Martin Tour noij `}, { `a العَرَبِي b `, `=?utf-8?q?a_=D8=A7=D9=84=D8=B9=D9=8E=D8=B1=D9=8E=D8=A8=D9=90=D9=8A_b?= `, diff --git a/bin/coverage b/bin/coverage deleted file mode 100755 index a62171d..0000000 --- a/bin/coverage +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -usage="Run coverage analyses and send it to Codecov." - -# Setup -####### -set -euC -root="$(cd "$(dirname "$0")/.." && pwd)" -. "$root/bin/start" - -# Run action -############ - -# Only test packages with actual test files. -test_pkgs=$(find -name "*_test.go" | - grep -v /vendor/ | - xargs dirname | - sort -u | - sed -e "s#^\.#$pkgname#") - -# Pass all packages to -coverpkg to list coverage for all packages, even those -# without tests. -allpkg=$(go list -tags="$test_tags" ./... | - grep -v /vendor/ | - tr '\n' , | - sed -e 's/,$//') - -# Cache -go test -i -covermode=count -tags="$test_tags" $(go list ./... | grep -v /vendor/) - -$pre_test_func - -echo 'mode: count' >| coverage.txt -for pkg in $test_pkgs; do - go test \ - -tags="$test_tags" \ - -covermode=count \ - -coverprofile=profile.out \ - -coverpkg=$allpkg \ - $pkg 2>&1 | grep -v 'warning: no packages being tested depend on ' - - if [ -f profile.out ]; then - tail -n+2 profile.out >> coverage.txt - rm profile.out - fi -done - -# The token is optional for public repos. -[ -n "${codecov_token:-}" ] && codecov_token="-t $codecov_token" - -if [ -n ${TRAVIS} ]; then - bash <(curl -s https://codecov.io/bash) $codecov_token -else - bash <(curl -s https://codecov.io/bash) \ - $codecov_token \ - -B $(git rev-parse --abbrev-ref HEAD) \ - -C $(git rev-parse HEAD) -fi diff --git a/bin/lint b/bin/lint deleted file mode 100755 index 1223d3b..0000000 --- a/bin/lint +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh - -# Setup -####### -set -euC -root="$(cd "$(dirname "$0")/.." && pwd)" -# shellcheck source=start -. "$root/bin/start" - -# Run action -############ - -ignore_metalinter() { - local IFS="$(printf '\n\b')" - for d in $lint_ignore; do printf " --skip-dirs %s" "$d"; done -} - -# Skip the linter on Travis if we're on a deployable branch. -if [ -n "$TRAVIS" ]; then - branch=${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH:-}} - branch=${branch:-$(git rev-parse --abbrev-ref HEAD)} - branch=${branch:-unknown} - case "$branch" in - master|beta|eu|unknown) - echo "We're on $branch; skipping lint tests" - exit 0 - ;; - esac -fi - -# Ensure generated files are up to date; only run on Travis to prevent -# clobbering people's working directories. -# TODO: Ideally this would never change the contents in the directory. -if [ -n "${TRAVIS:-}" ] && [ "${lint_skip_generate:-0}" = 0 ]; then - go generate ./... - changes="$(git diff)" - if [ -n "$changes" ]; then - echo - echo "*****************************************************" - echo "*** ***" - echo "*** Changes in generated files: ***" - echo "*** ***" - echo "*****************************************************" - echo - echo "$changes" - fi -fi - -export GO111MODULE=auto - -if [ -n "$TRAVIS" ]; then - if ! command -v golangci-lint; then - go get -u github.com/golangci/golangci-lint/cmd/golangci-lint - fi -fi - -# linters config at ../.golangci.yml -(cd -P .; golangci-lint run --skip-dirs testdata $(ignore_metalinter) "$@") - diff --git a/bin/setup-travis b/bin/setup-travis deleted file mode 100755 index 14bf119..0000000 --- a/bin/setup-travis +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -usage="Setup the environment for Travis" - -# Setup -####### -set -euC -root="$(cd "$(dirname "$0")/.." && pwd)" -. "$root/bin/start" - -# Run action -############ - -# Setup dep if it's used and vendor isn't in git. -if [ -f Gopkg.toml -a ! -d vendor ]; then - go get -u github.com/golang/dep/cmd/dep - dep ensure -fi diff --git a/bin/start b/bin/start deleted file mode 100644 index caf2e27..0000000 --- a/bin/start +++ /dev/null @@ -1,87 +0,0 @@ -# vi:ft=sh - -set -euC - -cd "$root" - -# Load settings -[ -f "$root/bin/settings" ] && . "$root/bin/settings" - -### -# Stuff to set in settings file. - -# Codecov token for coverage reports; only needed for private repos. -codecov_token=${codecov_token:-} - -# Tags to add to "go test" when running tests. -test_tags=${test_tags:-} - -# Verbose output? -verbose=${verbose:-0} - -# Directory names to ignore in the ./bin/lint script; multiple directories are -# separated by newlines. -lint_ignore="${lint_ignore:-}" - -# Callback to run before "go test" in ./bin/test and ./bin/coverage. -pre_test_func=${pre_test_func:-:} - - -### -# For the following the defaults should almost always be okay. If not, then -# consider fixing the project maybe? - -# Binary name. -name=${name:-$(basename "$root")} - -# Go package name -pkgname=${pkgname:-"github.com/teamwork/$name"} - -# Git branch -branch=${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}} - -# Docker image tag; usually the commit -docker_tag=${docker_tag:-${TRAVIS_COMMIT:-dev-env}} - -# Make sure this is set locally so we can do -z/-n. -TRAVIS=${TRAVIS:-} - -# So scripts can override this. -usage_func=${usage_func:-_usage} -options_func=${options_func:-_parse_options} - -# Usage info. -_usage() { - echo "Usage: ${0##*/} [-hv] [-t tag]" - echo - echo "$usage" - echo - echo "Options:" - echo " -h Show this help" - echo " -v Enable verbose output" - echo " -t Set tag for Docker and main.version" - echo " -b Go build tag; can be given more than once" - echo -} - -# Parse options -_parse_options() { - while getopts "hvt:b:" option; do - case "$option" in - h) $usage_func; exit 0 ;; - v) verbose=1; set -x ;; - t) tag=$OPTARG ;; - b) test_tags="$test_tags $OPTARG" ;; - *) - echo "error: unknown option '$option'" - $usage_func - exit 1 - ;; - esac - done - - [ -n "$test_tags" ] && test_tags="${test_tags# }" - return 0 -} - -$options_func "$@" diff --git a/bin/test b/bin/test deleted file mode 100755 index ba1e08e..0000000 --- a/bin/test +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -usage="Run all tests" - -# Setup -####### -set -euC -root="$(cd "$(dirname "$0")/.." && pwd)" -. "$root/bin/start" - -# Run action -############ - -# If we don't set this some stacks may not be complete when encountering race -# conditions. Uses a bit more memory, but we usually have enough of that. -export GORACE="history_size=4" - -$pre_test_func - -v_flag="" -[ $verbose -ge 1 ] && v_flag="-v" -go test $v_flag -race -tags="${test_tags# }" $(go list ./... | grep -v /vendor/) diff --git a/go.mod b/go.mod index 6f8b956..1203e5f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/teamwork/mailaddress -go 1.16 +go 1.21 require ( github.com/davecgh/go-spew v1.1.0 // indirect diff --git a/parse.go b/parse.go index be6a776..e5a097d 100644 --- a/parse.go +++ b/parse.go @@ -107,6 +107,13 @@ func parse(str string) (list List, haveError bool) { // End case !inQuote && chr == ">": addr.Raw += ">" + // we've observed name including `<>` + if i < len(str)-1 && !addr.Valid() { + addr.Name += " " + addr.Address + addr.Address = "" + addr.err = nil // valid is not idempoent + } + inAddress = false // Next
diff --git a/parse_test.go b/parse_test.go index cf832db..3a706d4 100644 --- a/parse_test.go +++ b/parse_test.go @@ -310,7 +310,7 @@ Tournoij func TestInvalid(t *testing.T) { for i, test := range invalidAddresses { - t.Run(fmt.Sprintf("%v", i), func(t *testing.T) { + t.Run(fmt.Sprintf("%d_%s", i, test), func(t *testing.T) { out, err := Parse(test) if out.Valid() { t.Fatal("out.Valid() said it was valid.")