test: add scripts test #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Main CI | |
on: | |
pull_request: | |
branches: | |
- main | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
all-status-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
needs: | |
- ci-req-check | |
- yaml-lint | |
- action-lint | |
- golang-build-check | |
- golang-fmt-check | |
- golang-lint-check | |
- golang-coverage-check | |
- golang-test-check | |
- golang-generate-check | |
steps: | |
- name: All status check | |
run: echo "All status check passed" | |
ci-req-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check all-status-check | |
run: | | |
diff \ | |
<(yq ".jobs | del(.all-status-check) | keys.[]" .github/workflows/ci.yml) \ | |
<(yq ".jobs.all-status-check.needs.[]" .github/workflows/ci.yml) | |
yaml-lint: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: reviewdog/action-yamllint@v1.20.0 | |
with: | |
level: warning | |
fail_level: warning | |
yamllint_flags: "-c .yamllint ." | |
action-lint: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: reviewdog/action-actionlint@v1.60.0 | |
with: | |
level: warning | |
fail_level: warning | |
golang-build-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
cache-dependency-path: go.sum | |
- name: Run go build | |
run: make build | |
golang-fmt-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
cache-dependency-path: go.sum | |
- name: Run go fmt | |
run: go fmt ./... | |
- name: Check diff | |
run: | | |
if [[ $(git status --porcelain) ]]; then | |
git diff | |
exit 1 | |
fi | |
golang-lint-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
cache-dependency-path: go.sum | |
- uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 | |
golang-coverage-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
cache-dependency-path: go.sum | |
- name: Run go test | |
id: golang-test | |
run: | | |
go test -race -coverprofile=coverage.txt -covermode=atomic -p=5 ./... | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@7f8b4b4bde536c465e797be725718b88c5d95e0e # v5.1.1 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
golang-test-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
cache-dependency-path: go.sum | |
- name: Set up gotestfmt | |
uses: gotesttools/gotestfmt-action@8b4478c7019be847373babde9300210e7de34bfb # v2.5.0 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run go test | |
id: golang-test | |
run: | | |
set +e | |
TEST_OUT=$(go test -json -v ./... -p=5 2>&1) | |
TEST_EXIT=$? | |
echo "$TEST_OUT" | tee /tmp/gotest.log | gotestfmt | |
exit $TEST_EXIT | |
continue-on-error: true | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: test-log | |
path: /tmp/gotest.log | |
if-no-files-found: error | |
- name: Error check | |
if: ${{ steps.golang-test.outcome != 'success' }} | |
run: exit 1 | |
golang-generate-check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
cache-dependency-path: go.sum | |
- name: Run go generate | |
run: go generate ./... | |
- name: Check diff | |
run: | | |
if [[ $(git status --porcelain) ]]; then | |
git diff | |
exit 1 | |
fi |