Skip to content

Commit

Permalink
Use GitHub action context for input
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Aug 6, 2024
1 parent 0d29f75 commit d4be951
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 54 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
Expand Down Expand Up @@ -159,7 +158,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
Expand All @@ -169,25 +167,17 @@ jobs:
### Specify the input directory

To run the action for parameters not declared at the root of the repository,
set the parameter `input` to the directory of your `buf.yaml` file.
set the parameter `input` and `breaking_against` to include a subdir to the path
of your `buf.yaml` file. These parameters are configured as a base input ref.

```yaml
- uses: bufbuild/buf-action@v1
with:
input: <path/to/module>
```

Breaking change detection by default will use the `input` value as a subdirectory for the breaking against value.
To customize this behavior, set the parameter `breaking_against` to the desired input.

```yaml
- uses: bufbuild/buf-action@v1
with:
input: <path/to/module>
input: ${{ github.event.repository.clone_url }}#format=git,commit=${{ github.event.pull_request.head.sha }},subdir=<path/to/module>
breaking_against: ${{ github.event.repository.clone_url }}#format=git,commit=${{ github.event.pull_request.base.sha }},subdir=<path/to/module>
```

Alternatively, you can checkout the base for the breaking comparison to a local folder
Alternatively, you can checkout the head and base to a local folder
and then set the value of `breaking_against` to the path of the base.

```yaml
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ inputs:
description: |-
Input for the buf command.
required: false
default: ${{ github.event.repository.clone_url }}#format=git,commit=${{ github.event.pull_request.head.sha || github.event.after }}
paths:
description: |-
Limit to specific files or directories (separated by newlines).
Expand Down Expand Up @@ -112,6 +113,7 @@ inputs:
Input to compare against for breaking change detection.
Defaults to the base branch of the pull request or the commit before the push.
required: false
default: ${{ github.event.repository.clone_url }}#format=git,commit=${{ github.event.pull_request.base.sha || github.event.before }}

push:
description: |-
Expand Down
16 changes: 2 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45413,23 +45413,11 @@ function getInputs() {
archive_labels: [],
};
if (lib_github.context.eventName === "push") {
const event = lib_github.context.payload;
if (inputs.breaking_against === "") {
inputs.breaking_against = `${event.repository.clone_url}#format=git,commit=${event.before}`;
if (inputs.input) {
inputs.breaking_against += `,subdir=${inputs.input}`;
}
}
//const event = github.context.payload as PushEvent;
inputs.archive_labels.push(lib_github.context.ref);
}
if (lib_github.context.eventName === "pull_request") {
const event = lib_github.context.payload;
if (inputs.breaking_against === "") {
inputs.breaking_against = `${event.repository.clone_url}#format=git,commit=${event.pull_request.base.sha}`;
if (inputs.input) {
inputs.breaking_against += `,subdir=${inputs.input}`;
}
}
//const event = github.context.payload as PullRequestEvent;
inputs.archive_labels.push(lib_github.context.ref);
}
if (lib_github.context.eventName === "delete") {
Expand Down
1 change: 0 additions & 1 deletion examples/disable-skip/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion examples/only-checks/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
1 change: 0 additions & 1 deletion examples/only-sync/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
1 change: 0 additions & 1 deletion examples/push-on-changes/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
1 change: 0 additions & 1 deletion examples/skip-on-commits/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion examples/skip-on-labels/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion examples/validate-push/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
# The token paramater is required to authenticate with the Buf Schema Registry.
Expand Down
1 change: 0 additions & 1 deletion examples/version-env/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
setup_only: true
Expand Down
1 change: 0 additions & 1 deletion examples/version-input/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
setup_only: true
Expand Down
1 change: 0 additions & 1 deletion examples/version-latest/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
with:
setup_only: true
Expand Down
20 changes: 4 additions & 16 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import {
PushEvent,
PullRequestEvent,
//PushEvent,
//PullRequestEvent,
DeleteEvent,
} from "@octokit/webhooks-definitions/schema";

Expand Down Expand Up @@ -71,23 +71,11 @@ export function getInputs(): Inputs {
archive_labels: [],
};
if (github.context.eventName === "push") {
const event = github.context.payload as PushEvent;
if (inputs.breaking_against === "") {
inputs.breaking_against = `${event.repository.clone_url}#format=git,commit=${event.before}`;
if (inputs.input) {
inputs.breaking_against += `,subdir=${inputs.input}`;
}
}
//const event = github.context.payload as PushEvent;
inputs.archive_labels.push(github.context.ref);
}
if (github.context.eventName === "pull_request") {
const event = github.context.payload as PullRequestEvent;
if (inputs.breaking_against === "") {
inputs.breaking_against = `${event.repository.clone_url}#format=git,commit=${event.pull_request.base.sha}`;
if (inputs.input) {
inputs.breaking_against += `,subdir=${inputs.input}`;
}
}
//const event = github.context.payload as PullRequestEvent;
inputs.archive_labels.push(github.context.ref);
}
if (github.context.eventName === "delete") {
Expand Down

0 comments on commit d4be951

Please sign in to comment.