Skip to content

Commit

Permalink
Fix CI issues (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshsadiq committed Jan 2, 2023
1 parent 1a4ec2c commit f58362c
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 101 deletions.
1 change: 0 additions & 1 deletion .github/labeler.yml
Expand Up @@ -13,4 +13,3 @@
# changes to shell completions
"area/*sh completion":
- ./*completions*

1 change: 0 additions & 1 deletion .github/workflows/labeler.yml
Expand Up @@ -9,4 +9,3 @@ jobs:
- uses: actions/labeler@v3
with:
repo-token: "${{ github.token }}"

18 changes: 12 additions & 6 deletions .github/workflows/site.yml
Expand Up @@ -2,14 +2,20 @@ name: 'site'

on:
push:
paths:
- 'site/**'
- '.github/workflows/site.yml'
pull_request:
paths:
- 'site/**'
- '.github/workflows/site.yml'

jobs:
doc:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Get Hugo and Theme
run: |
Expand All @@ -26,21 +32,21 @@ jobs:
run: |
cd site
hugo version
hugo
- uses: actions/upload-artifact@v2
hugo --gc --minify
- uses: actions/upload-artifact@v3
with:
name: site
path: site/public

- name: Publish site to gh-pages
if: github.event_name != 'pull_request'
if: success() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
cd site/public/
touch .nojekyll
git init
cp ../../.git/config ./.git/config
git add .
git config --local user.email "push@gha"
git config --local user.name "GHA"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "update ${{ github.sha }}"
git push -u origin +HEAD:gh-pages
184 changes: 107 additions & 77 deletions .github/workflows/test.yml
Expand Up @@ -8,89 +8,119 @@ env:
GO111MODULE: on

jobs:

golangci-lint:
DetermineVersion:
runs-on: ubuntu-latest
steps:

- uses: actions/setup-go@v2
- name: Checkout code
uses: actions/checkout@v3
- id: go-version-matrix
run: |
go_version="$(awk '/^go/{print $2}' go.mod)"
echo "go_version=${go_version}.x" >> $GITHUB_OUTPUT
matrix_versions="$(git ls-remote --tags https://github.com/golang/go |
awk -F/ '$3 ~ /^go([0-9]+(\.[0-9]+)$)/{gsub(/^go/, "", $3); print $3}' |
sort -V |
sed -ne "/^$go_version$/,$ p" |
jq -cMnR '[inputs | select(length>0)] | map(. + ".x") + ["tip"]')"
echo "matrix=$matrix_versions" >> $GITHUB_OUTPUT
golangci_version="$(yq '.repos[] | select(.repo | contains("golangci-lint")) | .rev' .pre-commit-config.yaml)"
echo "golangci_version=$golangci_version" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.go-version-matrix.outputs.matrix }}
go_version: ${{ steps.go-version-matrix.outputs.go_version }}
golangci_version: ${{ steps.go-version-matrix.outputs.golangci_version }}

Pre-Commit:
needs: DetermineVersion
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v3
- name: Setup go
run: curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.3/install-go.pl | perl - ${{ needs.DetermineVersion.outputs.go_version }} $HOME
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
go-version: '1.17'

- uses: actions/checkout@v2

- uses: golangci/golangci-lint-action@v2
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ needs.DetermineVersion.outputs.go_version }}-${{ hashFiles('**/go.sum') }}
restore-keys: go-mod
- name: Setup mdtoc
run: go install sigs.k8s.io/mdtoc@latest
- uses: pre-commit/action@v3.0.0
env:
SKIP: golangci-lint,go-build,go-unit-tests

GolangCI-Lint:
needs: DetermineVersion
runs-on: ubuntu-latest
steps:
- name: Setup go
run: curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.3/install-go.pl | perl - ${{ needs.DetermineVersion.outputs.go_version }} $HOME
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ needs.DetermineVersion.outputs.go_version }}-${{ hashFiles('**/go.sum') }}
restore-keys: go-mod
- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --verbose
version: ${{ needs.DetermineVersion.outputs.golangci_version }}

test-unix:
Vet:
needs: DetermineVersion
runs-on: ubuntu-latest
steps:
- name: Setup go
run: curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.3/install-go.pl | perl - ${{ needs.DetermineVersion.outputs.go_version }} $HOME
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ needs.DetermineVersion.outputs.go_version }}-${{ hashFiles('**/go.sum') }}
restore-keys: go-mod
- name: Run vet
run: go vet

Test:
needs: DetermineVersion
strategy:
fail-fast: false
matrix:
platform:
- ubuntu
- macOS
go:
- 16
- 17
- 18
- 19
name: '${{ matrix.platform }} | 1.${{ matrix.go }}.x'
runs-on: ${{ matrix.platform }}-latest
go: ${{ fromJson(needs.DetermineVersion.outputs.matrix) }}
os: [ ubuntu-latest, macOS-latest, windows-latest ]
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} Go ${{ matrix.go }} Tests
steps:

- uses: actions/setup-go@v2
with:
go-version: 1.${{ matrix.go }}.x

- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-1.${{ matrix.go }}.x-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-1.${{ matrix.go }}.x-

- run: |
export GOBIN=$HOME/go/bin
case "${{ matrix.go }}" in
16|17) _version='@latest';;
*) _version='';;
esac
go install github.com/kyoh86/richgo"${_version}"
go install github.com/mitchellh/gox"${_version}"
test-win:
name: MINGW64
defaults:
run:
shell: msys2 {0}
runs-on: windows-latest
steps:

