diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ea4ab05 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + + - name: Cache Dependencies + uses: actions/cache@v3 + id: gomod-cache + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('go.mod') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Install Dependencies + run: go mod tidy + + - name: Lint + run: | + go install golang.org/x/lint/golint@latest + golint ./... + + - name: Format Check + run: | + unformatted=$(go fmt ./...) + if [ -n "$unformatted" ]; then + echo "The following files are not formatted:" + echo "$unformatted" + exit 1 + else + echo "Code is formatted." + fi + + - name: Vet + run: go vet ./... + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 47d4561..3f8045f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,20 +5,12 @@ on: workflows: ["CI"] types: - completed - push: branches: - stable - tags: - - v* - -permissions: - contents: write jobs: release: - if: | - (github.event.workflow_run.conclusion == 'success' && github.event_name == 'workflow_run') || - (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) + if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest permissions: contents: write @@ -35,19 +27,10 @@ jobs: with: go-version: '1.23' - - name: Check formatting (go fmt) - run: | - out=$(go fmt ./...) - if [ -n "$out" ]; then - echo "The following files are not gofmt'ed:" >&2 - echo "$out" >&2 - exit 1 - fi - - name: Build for Multiple Platforms run: | mkdir -p releases - PLATFORMS=("windows/amd64" "linux/amd64" "darwin/amd64" "darwin/arm64") + PLATFORMS=("windows/amd64" "linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64") for platform in "${PLATFORMS[@]}"; do OS=${platform%/*} ARCH=${platform#*/} @@ -74,4 +57,4 @@ jobs: files: | releases/* env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}