Skip to content

Commit

Permalink
Drop username config
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Jul 24, 2024
1 parent 001e684 commit 8a51c13
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 47 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
```
Expand All @@ -65,7 +64,6 @@ Add these parameters under the `with` section of the `uses` step in the workflow
| Parameter | Description | Default |
|:--------------------------------|:---------------------------------------------------|:-------------------|
| `version` | Version of the `buf` CLI to use. | Latest [version][buf-releases] |
| `username` | Username for [logging into the BSR](https://buf.build/docs/bsr/authentication). | |
| `token` | API token for [logging into the BSR](https://buf.build/docs/bsr/authentication). | |
| `domain` | Domain for logging into the BSR, enterprise only.| `buf.build` |
| `input` | [Input](https://buf.build/docs/reference/inputs) for the `buf` command. | |
Expand Down Expand Up @@ -131,15 +129,12 @@ If no version is specified in the workflow config, the action will resolve the v
way for consumers of your APIs to generate code.
Authenticating with the BSR is required for both the push and archive label steps.

To authenticate with the BSR, set the parameters `username` and `token`.
The `username` and `token` values should be
[stored as secrets in the repository settings](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
The `token` value can be [generated from the BSR UI](https://buf.build/docs/bsr/authentication#create-an-api-token).
To authenticate with the BSR, set the API token as the parameter `token`.
Generate a token from the [BSR UI](https://buf.build/docs/bsr/authentication#create-an-api-token) and add it to the [repository secrets](https://docs.github.com/en/actions/reference/encrypted-secrets).

```yaml
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
```

Expand Down Expand Up @@ -170,7 +165,6 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
+ pr_comment: false
```
Expand Down
4 changes: 0 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ inputs:
with:
version: 1.34.0
required: false
username:
description: |-
Username for logging into the BSR.
required: false
token:
description: |-
API token for logging into the BSR.
Expand Down
11 changes: 3 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45391,7 +45391,6 @@ var parse_diff = __nccwpck_require__(4833);
function getInputs() {
const inputs = {
version: core.getInput("version"),
username: core.getInput("username"),
token: core.getInput("token") || getEnv("BUF_TOKEN"),
domain: core.getInput("domain"),
setup_only: core.getBooleanInput("setup_only"),
Expand Down Expand Up @@ -45848,16 +45847,12 @@ async function runWorkflow(bufPath, inputs, moduleNames) {
}
// login logs in to the Buf registry, storing credentials.
async function login(bufPath, inputs) {
const { username, token, domain } = inputs;
if (username == "") {
core.debug("Skipping login, no username provided");
return;
}
const { token, domain } = inputs;
if (token == "") {
throw new Error("No token provided");
}
core.debug(`Logging in as ${username}`);
await exec.exec(bufPath, ["registry", "login", domain, "--username", username, "--token-stdin"], {
core.debug(`Logging in to ${domain}`);
await exec.exec(bufPath, ["registry", "login", domain, "--token-stdin"], {
input: Buffer.from(token + "\n"),
});
}
Expand Down
1 change: 0 additions & 1 deletion examples/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
1 change: 0 additions & 1 deletion examples/disable-skip/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
breaking: ${{ github.event_name == 'pull_request' }}
3 changes: 1 addition & 2 deletions examples/only-setup-defaults/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
setup_only: true
- env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
BUF_USERNAME: ${{ secrets.BUF_USERNAME }}
run: echo ${BUF_TOKEN} | buf registry login buf.build --username ${BUF_USERNAME} --token-stdin
run: echo ${BUF_TOKEN} | buf registry login buf.build --token-stdin
- run: buf build --error-format=github-actions
- if: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'buf skip lint') }}
run: buf lint --error-format github-actions
Expand Down
4 changes: 2 additions & 2 deletions examples/only-setup/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
# Add username or token secrets to your repository settings to
# authenticate with the Buf Schema Registry.
# Add the parameter token as a secret in your repository settings
# to authenticate with the Buf Schema Registry.
setup_only: true
- run: buf build --error-format=github-actions
1 change: 0 additions & 1 deletion examples/only-sync/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
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 @@ -21,5 +21,4 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
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 @@ -12,7 +12,6 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
lint: |
github.event_name == 'push' && \
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 @@ -14,7 +14,6 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
username: ${{ secrets.BUF_USERNAME }}
token: ${{ secrets.BUF_TOKEN }}
lint: |
github.event_name == 'pull_request' && \
Expand Down
3 changes: 1 addition & 2 deletions examples/validate-push/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
# Username and token are required to authenticate with the Buf Schema Registry.
username: ${{ secrets.BUF_USERNAME }}
# The token paramater is required to authenticate with the Buf Schema Registry.
token: ${{ secrets.BUF_TOKEN }}
lint: ${{ github.event_name == 'push' }}
format: ${{ github.event_name == 'push' }}
Expand Down
2 changes: 0 additions & 2 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
// Inputs are the inputs to the action, matching the inputs in the action.yml.
export interface Inputs {
version: string;
username: string;
token: string;
domain: string;
setup_only: boolean;
Expand All @@ -50,7 +49,6 @@ export interface Inputs {
export function getInputs(): Inputs {
const inputs: Inputs = {
version: core.getInput("version"),
username: core.getInput("username"),
token: core.getInput("token") || getEnv("BUF_TOKEN"),
domain: core.getInput("domain"),
setup_only: core.getBooleanInput("setup_only"),
Expand Down
18 changes: 5 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,14 @@ async function runWorkflow(

// login logs in to the Buf registry, storing credentials.
async function login(bufPath: string, inputs: Inputs) {
const { username, token, domain } = inputs;
if (username == "") {
core.debug("Skipping login, no username provided");
return;
}
const { token, domain } = inputs;
if (token == "") {
throw new Error("No token provided");
}
core.debug(`Logging in as ${username}`);
await exec.exec(
bufPath,
["registry", "login", domain, "--username", username, "--token-stdin"],
{
input: Buffer.from(token + "\n"),
},
);
core.debug(`Logging in to ${domain}`);
await exec.exec(bufPath, ["registry", "login", domain, "--token-stdin"], {
input: Buffer.from(token + "\n"),
});
}

// build runs the "buf build" step.
Expand Down

0 comments on commit 8a51c13

Please sign in to comment.