diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml new file mode 100644 index 0000000..8652761 --- /dev/null +++ b/.github/workflows/server.yml @@ -0,0 +1,75 @@ +name: Server CI/CD + +on: + push: + branches: [ "main", "master" ] + tags: + - '*' + pull_request: + branches: [ "main", "master" ] + +jobs: + build: + name: Build server binaries + runs-on: ubuntu-latest + strategy: + matrix: + goos: [ linux, windows ] + goarch: [ amd64 ] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '1.22.x' + cache: true + + - name: Download modules + run: go mod download + + - name: Vet & Test + run: | + go vet ./... + go test ./... -v + + - name: Build cmd/server + shell: bash + run: | + mkdir -p build + EXT="" + if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi + OUT="server-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}" + echo "Building $OUT" + GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \ + go build -trimpath -ldflags="-s -w" -o "build/${OUT}" ./cmd/server + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: server-${{ matrix.goos }}-${{ matrix.goarch }} + path: build/server-${{ matrix.goos }}-${{ matrix.goarch }}* + + release: + name: Release binaries + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + path: dist + + - name: List artifacts + run: ls -R dist + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: dist/**/* + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file