From dde85d6e0fcebe2523db419a60db61279c936fbc Mon Sep 17 00:00:00 2001 From: GCSLaoLi Date: Tue, 9 Apr 2024 08:40:28 -0400 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0flow=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 127 ++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) 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..95998eb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,127 @@ +name: Build +on: + push: + branches: + - 'dev' + tags: + - '*' + pull_request: + +env: + APP_NAME: cockroachai-v2 + DOCKERHUB_REPO: xyhepler/cockroachai-v2 + GHCR_REPO: ghcr.io/cockroachai/cockroachai-v2 + PLATFORMS: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64 + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set Vars + run: | + echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Set up Go + uses: actions/setup-go@v5 + with: + check-latest: true + go-version-file: 'go.mod' + cache: true + + - name: Test + run: go test -v . + + - name: Build + uses: goreleaser/goreleaser-action@v5 + if: "!startsWith(github.ref, 'refs/tags/')" + with: + version: latest + args: build --snapshot --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload Artifact - Linux amd64 + uses: actions/upload-artifact@v4 + if: "!startsWith(github.ref, 'refs/tags/')" + with: + name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-linux-amd64 + path: | + ./dist/default_linux_amd64_v1/${{ env.APP_NAME }} + + - name: Upload Artifact - Linux arm64 + uses: actions/upload-artifact@v4 + if: "!startsWith(github.ref, 'refs/tags/')" + with: + name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-linux-arm64 + path: | + ./dist/default_linux_arm64/${{ env.APP_NAME }} + + - name: Upload Artifact - Darwin arm64 + uses: actions/upload-artifact@v4 + if: "!startsWith(github.ref, 'refs/tags/')" + with: + name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-darwin-arm64 + path: | + ./dist/default_darwin_arm64/${{ env.APP_NAME }} + + - name: Upload Artifact - Windows amd64 + uses: actions/upload-artifact@v4 + if: "!startsWith(github.ref, 'refs/tags/')" + with: + name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-windows-amd64 + path: | + ./dist/default_windows_amd64_v1/${{ env.APP_NAME }}.exe + + - name: Release + uses: goreleaser/goreleaser-action@v5 + if: startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker - Set up Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker - Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker - Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker - Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.DOCKERHUB_REPO }} + ${{ env.GHCR_REPO }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Docker - Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: .Dockerfile + platforms: ${{ env.PLATFORMS }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + \ No newline at end of file