From 167741df8e3421681203dc4667053efb9d4a11fe Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 16 Mar 2023 16:34:21 -0400 Subject: [PATCH 01/25] build and release nightly --- .gitea/workflows/release-nightly.yml | 30 +++++++++ .gitignore | 4 ++ .goreleaser.yaml | 93 ++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 .gitea/workflows/release-nightly.yml create mode 100644 .goreleaser.yaml diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml new file mode 100644 index 0000000..9304808 --- /dev/null +++ b/.gitea/workflows/release-nightly.yml @@ -0,0 +1,30 @@ +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 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.20.1' + - 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 }} diff --git a/.gitignore b/.gitignore index dfbe66a..8c854ab 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ # Go /vendor/ + +dist/ + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..94c4f7c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,93 @@ +before: + hooks: + - go mod tidy + +builds: +- env: + - CGO_ENABLED=0 + goos: + - darwin + - linux + - windows + - freebsd + goarch: + - amd64 + - arm + - arm64 +# - s390x +# - ppc64le + 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: 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" + flags: + - -trimpath + ldflags: + - -s -w -X code.gitea.io/changelog/cmd.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 + +blobs: + - + provider: s3 + bucket: "{{ .Env.S3_BUCKET }}" + region: "{{ .Env.S3_REGION }}" + folder: "changelog-tool/{{.Version}}" + +archives: + - format: binary + name_template: "{{ .Binary }}" + allow_different_binary_count: true + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ .Branch }}-devel" + +nightly: + name_template: "{{ .Branch }}" + +# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj -- 2.43.5 From f18b0110320a880a9dfa1d6a66c01172b43ef859 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 17 Mar 2023 04:36:25 +0800 Subject: [PATCH 02/25] build and release nightly (#71) Reviewed-on: https://gitea.com/gitea/changelog/pulls/71 Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- .gitea/workflows/release-nightly.yml | 30 +++++++++ .gitignore | 4 ++ .goreleaser.yaml | 93 ++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 .gitea/workflows/release-nightly.yml create mode 100644 .goreleaser.yaml diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml new file mode 100644 index 0000000..9304808 --- /dev/null +++ b/.gitea/workflows/release-nightly.yml @@ -0,0 +1,30 @@ +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 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.20.1' + - 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 }} diff --git a/.gitignore b/.gitignore index dfbe66a..8c854ab 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ # Go /vendor/ + +dist/ + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..94c4f7c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,93 @@ +before: + hooks: + - go mod tidy + +builds: +- env: + - CGO_ENABLED=0 + goos: + - darwin + - linux + - windows + - freebsd + goarch: + - amd64 + - arm + - arm64 +# - s390x +# - ppc64le + 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: 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" + flags: + - -trimpath + ldflags: + - -s -w -X code.gitea.io/changelog/cmd.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 + +blobs: + - + provider: s3 + bucket: "{{ .Env.S3_BUCKET }}" + region: "{{ .Env.S3_REGION }}" + folder: "changelog-tool/{{.Version}}" + +archives: + - format: binary + name_template: "{{ .Binary }}" + allow_different_binary_count: true + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ .Branch }}-devel" + +nightly: + name_template: "{{ .Branch }}" + +# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj -- 2.43.5 From a63229683128ee029bf115d9059f63088406941a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 17 Mar 2023 04:50:35 +0800 Subject: [PATCH 03/25] actions: test pull requests (#72) Reviewed-on: https://gitea.com/gitea/changelog/pulls/72 Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- .drone.yml | 141 ----------------------------------- .gitea/workflows/test-pr.yml | 19 +++++ .gitignore | 2 - 3 files changed, 19 insertions(+), 143 deletions(-) delete mode 100644 .drone.yml create mode 100644 .gitea/workflows/test-pr.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 481fcfd..0000000 --- a/.drone.yml +++ /dev/null @@ -1,141 +0,0 @@ ---- -kind: pipeline -name: compliance - -platform: - os: linux - arch: arm64 - -trigger: - event: - - pull_request - -steps: -- name: build - pull: always - image: golang:1.20 - environment: - GOPROXY: https://goproxy.io,direct - commands: - - go test -race ./... - - go build - -- name: check - pull: always - image: golang:1.20 - environment: - GOPROXY: https://goproxy.io,direct - commands: - - make lint - -- name: discord - pull: always - image: appleboy/drone-discord:1 - environment: - DISCORD_WEBHOOK_ID: - from_secret: discord_webhook_id - DISCORD_WEBHOOK_TOKEN: - from_secret: discord_webhook_token - when: - event: - - push - - tag - status: - - changed - - failure - ---- -kind: pipeline -name: release - -platform: - os: linux - arch: amd64 - -trigger: - branch: - - main - event: - - push - - tag - -steps: - - name: fetch-tags - pull: always - image: docker:git - commands: - - git fetch --tags --force - - - name: release - pull: always - image: techknowlogick/xgo:latest - environment: - GOPROXY: https://goproxy.io,direct - commands: - - export PATH=$PATH:$GOPATH/bin - - make release - - - name: bucket-main - 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: /changelog-tool/main - environment: - AWS_ACCESS_KEY_ID: - from_secret: aws_access_key_id - AWS_SECRET_ACCESS_KEY: - from_secret: aws_secret_access_key - when: - event: - - push - - - name: bucket-tag - 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: "/changelog-tool/${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: gitea - pull: always - image: plugins/gitea-release:1 - settings: - api_key: - from_secret: gitea_token - base_url: https://gitea.com - files: - - "dist/release/*" - when: - event: - - tag \ No newline at end of file diff --git a/.gitea/workflows/test-pr.yml b/.gitea/workflows/test-pr.yml new file mode 100644 index 0000000..cda25df --- /dev/null +++ b/.gitea/workflows/test-pr.yml @@ -0,0 +1,19 @@ +name: check-and-test + +on: [pull_request] + +jobs: + check-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.20.1' + - name: check-and-test + run: | + go test -race ./... + go build + make lint + env: + GOPROXY: https://goproxy.io,direct diff --git a/.gitignore b/.gitignore index 8c854ab..6bea5b4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,3 @@ /vendor/ dist/ - -dist/ -- 2.43.5 From 583ac7def28e30cda6f730f0e7af1085d3857e9e Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 00:45:40 -0400 Subject: [PATCH 04/25] xz binaries --- .goreleaser.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 94c4f7c..a5cb989 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,6 +2,31 @@ before: hooks: - go mod tidy +after: + hooks: + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 + dir: dist + builds: - env: - CGO_ENABLED=0 -- 2.43.5 From f2b3d8d60f588e04620135f4318910d2e4438954 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 00:53:02 -0400 Subject: [PATCH 05/25] run post build --- .goreleaser.yaml | 51 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a5cb989..292f84a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,31 +2,6 @@ before: hooks: - go mod tidy -after: - hooks: - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 - dir: dist - builds: - env: - CGO_ENABLED=0 @@ -39,8 +14,6 @@ builds: - amd64 - arm - arm64 -# - s390x -# - ppc64le goarm: - "5" - "6" @@ -92,6 +65,30 @@ builds: {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}-{{ .Arm }}{{ end }} no_unique_dist_dir: true + hooks: + post: + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 + dir: dist blobs: - -- 2.43.5 From d55f6646fbc6c2067e792919eb6e8941dd218347 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 00:59:17 -0400 Subject: [PATCH 06/25] simplify hooks --- .goreleaser.yaml | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 292f84a..d6bdc14 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -67,28 +67,7 @@ builds: no_unique_dist_dir: true hooks: post: - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 - dir: dist + - cmd: tar -cJf {{ .Path }}.xz {{ .Path }} blobs: - -- 2.43.5 From 88538267db88a55d49ba28578a1f35ff1e290522 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:09:05 -0400 Subject: [PATCH 07/25] individual checksums --- .goreleaser.checksum.sh | 10 ++++++++++ .goreleaser.yaml | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 .goreleaser.checksum.sh diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh new file mode 100644 index 0000000..042f0a2 --- /dev/null +++ b/.goreleaser.checksum.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +if [ -z "$1" ]; then + echo "usage: $0 " + exit 1 +fi + +shasum -a 256 "$1" | cut -d' ' -f1 > "$1".sha256 \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d6bdc14..8519b15 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -68,6 +68,10 @@ builds: hooks: post: - cmd: tar -cJf {{ .Path }}.xz {{ .Path }} + env: + - XZ_OPT=-9 + - cmd: .goreleaser.checksum.sh {{ .Path }} + - cmd: .goreleaser.checksum.sh {{ .Path }}.xz blobs: - -- 2.43.5 From b3eaafbefe006b61f556c917930f7fb6cb2c1f2b Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:16:18 -0400 Subject: [PATCH 08/25] add executable bit --- .goreleaser.checksum.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .goreleaser.checksum.sh diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh old mode 100644 new mode 100755 -- 2.43.5 From bda1f380e209c70898d6f992a5d996468868b332 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:20:34 -0400 Subject: [PATCH 09/25] execute with shell --- .goreleaser.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 8519b15..ffb6786 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -70,8 +70,8 @@ builds: - cmd: tar -cJf {{ .Path }}.xz {{ .Path }} env: - XZ_OPT=-9 - - cmd: .goreleaser.checksum.sh {{ .Path }} - - cmd: .goreleaser.checksum.sh {{ .Path }}.xz + - cmd: sh .goreleaser.checksum.sh {{ .Path }} + - cmd: sh .goreleaser.checksum.sh {{ .Path }}.xz blobs: - -- 2.43.5 From 0650d7c623e8330254cb67ca3a686b9027eaa00a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:27:14 -0400 Subject: [PATCH 10/25] generate full checksum --- .goreleaser.checksum.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh index 042f0a2..ed205df 100755 --- a/.goreleaser.checksum.sh +++ b/.goreleaser.checksum.sh @@ -7,4 +7,6 @@ if [ -z "$1" ]; then exit 1 fi -shasum -a 256 "$1" | cut -d' ' -f1 > "$1".sha256 \ No newline at end of file +SUM=$(shasum -a 256 "$1" | cut -d' ' -f1) +BASENAME=$(basename "$1") +echo -n "${SUM} ${BASENAME}" > "$1".sha256 \ No newline at end of file -- 2.43.5 From 66f3e382a16cf3f429bd246fb807e4b628a06633 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:32:19 -0400 Subject: [PATCH 11/25] upload custom files --- .goreleaser.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ffb6786..141f5cf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -79,6 +79,9 @@ blobs: bucket: "{{ .Env.S3_BUCKET }}" region: "{{ .Env.S3_REGION }}" folder: "changelog-tool/{{.Version}}" + extra_files: + - glob: ./**.xz + - glob: ./**.sha256 archives: - format: binary -- 2.43.5 From d17e881692c6cf083061321d2435618d461ab033 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:49:03 -0400 Subject: [PATCH 12/25] properly format checksum file --- .goreleaser.checksum.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh index ed205df..a11b71d 100755 --- a/.goreleaser.checksum.sh +++ b/.goreleaser.checksum.sh @@ -9,4 +9,4 @@ fi SUM=$(shasum -a 256 "$1" | cut -d' ' -f1) BASENAME=$(basename "$1") -echo -n "${SUM} ${BASENAME}" > "$1".sha256 \ No newline at end of file +echo -n "${SUM} ${BASENAME}" > "$1".sha256 \ No newline at end of file -- 2.43.5 From 374ea1ab46c9f01afebbdcc7f0f151a2d126ea7a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:58:55 -0400 Subject: [PATCH 13/25] checksum compressed files too --- .goreleaser.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 141f5cf..86c179e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -90,6 +90,8 @@ archives: checksum: name_template: 'checksums.txt' + extra_files: + - glob: ./**.xz snapshot: name_template: "{{ .Branch }}-devel" -- 2.43.5 From cbd80881bcb7e5e7674f748edb7f629e3203783f Mon Sep 17 00:00:00 2001 From: jolheiser Date: Tue, 21 Mar 2023 09:54:34 +0800 Subject: [PATCH 14/25] Trim space on title (#75) Resolves #74 Reviewed-on: https://gitea.com/gitea/changelog/pulls/75 Reviewed-by: Lunny Xiao Reviewed-by: silverwind Co-authored-by: jolheiser Co-committed-by: jolheiser --- service/gitea.go | 3 ++- service/github.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/service/gitea.go b/service/gitea.go index 874f858..a932f1a 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -6,6 +6,7 @@ package service import ( "fmt" + "strings" "time" "code.gitea.io/sdk/gitea" @@ -92,7 +93,7 @@ func getGiteaTagURL(c *gitea.Client, baseURL, owner, repo, mileName, gitTag, fro func convertToEntry(issue gitea.Issue) Entry { entry := Entry{ Index: issue.Index, - Title: issue.Title, + Title: strings.TrimSpace(issue.Title), } labels := make([]Label, len(issue.Labels)) diff --git a/service/github.go b/service/github.go index 5a0193d..93119ea 100644 --- a/service/github.go +++ b/service/github.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "os" + "strings" "time" "github.com/google/go-github/v50/github" @@ -58,7 +59,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { for _, pr := range result.Issues { if pr.IsPullRequest() == isPull { p := Entry{ - Title: pr.GetTitle(), + Title: strings.TrimSpace(pr.GetTitle()), Index: int64(pr.GetNumber()), } -- 2.43.5 From 70c955ae17967a7dfddb770cb8e7748fe0f4d8a6 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Wed, 22 Mar 2023 04:35:58 +0800 Subject: [PATCH 15/25] Title-case PR title (#76) Resolves #60 Extracts the previous trim into a new func as well to keep any title munging consistent. Reviewed-on: https://gitea.com/gitea/changelog/pulls/76 Reviewed-by: Lunny Xiao Reviewed-by: techknowlogick Co-authored-by: jolheiser Co-committed-by: jolheiser --- service/gitea.go | 3 +-- service/github.go | 3 +-- service/service.go | 13 +++++++++++++ service/service_test.go | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/service/gitea.go b/service/gitea.go index a932f1a..2c85808 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -6,7 +6,6 @@ package service import ( "fmt" - "strings" "time" "code.gitea.io/sdk/gitea" @@ -93,7 +92,7 @@ func getGiteaTagURL(c *gitea.Client, baseURL, owner, repo, mileName, gitTag, fro func convertToEntry(issue gitea.Issue) Entry { entry := Entry{ Index: issue.Index, - Title: strings.TrimSpace(issue.Title), + Title: CleanTitle(issue.Title), } labels := make([]Label, len(issue.Labels)) diff --git a/service/github.go b/service/github.go index 93119ea..00894b6 100644 --- a/service/github.go +++ b/service/github.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "os" - "strings" "time" "github.com/google/go-github/v50/github" @@ -59,7 +58,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { for _, pr := range result.Issues { if pr.IsPullRequest() == isPull { p := Entry{ - Title: strings.TrimSpace(pr.GetTitle()), + Title: CleanTitle(pr.GetTitle()), Index: int64(pr.GetNumber()), } diff --git a/service/service.go b/service/service.go index de7e76a..685d5b9 100644 --- a/service/service.go +++ b/service/service.go @@ -7,6 +7,7 @@ package service import ( "fmt" "strings" + "unicode" ) const defaultGitea = "https://gitea.com" @@ -86,3 +87,15 @@ func (cl ContributorList) Less(i, j int) bool { func (cl ContributorList) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] } + +// CleanTitle returns the string with spaces trimmed and the first rune title-cased +func CleanTitle(s string) string { + + s = strings.TrimSpace(s) + + r := []rune(s) + r[0] = unicode.ToUpper(r[0]) + s = string(r) + + return s +} diff --git a/service/service_test.go b/service/service_test.go index 045e70f..47c57cb 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -12,3 +12,27 @@ import ( func TestMain(m *testing.M) { os.Exit(m.Run()) } + +func TestCleanTitle(t *testing.T) { + tt := []struct { + Title string + Expected string + }{ + {Title: "foo", Expected: "Foo"}, + {Title: " foo", Expected: "Foo"}, + {Title: "foo bar", Expected: "Foo bar"}, + {Title: "Foo bar", Expected: "Foo bar"}, + {Title: " Foo bar ", Expected: "Foo bar"}, + {Title: "1234", Expected: "1234"}, + } + + for _, tc := range tt { + t.Run(tc.Title, func(t *testing.T) { + s := CleanTitle(tc.Title) + if s != tc.Expected { + t.Logf("got %q | expected %q", s, tc.Expected) + t.Fail() + } + }) + } +} -- 2.43.5 From 8156d742f5932199634bd7b6405b68387abec6a2 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 3 Apr 2023 11:51:25 +0800 Subject: [PATCH 16/25] Update to urfave/cli/v3 (#77) This allows for persistent flags, such that `changelog -m v0.4.0 generate` and `changelog generate -m v0.4.0` are equivalent. Reviewed-on: https://gitea.com/gitea/changelog/pulls/77 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao Co-authored-by: jolheiser Co-committed-by: jolheiser --- cmd/cmd.go | 37 ++++++++++--------------------------- cmd/contributors.go | 2 +- cmd/generate.go | 2 +- cmd/init.go | 2 +- go.mod | 8 ++++---- go.sum | 18 ++++++++---------- 6 files changed, 25 insertions(+), 44 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 77e869b..3ddaf64 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -8,7 +8,7 @@ import ( "os" "path/filepath" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var ( @@ -24,6 +24,8 @@ var ( ) // New returns a new changelog App +// +//nolint:funlen func New() *cli.App { app := &cli.App{ Name: "changelog", @@ -35,12 +37,14 @@ func New() *cli.App { Aliases: []string{"m"}, Usage: "Targeted milestone", Destination: &milestoneFlag, + Persistent: true, }, &cli.StringFlag{ Name: "tag", Aliases: []string{"T"}, Usage: "Git tag for milestone url, if not set milestone is used", Destination: &tagFlag, + Persistent: true, }, &cli.StringFlag{ Name: "config", @@ -48,30 +52,35 @@ func New() *cli.App { Usage: "Specify a config file", Value: getDefaultConfigFile(), Destination: &configPathFlag, + Persistent: true, }, &cli.StringFlag{ Name: "token", Aliases: []string{"t"}, Usage: "Access token for private repositories/instances", Destination: &tokenFlag, + Persistent: true, }, &cli.BoolFlag{ Name: "details", Aliases: []string{"d"}, Usage: "Generate detail lists instead of long lists", Destination: &detailsFlag, + Persistent: true, }, &cli.Int64Flag{ Name: "after", Aliases: []string{"a"}, Usage: "Only select PRs after a given index (continuing a previous changelog)", Destination: &afterFlag, + Persistent: true, }, &cli.BoolFlag{ Name: "issues", Aliases: []string{"i"}, Usage: "Generate changelog from issues (otherwise from pulls)", Destination: &issuesFlag, + Persistent: true, }, }, Commands: []*cli.Command{ @@ -80,7 +89,6 @@ func New() *cli.App { Init, }, } - copyGlobalFlags(app) return app } @@ -96,28 +104,3 @@ func getDefaultConfigFile() string { } return "" } - -func copyGlobalFlags(app *cli.App) { - for _, command := range app.Commands { - originalFlagNames := make([]string, 0, len(command.Flags)) - for _, flag := range command.Flags { - originalFlagNames = append(originalFlagNames, flag.Names()...) - } - - for _, flag := range app.Flags { - found := false - flagNameLoop: - for _, name := range flag.Names() { - for _, originalName := range originalFlagNames { - if name == originalName { - found = true - break flagNameLoop - } - } - } - if !found { - command.Flags = append(command.Flags, flag) - } - } - } -} diff --git a/cmd/contributors.go b/cmd/contributors.go index fbed4d9..2a06001 100644 --- a/cmd/contributors.go +++ b/cmd/contributors.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/changelog/config" "code.gitea.io/changelog/service" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var Contributors = &cli.Command{ diff --git a/cmd/generate.go b/cmd/generate.go index 9da8178..39aff8e 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -12,7 +12,7 @@ import ( "code.gitea.io/changelog/config" "code.gitea.io/changelog/service" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var Generate = &cli.Command{ diff --git a/cmd/init.go b/cmd/init.go index 629a155..9aaa3a5 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/changelog/config" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var ( diff --git a/go.mod b/go.mod index 15b0fbc..689515b 100644 --- a/go.mod +++ b/go.mod @@ -5,18 +5,18 @@ go 1.18 require ( code.gitea.io/sdk/gitea v0.14.0 github.com/google/go-github/v50 v50.0.0 - github.com/urfave/cli/v2 v2.2.0 + github.com/urfave/cli/v3 v3.0.0-alpha2 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be gopkg.in/yaml.v2 v2.3.0 ) require ( - github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/golang/protobuf v1.3.2 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/hashicorp/go-version v1.2.1 // indirect - github.com/russross/blackfriday/v2 v2.0.1 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 09a7632..58d0610 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ code.gitea.io/sdk/gitea v0.14.0 h1:m4J352I3p9+bmJUfS+g0odeQzBY/5OXP91Gv6D4fnJ0= code.gitea.io/sdk/gitea v0.14.0/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -19,15 +17,15 @@ github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pB github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= -github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +github.com/urfave/cli/v3 v3.0.0-alpha2 h1:JKkuTewMlS2leTQeAcsPGL7WmBVa2uoBLy89As4Jauc= +github.com/urfave/cli/v3 v3.0.0-alpha2/go.mod h1:gHI/xEYplFhOa3Y90xJleh3kqqsSanBj/19hVFxiVZ4= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -- 2.43.5 From 07c0fc1414e7b3b7f508aacdb16b5d238628a769 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 14 Apr 2023 15:17:23 -0400 Subject: [PATCH 17/25] release tag pipeline --- .gitea/workflows/release-tag.yml | 41 ++++++++++++++++++++++++++++++++ .goreleaser.yaml | 6 ++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/release-tag.yml diff --git a/.gitea/workflows/release-tag.yml b/.gitea/workflows/release-tag.yml new file mode 100644 index 0000000..4ae629b --- /dev/null +++ b/.gitea/workflows/release-tag.yml @@ -0,0 +1,41 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v3 + with: + go-version: '>=1.20.1' + - name: Import GPG key + id: import_gpg + uses: https://github.com/crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + fingerprint: CC64B1DB67ABBEECAB24B6455FC346329753F4B0 + - 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 }} + GORELEASER_FORCE_TOKEN: 'gitea' + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 86c179e..5509356 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -54,7 +54,7 @@ builds: flags: - -trimpath ldflags: - - -s -w -X code.gitea.io/changelog/cmd.Version={{ .Version }} + - -s -w -X code.gitea.io/changelog/cmd.Version={{ .Summary }} binary: >- {{ .ProjectName }}- {{- .Version }}- @@ -99,5 +99,9 @@ snapshot: 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 -- 2.43.5 From 482c085290212f6e2be5abddfe6798a955d6b940 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 23 Jun 2023 17:20:48 +0000 Subject: [PATCH 18/25] Respect --token argument on github too (#79) Reviewed-on: https://gitea.com/gitea/changelog/pulls/79 Reviewed-by: John Olheiser Reviewed-by: delvh --- service/github.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/service/github.go b/service/github.go index 00894b6..dd145b2 100644 --- a/service/github.go +++ b/service/github.go @@ -22,14 +22,15 @@ type GitHub struct { Token string Repo string Issues bool + client *github.Client } // Generate returns a GitHub changelog func (gh *GitHub) Generate() (string, []Entry, error) { - tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02")) - - client := github.NewClient(httpClient()) ctx := context.Background() + gh.initClient(ctx) + + tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02")) prs := make([]Entry, 0) @@ -42,7 +43,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { p := 1 perPage := 100 for { - result, _, err := client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -84,15 +85,15 @@ func (gh *GitHub) Generate() (string, []Entry, error) { // Contributors returns a list of contributors from GitHub func (gh *GitHub) Contributors() (ContributorList, error) { - client := github.NewClient(httpClient()) ctx := context.Background() + gh.initClient(ctx) contributorsMap := make(map[string]bool) query := fmt.Sprintf(`repo:%s is:merged milestone:"%s"`, gh.Repo, gh.Milestone) p := 1 perPage := 100 for { - result, _, err := client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -123,14 +124,19 @@ func (gh *GitHub) Contributors() (ContributorList, error) { return contributors, nil } -func httpClient() *http.Client { +func (gh *GitHub) initClient(ctx context.Context) { + token := gh.Token + if envToken, ok := os.LookupEnv("CHANGELOG_GITHUB_TOKEN"); ok && token == "" { + token = envToken + } + cl := http.DefaultClient - if token, ok := os.LookupEnv("CHANGELOG_GITHUB_TOKEN"); ok { - ctx := context.Background() + if token != "" { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, ) cl = oauth2.NewClient(ctx, ts) } - return cl + + gh.client = github.NewClient(cl) } -- 2.43.5 From 3d93c3a0cdc92eff027f47c19b96efd3092c186d Mon Sep 17 00:00:00 2001 From: jolheiser Date: Thu, 20 Jul 2023 10:08:48 +0000 Subject: [PATCH 19/25] Use issue list API instead of search (#78) This PR changes to using the GH issue list API rather than search, as for some reason the search results started missing several PRs... Reviewed-on: https://gitea.com/gitea/changelog/pulls/78 Co-authored-by: jolheiser Co-committed-by: jolheiser --- service/github.go | 76 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/service/github.go b/service/github.go index dd145b2..c079619 100644 --- a/service/github.go +++ b/service/github.go @@ -6,9 +6,12 @@ package service import ( "context" + "errors" "fmt" "net/http" "os" + "strconv" + "strings" "time" "github.com/google/go-github/v50/github" @@ -25,8 +28,18 @@ type GitHub struct { client *github.Client } +// OwnerRepo splits owner/repo +func (gh *GitHub) OwnerRepo() (string, string) { + parts := strings.Split(gh.Repo, "/") + if len(parts) < 2 { + return parts[0], "" + } + return parts[0], parts[1] +} + // Generate returns a GitHub changelog func (gh *GitHub) Generate() (string, []Entry, error) { + owner, repo := gh.OwnerRepo() ctx := context.Background() gh.initClient(ctx) @@ -34,16 +47,17 @@ func (gh *GitHub) Generate() (string, []Entry, error) { prs := make([]Entry, 0) - state := "merged" - if gh.Issues { - state = "closed" + milestoneNum, err := gh.milestoneNum(ctx) + if err != nil { + return "", nil, err } - query := fmt.Sprintf(`repo:%s is:%s milestone:"%s"`, gh.Repo, state, gh.Milestone) p := 1 perPage := 100 for { - result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + Milestone: strconv.Itoa(milestoneNum), + State: "closed", ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -56,7 +70,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { isPull := !(gh.Issues) - for _, pr := range result.Issues { + for _, pr := range result { if pr.IsPullRequest() == isPull { p := Entry{ Title: CleanTitle(pr.GetTitle()), @@ -75,7 +89,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { } } - if len(result.Issues) != perPage { + if len(result) != perPage { break } } @@ -86,14 +100,20 @@ func (gh *GitHub) Generate() (string, []Entry, error) { // Contributors returns a list of contributors from GitHub func (gh *GitHub) Contributors() (ContributorList, error) { ctx := context.Background() + owner, repo := gh.OwnerRepo() gh.initClient(ctx) contributorsMap := make(map[string]bool) - query := fmt.Sprintf(`repo:%s is:merged milestone:"%s"`, gh.Repo, gh.Milestone) + milestoneNum, err := gh.milestoneNum(ctx) + if err != nil { + return nil, err + } p := 1 perPage := 100 for { - result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + Milestone: strconv.Itoa(milestoneNum), + State: "closed", ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -104,11 +124,11 @@ func (gh *GitHub) Contributors() (ContributorList, error) { } p++ - for _, pr := range result.Issues { + for _, pr := range result { contributorsMap[pr.GetUser().GetLogin()] = true } - if len(result.Issues) != perPage { + if len(result) != perPage { break } } @@ -129,7 +149,6 @@ func (gh *GitHub) initClient(ctx context.Context) { if envToken, ok := os.LookupEnv("CHANGELOG_GITHUB_TOKEN"); ok && token == "" { token = envToken } - cl := http.DefaultClient if token != "" { ts := oauth2.StaticTokenSource( @@ -140,3 +159,36 @@ func (gh *GitHub) initClient(ctx context.Context) { gh.client = github.NewClient(cl) } + +func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { + owner, repo := gh.OwnerRepo() + p := 1 + perPage := 100 + for { + milestones, _, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{ + State: "all", + ListOptions: github.ListOptions{ + Page: p, + PerPage: perPage, + }, + Sort: "due_on", + Direction: "desc", + }) + if err != nil { + return 0, err + } + p++ + + for _, milestone := range milestones { + if strings.EqualFold(milestone.GetTitle(), gh.Milestone) { + return milestone.GetNumber(), nil + } + } + + if len(milestones) != perPage { + break + } + } + + return 0, errors.New("no milestone found") +} -- 2.43.5 From 769323fbd7c2fdd00b74607aabdf2fe10177d224 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Sep 2023 14:35:42 +0000 Subject: [PATCH 20/25] minor updates to readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1e9ad83..e0f2cb7 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ A changelog generator for Gitea -[![Build Status](https://drone.gitea.com/api/badges/gitea/changelog/status.svg)](https://drone.gitea.com/gitea/changelog) - ## Purpose This repo is currently part of Gitea. The purpose of it is to generate a changelog when writing release notes. @@ -12,7 +10,7 @@ This tool generates a changelog from PRs based on their milestone and labels. ## Installation -Download a pre-built binary from our [downloads page](https://dl.gitea.io/changelog-tool/) or clone the source and follow the [building instructions](#building). +Download a pre-built binary from our [downloads page](https://dl.gitea.com/changelog-tool/) or clone the source and follow the [building instructions](#building). ## Configuration @@ -45,7 +43,7 @@ Fork -> Patch -> Push -> Pull Request ## Authors * [Maintainers](https://gitea.com/org/gitea/members) -* [Contributors](https://gitea.com/gitea/changelog/commits/branch/master) +* [Contributors](https://gitea.com/gitea/changelog/commits/branch/main) ## License -- 2.43.5 From 91a081912c1d93e8dfa142e0d90671f2b478fa42 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Tue, 14 Nov 2023 02:08:19 +0000 Subject: [PATCH 21/25] Switch to new label style (#83) Reviewed-on: https://gitea.com/gitea/changelog/pulls/83 Reviewed-by: John Olheiser Reviewed-by: delvh Co-authored-by: Denys Konovalov Co-committed-by: Denys Konovalov --- config/changelog.example.yml | 121 ++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 57 deletions(-) diff --git a/config/changelog.example.yml b/config/changelog.example.yml index d092155..d8b460b 100644 --- a/config/changelog.example.yml +++ b/config/changelog.example.yml @@ -1,57 +1,64 @@ -# The full repository name -repo: go-gitea/gitea - -# Service type (gitea or github) -service: github - -# Base URL for Gitea instance if using gitea service type (optional) -# Default: https://gitea.com -base-url: - -# Changelog groups and which labeled PRs to add to each group -groups: - - - name: BREAKING - labels: - - kind/breaking - - - name: FEATURES - labels: - - kind/feature - - - name: BUGFIXES - labels: - - kind/bug - - - name: ENHANCEMENTS - labels: - - kind/enhancement - - kind/refactor - - kind/ui - - - name: SECURITY - labels: - - kind/security - - - name: TESTING - labels: - - kind/testing - - - name: TRANSLATION - labels: - - kind/translation - - - name: BUILD - labels: - - kind/build - - kind/lint - - - name: DOCS - labels: - - kind/docs - - - name: MISC - default: true - -# regex indicating which labels to skip for the changelog -skip-labels: skip-changelog|backport\/.+ \ No newline at end of file +# The full repository name +repo: go-gitea/gitea + +# Service type (gitea or github) +service: github + +# Base URL for Gitea instance if using gitea service type (optional) +# Default: https://gitea.com +base-url: + +# Changelog groups and which labeled PRs to add to each group +groups: + - + name: BREAKING + labels: + - pr/breaking + - + name: FEATURES + labels: + - type/feature + - + name: API + labels: + - modifies/api + - + name: BUGFIXES + labels: + - type/bug + - + name: ENHANCEMENTS + labels: + - type/enhancement + - type/refactoring + - topic/ui + - topic/ui-interaction + - performance/speed + - + name: SECURITY + labels: + - topic/security + - + name: TESTING + labels: + - type/testing + - + name: TRANSLATION + labels: + - modifies/translation + - + name: BUILD + labels: + - topic/build + - topic/code-linting + - + name: DOCS + labels: + - type/docs + - modifies/docs + - + name: MISC + default: true + +# regex indicating which labels to skip for the changelog +skip-labels: skip-changelog|backport\/.+|type\/dependency-update \ No newline at end of file -- 2.43.5 From 9d720a45a2295f9aa30c649cd788917e31d33d8f Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 27 Mar 2024 20:08:27 +0000 Subject: [PATCH 22/25] Remove `type/dependency-update` (#84) This only removes the `type/dependency-update` label which I recently deleted on GitHub. The file was CRLF and the web editor converted it to LF. I'd say LF is preferred anyways. Reviewed-on: https://gitea.com/gitea/changelog/pulls/84 Reviewed-by: Lunny Xiao Reviewed-by: Denys Konovalov --- config/changelog.example.yml | 128 +++++++++++++++++------------------ 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/config/changelog.example.yml b/config/changelog.example.yml index d8b460b..e4eef9e 100644 --- a/config/changelog.example.yml +++ b/config/changelog.example.yml @@ -1,64 +1,64 @@ -# The full repository name -repo: go-gitea/gitea - -# Service type (gitea or github) -service: github - -# Base URL for Gitea instance if using gitea service type (optional) -# Default: https://gitea.com -base-url: - -# Changelog groups and which labeled PRs to add to each group -groups: - - - name: BREAKING - labels: - - pr/breaking - - - name: FEATURES - labels: - - type/feature - - - name: API - labels: - - modifies/api - - - name: BUGFIXES - labels: - - type/bug - - - name: ENHANCEMENTS - labels: - - type/enhancement - - type/refactoring - - topic/ui - - topic/ui-interaction - - performance/speed - - - name: SECURITY - labels: - - topic/security - - - name: TESTING - labels: - - type/testing - - - name: TRANSLATION - labels: - - modifies/translation - - - name: BUILD - labels: - - topic/build - - topic/code-linting - - - name: DOCS - labels: - - type/docs - - modifies/docs - - - name: MISC - default: true - -# regex indicating which labels to skip for the changelog -skip-labels: skip-changelog|backport\/.+|type\/dependency-update \ No newline at end of file +# The full repository name +repo: go-gitea/gitea + +# Service type (gitea or github) +service: github + +# Base URL for Gitea instance if using gitea service type (optional) +# Default: https://gitea.com +base-url: + +# Changelog groups and which labeled PRs to add to each group +groups: + - + name: BREAKING + labels: + - pr/breaking + - + name: FEATURES + labels: + - type/feature + - + name: API + labels: + - modifies/api + - + name: BUGFIXES + labels: + - type/bug + - + name: ENHANCEMENTS + labels: + - type/enhancement + - type/refactoring + - topic/ui + - topic/ui-interaction + - performance/speed + - + name: SECURITY + labels: + - topic/security + - + name: TESTING + labels: + - type/testing + - + name: TRANSLATION + labels: + - modifies/translation + - + name: BUILD + labels: + - topic/build + - topic/code-linting + - + name: DOCS + labels: + - type/docs + - modifies/docs + - + name: MISC + default: true + +# regex indicating which labels to skip for the changelog +skip-labels: skip-changelog|backport\/.+ \ No newline at end of file -- 2.43.5 From ee1b5532aaf234aeb19fe74e889df1c1aea9c120 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 24 May 2024 05:59:15 +0000 Subject: [PATCH 23/25] Github support rate limit (#85) Reviewed-on: https://gitea.com/gitea/changelog/pulls/85 --- .gitea/workflows/release-nightly.yml | 6 +-- .gitea/workflows/release-tag.yml | 6 +-- .gitea/workflows/test-pr.yml | 6 +-- cmd/generate.go | 4 +- cmd/init.go | 3 +- config/config.go | 4 +- go.mod | 5 +-- go.sum | 9 ++--- service/gitea.go | 3 +- service/github.go | 59 ++++++++++++++++++++++++---- service/github_test.go | 7 +++- service/service.go | 4 +- 12 files changed, 81 insertions(+), 35 deletions(-) diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml index 9304808..3cbb7a8 100644 --- a/.gitea/workflows/release-nightly.yml +++ b/.gitea/workflows/release-nightly.yml @@ -8,13 +8,13 @@ jobs: goreleaser: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - run: git fetch --force --tags - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: goreleaser uses: https://github.com/goreleaser/goreleaser-action@v4 with: diff --git a/.gitea/workflows/release-tag.yml b/.gitea/workflows/release-tag.yml index 4ae629b..f20d132 100644 --- a/.gitea/workflows/release-tag.yml +++ b/.gitea/workflows/release-tag.yml @@ -9,13 +9,13 @@ jobs: goreleaser: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - run: git fetch --force --tags - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: Import GPG key id: import_gpg uses: https://github.com/crazy-max/ghaction-import-gpg@v5 diff --git a/.gitea/workflows/test-pr.yml b/.gitea/workflows/test-pr.yml index cda25df..00e7e1b 100644 --- a/.gitea/workflows/test-pr.yml +++ b/.gitea/workflows/test-pr.yml @@ -6,10 +6,10 @@ jobs: check-and-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: check-and-test run: | go test -race ./... diff --git a/cmd/generate.go b/cmd/generate.go index 39aff8e..bb4ebbe 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -21,7 +21,7 @@ var Generate = &cli.Command{ Action: runGenerate, } -func runGenerate(_ *cli.Context) error { +func runGenerate(ctx *cli.Context) error { cfg, err := config.New(configPathFlag) if err != nil { return err @@ -32,7 +32,7 @@ func runGenerate(_ *cli.Context) error { return err } - title, prs, err := s.Generate() + title, prs, err := s.Generate(ctx.Context) if err != nil { return err } diff --git a/cmd/init.go b/cmd/init.go index 9aaa3a5..5ecca0b 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -6,7 +6,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "code.gitea.io/changelog/config" @@ -37,7 +36,7 @@ func runInit(_ *cli.Context) error { return fmt.Errorf("file '%s' already exists", nameFlag) } - if err := ioutil.WriteFile(nameFlag, config.DefaultConfig, os.ModePerm); err != nil { + if err := os.WriteFile(nameFlag, config.DefaultConfig, os.ModePerm); err != nil { return err } diff --git a/config/config.go b/config/config.go index 08a32ae..506cfb8 100644 --- a/config/config.go +++ b/config/config.go @@ -6,7 +6,7 @@ package config import ( _ "embed" - "io/ioutil" + "os" "regexp" "gopkg.in/yaml.v2" @@ -64,7 +64,7 @@ func New(configPath string) (*Config, error) { var err error configContent := DefaultConfig if len(configPath) != 0 { - configContent, err = ioutil.ReadFile(configPath) + configContent, err = os.ReadFile(configPath) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 689515b..00e3457 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module code.gitea.io/changelog -go 1.18 +go 1.22 require ( code.gitea.io/sdk/gitea v0.14.0 - github.com/google/go-github/v50 v50.0.0 + github.com/google/go-github/v61 v61.0.0 github.com/urfave/cli/v3 v3.0.0-alpha2 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be gopkg.in/yaml.v2 v2.3.0 @@ -17,7 +17,6 @@ require ( github.com/hashicorp/go-version v1.2.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect google.golang.org/appengine v1.6.7 // indirect ) diff --git a/go.sum b/go.sum index 58d0610..931fd86 100644 --- a/go.sum +++ b/go.sum @@ -8,9 +8,10 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-github/v50 v50.0.0 h1:gdO1AeuSZZK4iYWwVbjni7zg8PIQhp7QfmPunr016Jk= -github.com/google/go-github/v50 v50.0.0/go.mod h1:Ev4Tre8QoKiolvbpOSG3FIi4Mlon3S2Nt9W5JYqKiwA= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go= +github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= @@ -27,8 +28,6 @@ github.com/urfave/cli/v3 v3.0.0-alpha2/go.mod h1:gHI/xEYplFhOa3Y90xJleh3kqqsSanB github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= diff --git a/service/gitea.go b/service/gitea.go index 2c85808..e8160ea 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -5,6 +5,7 @@ package service import ( + "context" "fmt" "time" @@ -23,7 +24,7 @@ type Gitea struct { } // Generate returns a Gitea changelog -func (ge *Gitea) Generate() (string, []Entry, error) { +func (ge *Gitea) Generate(_ context.Context) (string, []Entry, error) { client, err := gitea.NewClient(ge.BaseURL, gitea.SetToken(ge.Token)) if err != nil { return "", nil, err diff --git a/service/github.go b/service/github.go index c079619..4f943c5 100644 --- a/service/github.go +++ b/service/github.go @@ -8,13 +8,14 @@ import ( "context" "errors" "fmt" + log "log/slog" "net/http" "os" "strconv" "strings" "time" - "github.com/google/go-github/v50/github" + "github.com/google/go-github/v61/github" "golang.org/x/oauth2" ) @@ -25,7 +26,45 @@ type GitHub struct { Token string Repo string Issues bool + ctx context.Context client *github.Client + rate *github.Rate +} + +func (gh *GitHub) setRate(rate *github.Rate) { + gh.rate = rate +} + +func (gh *GitHub) RefreshRate() error { + rates, _, err := gh.client.RateLimit.Get(gh.ctx) + if err != nil { + // if rate limit is not enabled, ignore it + if strings.Contains(err.Error(), "404") { + gh.setRate(nil) + return nil + } + return err + } + + gh.setRate(rates.GetCore()) + return nil +} + +func (gh *GitHub) waitAndPickClient() { + for gh.rate != nil && gh.rate.Remaining <= 0 { + timer := time.NewTimer(time.Until(gh.rate.Reset.Time)) + select { + case <-gh.ctx.Done(): + timer.Stop() + return + case <-timer.C: + } + + err := gh.RefreshRate() + if err != nil { + log.Error("g.getClient().RateLimit.Get: %s", err) + } + } } // OwnerRepo splits owner/repo @@ -38,12 +77,11 @@ func (gh *GitHub) OwnerRepo() (string, string) { } // Generate returns a GitHub changelog -func (gh *GitHub) Generate() (string, []Entry, error) { +func (gh *GitHub) Generate(ctx context.Context) (string, []Entry, error) { owner, repo := gh.OwnerRepo() - ctx := context.Background() gh.initClient(ctx) - tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02")) + tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/v%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02")) prs := make([]Entry, 0) @@ -55,7 +93,8 @@ func (gh *GitHub) Generate() (string, []Entry, error) { p := 1 perPage := 100 for { - result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + gh.waitAndPickClient() + result, resp, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ Milestone: strconv.Itoa(milestoneNum), State: "closed", ListOptions: github.ListOptions{ @@ -66,6 +105,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { if err != nil { return "", nil, err } + gh.setRate(&resp.Rate) p++ isPull := !(gh.Issues) @@ -111,7 +151,8 @@ func (gh *GitHub) Contributors() (ContributorList, error) { p := 1 perPage := 100 for { - result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + gh.waitAndPickClient() + result, resp, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ Milestone: strconv.Itoa(milestoneNum), State: "closed", ListOptions: github.ListOptions{ @@ -122,6 +163,7 @@ func (gh *GitHub) Contributors() (ContributorList, error) { if err != nil { return nil, err } + gh.setRate(&resp.Rate) p++ for _, pr := range result { @@ -158,6 +200,7 @@ func (gh *GitHub) initClient(ctx context.Context) { } gh.client = github.NewClient(cl) + gh.ctx = ctx } func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { @@ -165,7 +208,8 @@ func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { p := 1 perPage := 100 for { - milestones, _, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{ + gh.waitAndPickClient() + milestones, resp, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{ State: "all", ListOptions: github.ListOptions{ Page: p, @@ -177,6 +221,7 @@ func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { if err != nil { return 0, err } + gh.setRate(&resp.Rate) p++ for _, milestone := range milestones { diff --git a/service/github_test.go b/service/github_test.go index 562216d..2cc4f17 100644 --- a/service/github_test.go +++ b/service/github_test.go @@ -4,7 +4,10 @@ package service -import "testing" +import ( + "context" + "testing" +) var gh = &GitHub{ Milestone: "1.1.0", // https://github.com/go-gitea/test_repo/milestone/2?closed=1 @@ -12,7 +15,7 @@ var gh = &GitHub{ } func TestGitHubGenerate(t *testing.T) { - _, entries, err := gh.Generate() + _, entries, err := gh.Generate(context.Background()) if err != nil { t.Log(err) t.FailNow() diff --git a/service/service.go b/service/service.go index 685d5b9..58f29d7 100644 --- a/service/service.go +++ b/service/service.go @@ -5,6 +5,7 @@ package service import ( + "context" "fmt" "strings" "unicode" @@ -48,7 +49,7 @@ func New(serviceType, repo, baseURL, milestone, tag, token string, issues bool) // Service defines how a struct can be a Changelog Service type Service interface { - Generate() (string, []Entry, error) + Generate(ctx context.Context) (string, []Entry, error) Contributors() (ContributorList, error) } @@ -90,7 +91,6 @@ func (cl ContributorList) Swap(i, j int) { // CleanTitle returns the string with spaces trimmed and the first rune title-cased func CleanTitle(s string) string { - s = strings.TrimSpace(s) r := []rune(s) -- 2.43.5 From c71343729044ba7d46c79db5dcb0b5874d2d26ff Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sun, 26 May 2024 21:39:37 +0000 Subject: [PATCH 24/25] Update .goreleaser.yaml --- .goreleaser.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5509356..908be06 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -99,6 +99,8 @@ snapshot: nightly: name_template: "{{ .Branch }}" +force_token: gitea + gitea_urls: api: https://gitea.com/api/v1 download: https://gitea.com -- 2.43.5 From e5f22910df3a577d2de34a312a70809494e0b18a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sun, 26 May 2024 21:40:53 +0000 Subject: [PATCH 25/25] Update .gitea/workflows/release-nightly.yml --- .gitea/workflows/release-nightly.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml index 3cbb7a8..f521dcc 100644 --- a/.gitea/workflows/release-nightly.yml +++ b/.gitea/workflows/release-nightly.yml @@ -16,7 +16,7 @@ jobs: with: go-version-file: 'go.mod' - name: goreleaser - uses: https://github.com/goreleaser/goreleaser-action@v4 + uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser-pro version: latest @@ -28,3 +28,4 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} S3_REGION: ${{ secrets.AWS_REGION }} S3_BUCKET: ${{ secrets.AWS_BUCKET }} + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} -- 2.43.5