From b705188599162c829e6b91735ec739910bf8c725 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 30 Mar 2023 10:24:03 +0800 Subject: [PATCH] Switch CI to Actions and use Goreleaser (#536) Reviewed-on: https://gitea.com/gitea/tea/pulls/536 Reviewed-by: Lunny Xiao Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- .drone.yml | 212 --------------------------- .gitea/workflows/release-nightly.yml | 37 +++++ .gitea/workflows/release-tag.yml | 39 +++++ .gitea/workflows/test-pr.yml | 31 ++++ .gitignore | 2 + .goreleaser.checksum.sh | 12 ++ .goreleaser.yaml | 122 +++++++++++++++ 7 files changed, 243 insertions(+), 212 deletions(-) delete mode 100644 .drone.yml create mode 100644 .gitea/workflows/release-nightly.yml create mode 100644 .gitea/workflows/release-tag.yml create mode 100644 .gitea/workflows/test-pr.yml create mode 100644 .goreleaser.checksum.sh create mode 100644 .goreleaser.yaml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index ef80154..0000000 --- a/.drone.yml +++ /dev/null @@ -1,212 +0,0 @@ ---- -kind: pipeline -name: default - -platform: - os: linux - arch: amd64 - -steps: - -- name: build - pull: always - image: golang:1.20 - environment: - GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not - commands: - - make clean - - make vet - - make lint - - make fmt-check - - make misspell-check - - make build - when: - event: - - push - - tag - - pull_request - -- name: unit-test - image: golang:1.20 - commands: - - make unit-test-coverage - settings: - group: test - environment: - GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not - when: - branch: - - main - event: - - push - - pull_request - -- name: release-test - image: golang:1.20 - commands: - - make test - settings: - group: test - environment: - GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not - when: - branch: - - "release/*" - event: - - push - - pull_request - -- name: tag-test - pull: always - image: golang:1.20 - commands: - - make test - settings: - group: test - environment: - GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not - when: - event: - - tag - -- name: static - image: golang:1.20 - environment: - GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not - commands: - - make release - when: - event: - - push - - tag - -- name: gpg-sign - pull: always - image: plugins/gpgsign:1 - settings: - detach_sign: true - excludes: - - "dist/release/*.sha256" - files: - - "dist/release/*" - environment: - GPGSIGN_KEY: - from_secret: gpgsign_key - GPGSIGN_PASSPHRASE: - from_secret: gpgsign_passphrase - when: - event: - - push - - tag - -- name: tag-release - pull: always - image: woodpeckerci/plugin-s3:latest - settings: - acl: - from_secret: aws_s3_acl - region: - from_secret: aws_s3_region - bucket: - from_secret: aws_s3_bucket - endpoint: - from_secret: aws_s3_endpoint - path_style: - from_secret: aws_s3_path_style - source: "dist/release/*" - strip_prefix: dist/release/ - target: "/tea/${DRONE_TAG##v}" - environment: - AWS_ACCESS_KEY_ID: - from_secret: aws_access_key_id - AWS_SECRET_ACCESS_KEY: - from_secret: aws_secret_access_key - when: - event: - - tag - -- name: release-branch-release - pull: always - image: woodpeckerci/plugin-s3:latest - settings: - acl: - from_secret: aws_s3_acl - region: - from_secret: aws_s3_region - bucket: - from_secret: aws_s3_bucket - endpoint: - from_secret: aws_s3_endpoint - path_style: - from_secret: aws_s3_path_style - source: "dist/release/*" - strip_prefix: dist/release/ - target: "/tea/${DRONE_BRANCH##release/v}" - environment: - AWS_ACCESS_KEY_ID: - from_secret: aws_access_key_id - AWS_SECRET_ACCESS_KEY: - from_secret: aws_secret_access_key - when: - branch: - - "release/*" - event: - - push - -- name: release - pull: always - image: woodpeckerci/plugin-s3:latest - settings: - acl: - from_secret: aws_s3_acl - region: - from_secret: aws_s3_region - bucket: - from_secret: aws_s3_bucket - endpoint: - from_secret: aws_s3_endpoint - path_style: - from_secret: aws_s3_path_style - source: "dist/release/*" - strip_prefix: dist/release/ - target: /tea/main - environment: - AWS_ACCESS_KEY_ID: - from_secret: aws_access_key_id - AWS_SECRET_ACCESS_KEY: - from_secret: aws_secret_access_key - when: - branch: - - main - event: - - push - -- name: gitea - pull: always - image: plugins/gitea-release:1 - settings: - files: - - "dist/release/*" - base_url: https://gitea.com - api_key: - from_secret: gitea_token - when: - event: - - tag - -- name: discord - pull: always - image: appleboy/drone-discord:1.0.0 - environment: - DISCORD_WEBHOOK_ID: - from_secret: discord_webhook_id - DISCORD_WEBHOOK_TOKEN: - from_secret: discord_webhook_token - when: - event: - - push - - tag - - pull_request - status: - - changed - - failure diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml new file mode 100644 index 0000000..a192f61 --- /dev/null +++ b/.gitea/workflows/release-nightly.yml @@ -0,0 +1,37 @@ +name: goreleaser + +on: + push: + branches: [ main ] + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - name: setup go + uses: https://github.com/actions/setup-go@v4 + with: + go-version: '>=1.20.1' + - name: import gpg + uses: https://github.com/crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.GPGSIGN_KEY }} + passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }} + - name: goreleaser + uses: https://github.com/goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser-pro + version: latest + args: release --nightly + env: + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.AWS_REGION }} + S3_BUCKET: ${{ secrets.AWS_BUCKET }} + GPGSIGN_PASSPHRASE: ${{ secrets.GPGSIGN_PASSPHRASE }} diff --git a/.gitea/workflows/release-tag.yml b/.gitea/workflows/release-tag.yml new file mode 100644 index 0000000..e9920b8 --- /dev/null +++ b/.gitea/workflows/release-tag.yml @@ -0,0 +1,39 @@ +name: goreleaser + +on: [tags] + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - name: setup go + uses: https://github.com/actions/setup-go@v4 + with: + go-version: '>=1.20.1' + - name: import gpg + id: import_gpg + uses: https://github.com/crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.GPGSIGN_KEY }} + passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }} + - name: goreleaser + uses: https://github.com/goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser-pro + version: latest + args: release + env: + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.AWS_REGION }} + S3_BUCKET: ${{ secrets.AWS_BUCKET }} + GPGSIGN_PASSPHRASE: ${{ secrets.GPGSIGN_PASSPHRASE }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} + GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }} + GITHUB_TOKEN: diff --git a/.gitea/workflows/test-pr.yml b/.gitea/workflows/test-pr.yml new file mode 100644 index 0000000..d6a660f --- /dev/null +++ b/.gitea/workflows/test-pr.yml @@ -0,0 +1,31 @@ +name: check-and-test + +on: + - push + - pull_request + +jobs: + check-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: setup go + uses: https://github.com/actions/setup-go@v4 + with: + go-version: '>=1.20.1' + - name: lint and build + run: | + make clean + make vet + make lint + make fmt-check + make misspell-check + make build + env: + GOPROXY: https://goproxy.io,direct + - name: test and coverage + run: | + make test + make unit-test-coverage + env: + GOPROXY: https://goproxy.io,direct diff --git a/.gitignore b/.gitignore index 464f9d0..10fad8b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ dist/ vendor/ coverage.out + +dist/ diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh new file mode 100644 index 0000000..a11b71d --- /dev/null +++ b/.goreleaser.checksum.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +if [ -z "$1" ]; then + echo "usage: $0 " + exit 1 +fi + +SUM=$(shasum -a 256 "$1" | cut -d' ' -f1) +BASENAME=$(basename "$1") +echo -n "${SUM} ${BASENAME}" > "$1".sha256 \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..0e99b6c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,122 @@ +before: + hooks: + - go mod tidy + +builds: +- env: + - CGO_ENABLED=0 + goos: + - darwin + - linux + - windows + - freebsd + goarch: + - amd64 + - arm + - arm64 + goarm: + - "5" + - "6" + - "7" + ignore: + - goos: darwin + goarch: arm + - goos: darwin + goarch: ppc64le + - goos: darwin + goarch: s390x + - goos: windows + goarch: ppc64le + - goos: windows + goarch: s390x + - goos: windows + goarch: arm + goarm: "5" + - goos: windows + goarch: arm + goarm: "6" + - goos: windows + goarch: arm + goarm: "7" + - goos: windows + goarch: arm64 + - goos: freebsd + goarch: ppc64le + - goos: freebsd + goarch: s390x + - goos: freebsd + goarch: arm + goarm: "5" + - goos: freebsd + goarch: arm + goarm: "6" + - goos: freebsd + goarch: arm + goarm: "7" + - goos: freebsd + goarch: arm64 + flags: + - -trimpath + ldflags: + - -s -w -X main.Version={{ .Version }} + binary: >- + {{ .ProjectName }}- + {{- .Version }}- + {{- .Os }}- + {{- if eq .Arch "amd64" }}amd64 + {{- else if eq .Arch "amd64_v1" }}amd64 + {{- else if eq .Arch "386" }}386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}-{{ .Arm }}{{ end }} + no_unique_dist_dir: true + hooks: + post: + - cmd: tar -cJf {{ .Path }}.xz {{ .Path }} + env: + - XZ_OPT=-9 + - cmd: sh .goreleaser.checksum.sh {{ .Path }} + - cmd: sh .goreleaser.checksum.sh {{ .Path }}.xz + +blobs: + - + provider: s3 + bucket: "{{ .Env.S3_BUCKET }}" + region: "{{ .Env.S3_REGION }}" + folder: "tea/{{.Version}}" + extra_files: + - glob: ./**.xz + - glob: ./**.sha256 + +archives: + - format: binary + name_template: "{{ .Binary }}" + allow_different_binary_count: true + +checksum: + name_template: 'checksums.txt' + extra_files: + - glob: ./**.xz + +env_files: + # override gitea actions which passes GITHUB_TOKEN to set env var as null + github_token: /dev/null + +signs: + - + signature: "${artifact}.sig" + artifacts: checksum + stdin: '{{ .Env.GPGSIGN_PASSPHRASE }}' + args: ["--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}"] + +snapshot: + name_template: "{{ .Branch }}-devel" + +nightly: + name_template: "{{ .Branch }}" + +gitea_urls: + api: https://gitea.com/api/v1 + download: https://gitea.com + +# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj \ No newline at end of file