Skip to content

Commit

Permalink
Fix push with no configured module names (#31)
Browse files Browse the repository at this point in the history
This PR allows for better push behaviour when unnamed modules are
present. The action will now read the `buf.yaml` config file to check
for missing names before running the push or archive steps. With the
latest release of `buf`@v.1.33.0 we can now also use the flag
`--exclude-unnamed` to avoid failing push on unnamed modules when
multiple modules are present. As a test (and example) see the
`test-push-unnamed` step in CI.

In addition is the introduction of outputs in the `action.yml` by
setting the resolved version of `buf`.
  • Loading branch information
emcfarlane authored Jun 13, 2024
1 parent 4bf9507 commit d17c53a
Show file tree
Hide file tree
Showing 9 changed files with 8,796 additions and 48 deletions.
142 changes: 119 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ permissions:
contents: read
pull-requests: write
env:
BUF_VERSION: "1.32.2"
BUF_VERSION: "1.33.0"
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Check diff
run: |
make checkgenerate
setup:
test-setup:
runs-on: ubuntu-latest
needs: build
steps:
Expand All @@ -36,9 +36,9 @@ jobs:
with:
setup_only: true
- run: buf --version | grep $BUF_VERSION
setup-latest:
test-setup-latest:
runs-on: ubuntu-latest
needs: build
needs: test-setup
env:
BUF_VERSION: "" # Use the latest version
steps:
Expand All @@ -47,8 +47,8 @@ jobs:
with:
setup_only: true
- run: buf --version
setup-macos:
needs: setup
test-setup-macos:
needs: test-setup
if: github.event_name == 'push'
runs-on: macos-latest
steps:
Expand All @@ -57,8 +57,8 @@ jobs:
with:
setup_only: true
- run: buf --version | grep $BUF_VERSION
setup-windows:
needs: setup
test-setup-windows:
needs: test-setup
if: github.event_name == 'push'
runs-on: windows-latest
steps:
Expand All @@ -67,8 +67,8 @@ jobs:
with:
setup_only: true
- run: buf --version | Select-String -Pattern $env:BUF_VERSION -CaseSensitive -SimpleMatch
setup-self-hosted:
needs: setup
test-setup-self-hosted:
needs: test-setup
# Disable this job, only for testing.
if: false
runs-on: self-hosted
Expand All @@ -78,7 +78,7 @@ jobs:
with:
setup_only: true
- run: buf --version | grep $BUF_VERSION
lint:
test-lint:
runs-on: ubuntu-latest
needs: build
steps:
Expand All @@ -95,7 +95,7 @@ jobs:
push: false
archive: false
comment: false
format:
test-format:
runs-on: ubuntu-latest
needs: build
steps:
Expand All @@ -112,7 +112,7 @@ jobs:
push: false
archive: false
comment: false
breaking:
test-breaking:
runs-on: ubuntu-latest
needs: build
steps:
Expand All @@ -130,10 +130,13 @@ jobs:
push: false
archive: false
comment: false
comment:
test-comment:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs: [lint,format,breaking]
needs:
- test-lint
- test-format
- test-breaking
steps:
- uses: actions/checkout@v4
- env:
Expand Down Expand Up @@ -206,7 +209,7 @@ jobs:
}
`))
core.info('Updated comment.');
push:
test-push:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }} # --git-metadata is only available on push
needs: build
Expand All @@ -228,7 +231,7 @@ jobs:
push: true
archive: false
comment: false
push-token-only:
test-push-token-only:
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }} # --git-metadata is only available on push
Expand All @@ -249,12 +252,67 @@ jobs:
push: true
archive: false
comment: false
archive:
test-push-unnamed:
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }} # --git-metadata is only available on push
steps:
- uses: actions/checkout@v4
# Test v2 buf.yaml config.
- run: |
mkdir -p proto/foo/v1
printf "version: v2\nmodules:\n - path: proto\n" > buf.yaml
printf "syntax = \"proto3\";\npackage foo.v1;\nmessage Bar {}\n" > proto/foo/v1/bar.proto
- uses: ./
with:
token: ${{ secrets.BUF_TOKEN }}
lint: false
format: false
breaking: false
push: true
archive: false
comment: false
# Test v1 buf.yaml config.
- run: |
rm -rf proto
mkdir -p proto/foo/v1
printf "version: v1\n" > proto/buf.yaml
printf "syntax = \"proto3\";\npackage foo.v1;\nmessage Bar {}\n" > proto/foo/v1/bar.proto
- uses: ./
with:
token: ${{ secrets.BUF_TOKEN }}
lint: false
format: false
breaking: false
push: true
archive: false
comment: false
input: proto
# Test v2 with multiple modules, one without a name.
- env:
BUF_USERNAME: ${{ secrets.BUF_USERNAME }}
run: |
mkdir -p foo/foo/v1 bar/bar/v1
printf "syntax = \"proto3\";\npackage foo.v1;\nmessage Bar {}\n" > foo/foo/v1/bar.proto
printf "syntax = \"proto3\";\npackage bar.v1;\nmessage Foo {}\n" > bar/bar/v1/foo.proto
printf "version: v2\nmodules:\n - path: foo\n name: buf.build/${BUF_USERNAME}/foo\n - path: bar\n" > buf.yaml
- uses: ./
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
lint: false
format: false
breaking: false
push: true
archive: false
comment: false
test-archive:
if: github.event_name == 'push' && github.ref_name != github.event.repository.default_branch
runs-on: ubuntu-latest
needs:
- push
- push-token-only
- test-push
- test-push-token-only
- test-push-unnamed
steps:
- uses: actions/checkout@v4
- env:
Expand All @@ -275,12 +333,13 @@ jobs:
# On push github.ref_name, on delete github.event.ref_name.
archive_labels: ${{ github.ref_name }}
comment: false
archive-not-exists:
test-archive-not-exists:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- push
- push-token-only
- test-push
- test-push-token-only
- test-push-unnamed
steps:
- uses: actions/checkout@v4
- env:
Expand Down Expand Up @@ -313,3 +372,40 @@ jobs:
label_does_not_exist
label_does_not_exist_either
comment: false
test-archive-unnamed:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- test-push
- test-push-token-only
- test-push-unnamed
steps:
- uses: actions/checkout@v4
- run: |
mkdir -p proto/foo/v1
printf "version: v2\nmodules:\n - path: proto\n" > buf.yaml
printf "syntax = \"proto3\";\npackage foo.v1;\nmessage Bar {}\n" > proto/foo/v1/bar.proto
- uses: ./
with:
token: ${{ secrets.BUF_TOKEN }}
lint: false
format: false
breaking: false
push: false
archive: true
comment: false
- run: |
rm -rf proto
mkdir -p proto/foo/v1
printf "version: v1\n" > proto/buf.yaml
printf "syntax = \"proto3\";\npackage foo.v1;\nmessage Bar {}\n" > proto/foo/v1/bar.proto
- uses: ./
with:
token: ${{ secrets.BUF_TOKEN }}
lint: false
format: false
breaking: false
push: false
archive: true
comment: false
input: proto
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ inputs:
default: |
${{ github.event.ref }}
outputs:
buf_version:
description: |-
Version of the Buf CLI used.
runs:
using: "node20"
main: "./dist/index.js"
Loading

0 comments on commit d17c53a

Please sign in to comment.