From 01e611a9f9806055a0f8661bca00d3eafe05d3a5 Mon Sep 17 00:00:00 2001 From: kongfei605 Date: Thu, 7 Jul 2022 14:17:23 +0800 Subject: [PATCH] auto release with github action (#1032) * auto release with github action * build arm64 artifacts --- .github/workflows/n9e.yml | 44 ++++++++++-------- .goreleaser.yaml | 88 ++++++++++++++++++++++++++++++++++++ docker/Dockerfile.goreleaser | 14 ++++++ fe.sh | 8 ++++ 4 files changed, 135 insertions(+), 19 deletions(-) create mode 100644 .goreleaser.yaml create mode 100644 docker/Dockerfile.goreleaser create mode 100755 fe.sh diff --git a/.github/workflows/n9e.yml b/.github/workflows/n9e.yml index 372af9fe..68ac0b51 100644 --- a/.github/workflows/n9e.yml +++ b/.github/workflows/n9e.yml @@ -1,26 +1,32 @@ -name: Go +name: Release on: push: - branches: [ main ] - pull_request: - branches: [ main ] + tags: + - 'v*' +env: + GO_VERSION: 1.18 jobs: - - build: - name: Build + goreleaser: runs-on: ubuntu-latest steps: - - - name: Set up Go 1.17 - uses: actions/setup-go@v1 - with: - go-version: 1.17 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Build - run: make + - name: Checkout Source Code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Go Environment + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + - uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..ef68116a --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,88 @@ +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + +snapshot: + name_template: '{{ .Tag }}' +checksum: + name_template: 'checksums.txt' +changelog: + skip: true + +builds: + - id: build + hooks: + pre: + - ./fe.sh + main: ./src/ + binary: n9e + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + ldflags: + - -s -w + - -X github.com/didi/nightingale/v5/src/pkg/version.VERSION={{ .Tag }}-{{.Commit}} + +archives: + - id: n9e + builds: + - build + format: tar.gz + format_overrides: + - goos: windows + format: zip + name_template: "n9e-v{{ .Version }}-{{ .Os }}-{{ .Arch }}" + wrap_in_directory: false + files: + - docker/* + - etc/* + - pub/* + +release: + github: + owner: ccfos + name: nightingale + name_template: "v{{ .Version }}" + +dockers: + - image_templates: + - flashcatcloud/nightingale:{{ .Version }}-amd64 + goos: linux + goarch: amd64 + ids: + - build + dockerfile: docker/Dockerfile.goreleaser + extra_files: + - pub + use: buildx + build_flag_templates: + - "--platform=linux/amd64" + - image_templates: + - flashcatcloud/nightingale:{{ .Version }}-arm64v8 + goos: linux + goarch: arm64 + ids: + - build + dockerfile: docker/Dockerfile.goreleaser + extra_files: + - pub + use: buildx + build_flag_templates: + - "--platform=linux/arm64/v8" + +docker_manifests: + + - name_template: flashcatcloud/nightingale:{{ .Version }} + image_templates: + - flashcatcloud/nightingale:{{ .Version }}-amd64 + - flashcatcloud/nightingale:{{ .Version }}-arm64v8 + + - name_template: flashcatcloud/nightingale:latest + image_templates: + - flashcatcloud/nightingale:{{ .Version }}-amd64 + - flashcatcloud/nightingale:{{ .Version }}-arm64v8 diff --git a/docker/Dockerfile.goreleaser b/docker/Dockerfile.goreleaser new file mode 100644 index 00000000..cc8a8222 --- /dev/null +++ b/docker/Dockerfile.goreleaser @@ -0,0 +1,14 @@ +FROM --platform=$BUILDPLATFORM python:2 + + +WORKDIR /app +ADD n9e /app +ADD http://download.flashcat.cloud/wait /wait +RUN mkdir -p /app/pub && chmod +x /wait +ADD pub /app/pub/ +RUN chmod +x n9e + +EXPOSE 19000 +EXPOSE 18000 + +CMD ["/app/n9e", "-h"] diff --git a/fe.sh b/fe.sh new file mode 100755 index 00000000..8a21487f --- /dev/null +++ b/fe.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +TAG=$(curl -sX GET https://api.github.com/repos/n9e/fe-v5/releases/latest | awk '/tag_name/{print $4;exit}' FS='[""]') +VERSION=$(echo $TAG | sed 's/v//g') + +curl -o n9e-fe-${VERSION}.tar.gz -L https://github.com/n9e/fe-v5/releases/download/${TAG}/n9e-fe-${VERSION}.tar.gz + +tar zxvf n9e-fe-${VERSION}.tar.gz