- shell: bash
run: git config --global core.autocrlf input

- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >
git
make
unzip
mingw-w64-x86_64-go
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-${{ matrix.go }}-

- run: |
export GOBIN=$HOME/go/bin
go install github.com/kyoh86/richgo@latest
go install github.com/mitchellh/gox@latest
- name: Setup go
shell: bash
run: curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.3/install-go.pl | perl - ${{ matrix.go }} $HOME
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: go-mod
- name: Run tests
shell: bash
run: go test -v -cover -race
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,40 @@
minimum_pre_commit_version: '2.9.3'

repos:
- repo: https://github.com/pre-commit/pre-commit
rev: v2.17.0
hooks:
- id: validate_manifest

- repo: https://github.com/golangci/golangci-lint
rev: v1.47.0
hooks:
- id: golangci-lint

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-merge-conflict
stages: [commit]
- id: check-symlinks
stages: [commit]
- id: check-yaml
stages: [commit]
- id: end-of-file-fixer
stages: [commit]
- id: trailing-whitespace
stages: [commit]

- repo: local
hooks:
- name: Go Tests
id: go-tests
language: system
files: '\.go$'
pass_filenames: false
entry: go test -timeout 30s -short -v ./...
- name: Go Mod Tidy
id: go-mod-tidy
language: system
pass_filenames: false
entry: go mod tidy
6 changes: 1 addition & 5 deletions Makefile
Expand Up @@ -5,10 +5,6 @@ ifeq (, $(shell which golangci-lint))
$(warning "could not find golangci-lint in $(PATH), run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh")
endif

ifeq (, $(shell which richgo))
$(warning "could not find richgo in $(PATH), run: go get github.com/kyoh86/richgo")
endif

.PHONY: fmt lint test install_deps clean

default: all
Expand All @@ -25,7 +21,7 @@ lint:

test: install_deps
$(info ******************** running tests ********************)
richgo test -v ./...
go test -v ./...

install_deps:
$(info ******************** downloading dependencies ********************)
Expand Down
4 changes: 2 additions & 2 deletions bash_completions_test.go
Expand Up @@ -115,7 +115,7 @@ func TestFailGenBashCompletionFile(t *testing.T) {
t.Error("should raise permission denied error")
}

if got.Error() != "open ./tmp/test: permission denied" {
t.Errorf("got: %s, want: %s", got.Error(), "open ./tmp/test: permission denied")
if got.Error() != expectedPermissionError {
t.Errorf("got: %s, want: %s", got.Error(), expectedPermissionError)
}
}
13 changes: 8 additions & 5 deletions command_test.go
Expand Up @@ -928,8 +928,8 @@ Global Flags:
--bar parent bar usage
`

if got != expected {
t.Errorf("Help text mismatch.\nExpected:\n%s\n\nGot:\n%s\n", expected, got)
if rmCarriageRet(got) != expected {
t.Errorf("Help text mismatch.\nExpected:\n%q\n\nGot:\n%q\n", expected, got)
}
}

Expand Down Expand Up @@ -1717,6 +1717,7 @@ func TestUsageWithGroup(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}

output = rmCarriageRet(output)
// help should be ungrouped here
checkStringContains(t, output, "\nAvailable Commands:\n help")
checkStringContains(t, output, "\ngroup1\n cmd1")
Expand All @@ -1734,6 +1735,7 @@ func TestUsageHelpGroup(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}

output = rmCarriageRet(output)
// now help should be grouped under "group"
checkStringOmits(t, output, "\nAvailable Commands:\n help")
checkStringContains(t, output, "\nAvailable Commands:\n\ngroup\n help")
Expand All @@ -1750,6 +1752,7 @@ func TestAddGroup(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}

output = rmCarriageRet(output)
checkStringContains(t, output, "\nTest group\n cmd")
}

Expand Down Expand Up @@ -1865,11 +1868,11 @@ func TestFlagErrorFuncHelp(t *testing.T) {

out, err := executeCommand(c, "--help")
assertNoErr(t, err)
assertEqual(t, expected, out)
assertEqual(t, expected, rmCarriageRet(out))

out, err = executeCommand(c, "-h")
assertNoErr(t, err)
assertEqual(t, expected, out)
assertEqual(t, expected, rmCarriageRet(out))
}

// TestSortedFlags checks,
Expand Down Expand Up @@ -2541,7 +2544,7 @@ Use "root child [command] --help" for more information about a command.
t.FailNow()
}

output := buf.String()
output := rmCarriageRet(buf.String())
if output != test.expectedUsage {
t.Errorf("Expecting: \n %q\nGot:\n %q\n", test.expectedUsage, output)
}
Expand Down
4 changes: 2 additions & 2 deletions fish_completions_test.go
Expand Up @@ -115,7 +115,7 @@ func TestFailGenFishCompletionFile(t *testing.T) {
t.Error("should raise permission denied error")
}

if got.Error() != "open ./tmp/test: permission denied" {
t.Errorf("got: %s, want: %s", got.Error(), "open ./tmp/test: permission denied")
if got.Error() != expectedPermissionError {
t.Errorf("got: %s, want: %s", got.Error(), expectedPermissionError)
}
}

0 comments on commit f58362c

Please sign in to comment.