From 195bafb0acdde36967b922030604e35c0d1b829c Mon Sep 17 00:00:00 2001 From: Muhammed Efe Cetin Date: Mon, 17 Mar 2025 12:48:36 +0300 Subject: [PATCH] actions: add ci actions for testing and building --- .github/workflows/build.yml | 37 +++++++++++++++++++++++++++++++ .github/workflows/test.yml | 43 ++++++++++++++++++++++++++----------- 2 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9a82390 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Go Build + +on: + push: + branches: [ main ] + pull_request: + + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + go-version: [1.24] + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.go-version }}- + + - name: Build project + run: go build -v cmd/main.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8f36d7..d454df5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,20 +1,37 @@ -name: Hello World +name: Go Tests on: push: - branches: - - main + branches: [ main ] pull_request: - branches: - - main - workflow_dispatch: + jobs: - hello: - runs-on: ubuntu-latest + test: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + go-version: [1.24] + runs-on: ${{ matrix.os }} + steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Print Hello World - run: echo "Hello, World!" + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.go-version }}- + + - name: Run tests recursively + run: go test ./...