From 049623b1331460d6fc18ec15fb95758afd35a755 Mon Sep 17 00:00:00 2001 From: heronimus Date: Thu, 19 Oct 2023 21:24:51 +0700 Subject: [PATCH] chore(ci): add init multiplatform build --- .github/workflows/build.yml | 27 +++++++++++++++++++-------- .github/workflows/release.yml | 6 +++--- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7703bdc..b97c32a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,12 @@ on: branches: - main workflow_call: + inputs: + create_release: + description: 'Check if workflows called from Github Release event.' + default: false + required: false + type: boolean jobs: go-build: @@ -16,6 +22,8 @@ jobs: strategy: matrix: go-version: [1.21.x] + goos: [linux, windows, darwin] + goarch: [amd64] steps: - name: Checkout uses: actions/checkout@v3 @@ -26,14 +34,17 @@ jobs: with: go-version: ${{ matrix.go-version }} cache-dependency-path: "go.sum" - - name: Build + - name: Build ${{ matrix.goos }}/${{ matrix.goarch }} run: | - go build - - name: Run build binary - run: | - ./world-cli version - - name: Upload binary Github artifact + output_name=world-cli_${{ matrix.goos }}_${{ matrix.goarch }} + if [ $GOOS = "windows" ]; then + output_name+='.exe' + fi + + env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o $output_name + - name: Upload binary to Github artifact + if: ${{ inputs.create_release }} uses: actions/upload-artifact@v3 with: - name: world-cli - path: ./world-cli + name: world-cli-${{ matrix.goos }}-${{ matrix.goarch }} + path: ./world-cli* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fd3cbb5..c8bfebf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,6 +12,8 @@ jobs: go-build: name: Build uses: ./.github/workflows/build.yml + with: + create_release: true release: name: Release world-cli binary @@ -23,11 +25,9 @@ jobs: steps: - name: Download world-cli build binary uses: actions/download-artifact@v3 - with: - name: world-cli - name: Publish world-cli binary to corresponding Github Release uses: skx/github-action-publish-binaries@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - args: 'world-cli' + args: 'world-cli*'