Skip to content

feat: Reporting including different levels #19

feat: Reporting including different levels

feat: Reporting including different levels #19

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
release:
types: [ created ]
env:
GO_VERSION: '1.21'
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
run: make deps
- name: Format check
run: |
make fmt
git diff --exit-code || (echo "Code is not formatted. Run 'make fmt' to fix." && exit 1)
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m
- name: Run tests
run: make test-coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
build:
name: Build
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Linux builds
- goos: linux
goarch: 386
name: linux-386
- goos: linux
goarch: amd64
name: linux-amd64
- goos: linux
goarch: arm64
name: linux-arm64
# Windows builds
- goos: windows
goarch: 386
name: windows-386
ext: .exe
- goos: windows
goarch: amd64
name: windows-amd64
ext: .exe
- goos: windows
goarch: arm64
name: windows-arm64
ext: .exe
# macOS builds
- goos: darwin
goarch: amd64
name: darwin-amd64
- goos: darwin
goarch: arm64
name: darwin-arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for git describe
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
run: make deps
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=$(git describe --tags --always --dirty)
BINARY_NAME=httprunner-${{ matrix.name }}${{ matrix.ext }}
mkdir -p build
go build -ldflags "-X main.version=${VERSION} -s -w" -o build/${BINARY_NAME}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: httprunner-${{ matrix.name }}
path: build/httprunner-${{ matrix.name }}${{ matrix.ext }}
retention-days: 30
release:
name: Release
if: github.event_name == 'release'
needs: [test, build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Install dependencies
run: make deps
- name: Build all platforms
run: make build-all
- name: Create release archives
run: |
cd build
for file in httprunner-*; do
if [[ "$file" == *".exe" ]]; then
# Windows executable - create zip
zip "${file%.exe}.zip" "$file"
else
# Unix executable - create tar.gz
tar -czf "${file}.tar.gz" "$file"
fi
done
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
files: |
build/*.zip
build/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
name: Docker Build
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: github.event_name == 'release'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max