Add middleware logger on http server #39
This file contains hidden or 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: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-test: | |
name: Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.21 | |
cache: false | |
- name: Get changed Go files | |
id: changed-files | |
run: | | |
changed_files=$(git diff --name-only --diff-filter=ACMR HEAD^ HEAD | grep '\.go$' || true) | |
# Use EOF to handle multi-line output | |
if [ -n "$changed_files" ]; then | |
echo "changed_files<<EOF" >> $GITHUB_OUTPUT | |
echo "$changed_files" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
else | |
echo "changed_files=" >> $GITHUB_OUTPUT | |
fi | |
- name: Cache Go Vendor Directory | |
uses: actions/cache@v3 | |
id: vendor-cache | |
with: | |
path: vendor | |
key: go-vendor-${{ runner.os }}-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
go-vendor-${{ runner.os }}- | |
- name: Install Dependencies (if cache is missing) | |
if: steps.vendor-cache.outputs.cache-hit != 'true' | |
run: | | |
go mod tidy | |
go mod vendor | |
go mod verify | |
- name: Run generate | |
run: go generate ./... | |
- name: Run static analysis on changed files | |
if: ${{ steps.changed-files.outputs.changed_files != '' }} | |
run: | | |
packages=$(echo "${{ steps.changed-files.outputs.changed_files }}" | xargs -n1 dirname | sort -u) | |
echo "Running go vet on packages: $packages" | |
for pkg in $packages; do | |
go vet ./$pkg | |
done | |
- name: Run lint analysis on changed files | |
if: ${{ steps.changed-files.outputs.changed_files != '' }} | |
run: | | |
echo "Running golangci-lint on changed files: ${{ steps.changed-files.outputs.changed_files }}" | |
echo "${{ steps.changed-files.outputs.files }}" | xargs go run github.com/golangci/golangci-lint/cmd/golangci-lint run | |
- name: Run tests | |
run: go test ./... |