Skip to content

Commit

Permalink
Drop username config (#55)
Browse files Browse the repository at this point in the history
No longer required by `buf` as of `v1.35.0`, requires version
restriction.
  • Loading branch information
emcfarlane authored Jul 29, 2024
1 parent 34dff83 commit 4b64761
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .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.34.0"
BUF_VERSION: "1.35.0"
BUF_MODULE: ${{ vars.BUF_MODULE }}
jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL := bash
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BUF_VERSION ?= 1.34.0
BUF_VERSION ?= 1.35.0

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
Expand Down
12 changes: 3 additions & 9 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 @@ -117,7 +115,7 @@ For reproducible builds, you can pin to an explicit version of `buf` by setting
```yaml
- uses: bufbuild/[email protected]
with:
version: 1.34.0
version: 1.35.0
```

If no version is specified in the workflow config, the action will resolve the version in order of precedence:
Expand All @@ -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
6 changes: 1 addition & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ inputs:
Version of the Buf CLI to use.
Example:
with:
version: 1.34.0
required: false
username:
description: |-
Username for logging into the BSR.
version: 1.35.0
required: false
token:
description: |-
Expand Down
16 changes: 6 additions & 10 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 @@ -45489,7 +45488,7 @@ var semver = __nccwpck_require__(1383);


// requiredVersion is the minimum version of buf required.
const requiredVersion = ">=1.34.0";
const requiredVersion = ">=1.35.0";
// installBuf installs the buf binary and returns the path to the binary. The
// versionInput should be an explicit version of buf.
async function installBuf(github, versionInput) {
Expand Down Expand Up @@ -45848,16 +45847,13 @@ 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("Skipping login, no token provided");
return;
}
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: 1 addition & 1 deletion examples/version-input/buf-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
- uses: bufbuild/[email protected]
with:
setup_only: true
version: 1.34.0
version: 1.35.0
- run: buf version
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
2 changes: 1 addition & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as semver from "semver";
import { getEnv } from "./inputs";

// requiredVersion is the minimum version of buf required.
const requiredVersion = ">=1.34.0";
const requiredVersion = ">=1.35.0";

// installBuf installs the buf binary and returns the path to the binary. The
// versionInput should be an explicit version of buf.
Expand Down
21 changes: 7 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,15 @@ 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");
const { token, domain } = inputs;
if (token == "") {
core.debug("Skipping login, no token provided");
return;
}
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 4b64761

Please sign in to comment.