From 8ce9b9949fba4fd473038cf511e93a2bd9cccf18 Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Thu, 15 Aug 2024 11:05:46 +0200 Subject: [PATCH 1/4] Update Buf actions --- .github/workflows/buf-push.yaml | 33 ++++++++++++++++ .github/workflows/buf-update.yaml | 27 +++++++++++++ .github/workflows/buf-validate.yaml | 33 ++++++++++++++++ .github/workflows/buf.yml | 39 ------------------- .../workflows/validate-generated-files.yml | 5 ++- 5 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/buf-push.yaml create mode 100644 .github/workflows/buf-update.yaml create mode 100644 .github/workflows/buf-validate.yaml delete mode 100644 .github/workflows/buf.yml diff --git a/.github/workflows/buf-push.yaml b/.github/workflows/buf-push.yaml new file mode 100644 index 0000000..b085409 --- /dev/null +++ b/.github/workflows/buf-push.yaml @@ -0,0 +1,33 @@ +name: buf-push + +on: + push: + branches: + - main + paths: + - 'proto/**' + +jobs: + push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # This step sets up the variable steps.buf-version.outputs.v + # to contain the version of Buf (e.g. v1.36.0) from go.mod. + - name: Get Buf version + id: buf-version + run: | + BUF_VERSION=$( go list -m -f '{{.Version}}' github.com/bufbuild/buf ) + # remove the leading 'v' in front of the version + BUF_VERSION=${BUF_VERSION#v} + echo "v=$BUF_VERSION" >> "$GITHUB_OUTPUT" + - uses: bufbuild/buf-action@v1 + with: + version: ${{ steps.buf-version.outputs.v }} + token: ${{ secrets.BUF_TOKEN }} + input: 'proto' + # The repository should already exist. + # If it can be automatically created, that's a sign that it was deleted, + # which is likely a major issue, which we want to be aware of. + push_disable_create: true diff --git a/.github/workflows/buf-update.yaml b/.github/workflows/buf-update.yaml new file mode 100644 index 0000000..ba8f1c3 --- /dev/null +++ b/.github/workflows/buf-update.yaml @@ -0,0 +1,27 @@ +name: "Run 'buf update'" + +on: + workflow_dispatch: + schedule: + - cron: '30 10 * * 1' + +jobs: + update-buf-dependencies: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ github.token }} + steps: + - uses: actions/checkout@v4 + + - name: Run 'buf update' + run: | + export PATH=$PATH:$(go env GOPATH)/bin + make install-tools proto-update + + - name: Create pull request + uses: peter-evans/create-pull-request@v6.0.2 + with: + title: Update Buf dependencies + body: Automatic pull request for updating Buf dependencies + branch: update-buf-dependencies + commit-message: "[automated] Update Buf dependencies" diff --git a/.github/workflows/buf-validate.yaml b/.github/workflows/buf-validate.yaml new file mode 100644 index 0000000..56b3361 --- /dev/null +++ b/.github/workflows/buf-validate.yaml @@ -0,0 +1,33 @@ +name: buf-validate + +on: + pull_request: + # 'labeled' and 'unlabeled' are included so we can use the 'Buf Skip Breaking' label + # and skip a breaking change if that's required. + # See: https://github.com/bufbuild/buf-action?tab=readme-ov-file#skip-the-breaking-change-detection-step + types: [opened, synchronize, reopened, labeled, unlabeled] + paths: + - 'proto/**' + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # This step sets up the variable steps.buf-version.outputs.v + # to contain the version of Buf (e.g. v1.36.0) from go.mod. + - name: Get Buf version + id: buf-version + run: | + BUF_VERSION=$( go list -m -f '{{.Version}}' github.com/bufbuild/buf ) + # remove the leading 'v' in front of the version + BUF_VERSION=${BUF_VERSION#v} + echo "v=$BUF_VERSION" >> "$GITHUB_OUTPUT" + - uses: bufbuild/buf-action@v1 + with: + version: ${{ steps.buf-version.outputs.v }} + token: ${{ secrets.BUF_TOKEN }} + input: 'proto' + push: false + breaking_against: '${{ github.event.repository.clone_url }}#branch=main,subdir=proto' diff --git a/.github/workflows/buf.yml b/.github/workflows/buf.yml deleted file mode 100644 index 64b939e..0000000 --- a/.github/workflows/buf.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: buf - -on: - push: - branches: [ main ] - pull_request: - -jobs: - validate: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: bufbuild/buf-setup-action@v1 - - uses: bufbuild/buf-lint-action@v1 - with: - input: 'proto' - - # We need to fetch main so we can compare breaking changes against whatever is in main right now. - - name: Fetch origin/main - run: git fetch --no-tags --prune --depth=1 origin +refs/heads/main:refs/remotes/origin/main - - - uses: bufbuild/buf-breaking-action@v1 - with: - input: 'proto' - against: '.git#branch=origin/main,subdir=proto' - - # Push buf module to the buf schema registry, but only if the validate action succeeded and if the action is running - # on branch main. - push: - runs-on: ubuntu-latest - needs: validate - if: ${{ github.ref == 'refs/heads/main' }} - steps: - - uses: actions/checkout@v4 - - uses: bufbuild/buf-setup-action@v1 - - uses: bufbuild/buf-push-action@v1 - with: - input: 'proto' - buf_token: ${{ secrets.BUF_TOKEN }} diff --git a/.github/workflows/validate-generated-files.yml b/.github/workflows/validate-generated-files.yml index eb296f2..3f8a096 100644 --- a/.github/workflows/validate-generated-files.yml +++ b/.github/workflows/validate-generated-files.yml @@ -17,7 +17,10 @@ jobs: go-version-file: 'go.mod' - name: Check generated files + env: + BUF_TOKEN: ${{ secrets.BUF_TOKEN }} run: | export PATH=$PATH:$(go env GOPATH)/bin - make install-tools generate buf + make install-tools generate proto-generate + git diff git diff --exit-code --numstat From 40827de612d91e017c91f8c974a9450ae0ae2c0f Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Thu, 15 Aug 2024 11:15:07 +0200 Subject: [PATCH 2/4] standardized makefile --- Makefile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index dc08494..d9b1ae5 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,14 @@ install-tools: generate: go generate ./... -.PHONY: buf -buf: - cd proto && buf generate +.PHONY: proto-generate +proto-generate: + rm -rf proto/gen && cd proto && buf generate + +.PHONY: proto-update +proto-update: + cd proto && buf dep update + +.PHONY: proto-lint +proto-lint: + cd proto && buf lint From 78ce8e0d5430747e3fb2c89de4d5ff299496d463 Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Mon, 19 Aug 2024 18:18:02 +0200 Subject: [PATCH 3/4] simplify --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d9b1ae5..0fb4b1c 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ generate: .PHONY: proto-generate proto-generate: - rm -rf proto/gen && cd proto && buf generate + cd proto && buf generate .PHONY: proto-update proto-update: From ea692d998f5b5a9d932b0744196fac01e279738d Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Mon, 19 Aug 2024 19:18:25 +0200 Subject: [PATCH 4/4] update action --- .github/workflows/buf-update.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buf-update.yaml b/.github/workflows/buf-update.yaml index ba8f1c3..a923354 100644 --- a/.github/workflows/buf-update.yaml +++ b/.github/workflows/buf-update.yaml @@ -19,7 +19,7 @@ jobs: make install-tools proto-update - name: Create pull request - uses: peter-evans/create-pull-request@v6.0.2 + uses: peter-evans/create-pull-request@v6.1.0 with: title: Update Buf dependencies body: Automatic pull request for updating Buf dependencies