|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + tags: [ 'v*' ] |
| 7 | +env: |
| 8 | + GO_VERSION: '1.24.3' |
| 9 | + GOLANGCI_LINT_VERSION: 'v2.2.2' |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Set up Go |
| 19 | + uses: actions/setup-go@v5 |
| 20 | + with: |
| 21 | + go-version: ${{ env.GO_VERSION }} |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + run: | |
| 25 | + go mod tidy |
| 26 | + go get github.com/stretchr/testify |
| 27 | +
|
| 28 | + - name: Install golangci-lint |
| 29 | + run: | |
| 30 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${{ env.GOLANGCI_LINT_VERSION }} |
| 31 | +
|
| 32 | + - name: Lint |
| 33 | + run: make lint |
| 34 | + |
| 35 | + - name: Code format |
| 36 | + run: | |
| 37 | + if [ -f style.sh ]; then bash style.sh; fi |
| 38 | +
|
| 39 | + - name: Build (local) |
| 40 | + run: make build-local |
| 41 | + |
| 42 | + - name: Test |
| 43 | + run: make test |
| 44 | + |
| 45 | + - name: Build binaries |
| 46 | + if: startsWith(github.ref, 'refs/tags/v') |
| 47 | + run: make build-binaries |
| 48 | + |
| 49 | + - name: Package binaries |
| 50 | + if: startsWith(github.ref, 'refs/tags/v') |
| 51 | + run: make package-binaries |
| 52 | + |
| 53 | + - name: Upload Binaries |
| 54 | + if: startsWith(github.ref, 'refs/tags/v') |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: binaries |
| 58 | + path: | |
| 59 | + dist/*.tar.gz |
| 60 | + dist/*.zip |
| 61 | +
|
| 62 | + release: |
| 63 | + name: Create GitHub Release |
| 64 | + if: startsWith(github.ref, 'refs/tags/v') |
| 65 | + needs: build-test |
| 66 | + runs-on: ubuntu-latest |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: Download Binaries |
| 70 | + uses: actions/download-artifact@v4 |
| 71 | + with: |
| 72 | + name: binaries |
| 73 | + |
| 74 | + - name: List Downloaded Files |
| 75 | + run: ls -l |
| 76 | + |
| 77 | + - name: Create Release |
| 78 | + uses: ncipollo/release-action@v1 |
| 79 | + with: |
| 80 | + artifacts: "*.tar.gz,*.zip" |
| 81 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + tag: ${{ github.ref_name }} |
| 83 | + name: Release ${{ github.ref_name }} |
| 84 | + prerelease: false |
0 commit comments