From be6d3e5a44e4fa36d20885058563408f0d7e1779 Mon Sep 17 00:00:00 2001 From: Emmm Monster <58943012+emmmx@users.noreply.github.com> Date: Fri, 12 Nov 2021 05:17:06 +0800 Subject: [PATCH] improve ci --- .github/workflows/build.yml | 26 ++++++++---- .github/workflows/release.yml | 79 +++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6e9c89a..044380d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,17 +17,23 @@ on: jobs: test: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: matrix: - os: [ windows-latest, ubuntu-latest, macos-latest ] include: - - os: ubuntu-latest + - target: "linux/amd64" + GOOS: "linux" + GOARCH: "amd64" BIN_SUFFIX: "" - - os: macos-latest - BIN_SUFFIX: "" - - os: windows-latest + - target: "windows/amd64" + GOOS: "windows" + GOARCH: "amd64" BIN_SUFFIX: ".exe" + - target: "darwin/amd64" + GOOS: "darwin" + GOARCH: "amd64" + BIN_SUFFIX: "" + steps: - name: Checkout codebase uses: actions/checkout@v2 @@ -47,11 +53,13 @@ jobs: - name: Build env: + GOOS: ${{ matrix.GOOS }} + GOARCH: ${{ matrix.GOARCH }} CGO_ENABLED: 0 - run: go build -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -v -o um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} ./cmd/um + run: go build -v -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -o um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }} ./cmd/um - name: Publish artifact uses: actions/upload-artifact@v2 with: - name: um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} - path: ./um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} + name: um-${{ matrix.GOOS }}-${{ matrix.GOARCH }} + path: ./um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4a069d2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,79 @@ +name: Create Release + +on: + push: + tags: + - "v*" + +jobs: + create-release: + runs-on: ubuntu-latest + steps: + - name: Get current time + id: date + run: echo "::set-output name=date::$(date +'%Y/%m/%d')" + + - name: Create release + id: release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: "Build ${{ steps.date.outputs.date }}" + draft: true + + build: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - target: "linux/amd64" + GOOS: "linux" + GOARCH: "amd64" + BIN_SUFFIX: "" + - target: "windows/amd64" + GOOS: "windows" + GOARCH: "amd64" + BIN_SUFFIX: ".exe" + - target: "windows/386" + GOOS: "windows" + GOARCH: "386" + BIN_SUFFIX: ".exe" + - target: "darwin/amd64" + GOOS: "darwin" + GOARCH: "amd64" + BIN_SUFFIX: "" + + steps: + - name: Checkout codebase + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup vars + id: vars + run: | + echo "::set-output name=short_sha::$(git rev-parse --short HEAD)" + echo "::set-output name=git_tag::$(git describe --tags --always)" + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.17 + + - name: Build + env: + GOOS: ${{ matrix.GOOS }} + GOARCH: ${{ matrix.GOARCH }} + CGO_ENABLED: 0 + run: go build -trimpath -v -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -o um ./cmd/um + + - name: Upload release assets + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ jobs.create-release.steps.release.outputs.upload_url }} + asset_path: um + asset_name: um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }}