Skip to content

Commit

Permalink
Config cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Jun 28, 2024
1 parent 325f207 commit 49dbce6
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 182 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The default behavior of this action is the recommended workflow for a GitHub rep
### Configuration

To customize the behavior of the action, you can set the following inputs in the workflow file.
Add these inputs to the `with` section of the `uses` step in the workflow file.
Add these inputs under the `with` section of the `uses` step in the workflow file.

```yaml
Expand All @@ -76,13 +76,8 @@ Add these inputs to the `with` section of the `uses` step in the workflow file.
| `breaking` | Whether to run the breaking change detection step. | Runs on pushes to Git PR |
| `breaking_against` | Input to compare against. | Base of the pull requests or the commit before the push event |
| `push` | Whether to run the push step. | Runs on Git pushes |
| `push_create` | Create the repository if it does not exist. | True |
| `push_create_visibility` | Repository visibility setting if created. | Unset is equivelent to "private" |
| `push_labels` | Associate the labels with the pushed modules (separated by newlines). | |
| `push_git_metadta` | Set additional git metadata on push. | True |
| `push_source_control_url` | Set the source control URL for each pushed modules. | |
| `push_disable_create` | Disables repository creation if it does not exist. | False |
| `archive` | Whether to run the archive step. | Runs on Git deletes |
| `archive_labels` | Labels to archive (separated by newlines), | |


### Skipping steps
Expand Down
59 changes: 11 additions & 48 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,82 +94,45 @@ inputs:
lint:
description: |-
Whether to run the linting step.
Runs by default on pull requests if the "buf skip lint" label is not applied.
Runs by default on pull requests.
required: false
default: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'buf skip lint') }}
default: ${{ github.event_name == 'pull_request' }}

format:
description: |-
Whether to run the formatting step.
Runs by default on pull requests if the "buf skip format" label is not applied.
Runs by default on pull requests.
required: false
default: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'buf skip format') }}
default: ${{ github.event_name == 'pull_request' }}

breaking:
description: |-
Whether to run the breaking change detection step.
Runs by default on pull requests if the "buf skip breaking" label is not applied.
required: false
default: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'buf skip breaking') }}
#breaking_against:
# description: |-
# 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 }}
breaking_against:
description: |-
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

push:
description: |-
Whether to run the push step. Runs by default on pushes.
required: false
default: ${{ github.event_name == 'push' }}
push_create:
push_disable_create:
description: |-
Create the repository if it does not exist.
Disables repository creation if it does not exist.
required: false
default: "true"
push_create_visibility:
description: |-
Repository's visibility setting if created.
Must be either "public" or "private".
required: false
push_labels:
description: |-
Associates the labels with the pushed modules (separated by newlines).
Labels are added in addition to the default labels from "--git-metadata".
Example:
with:
push_labels: |
label1
label2
required: false
push_git_metadata:
description: |-
Set additional git metadata for the push using "--git-metadata".
Defaults to true.
required: false
default: "true"
push_source_control_url:
description: |-
Set the source control URL for the pushed modules.
required: false

archive:
description: |-
Whether to run the archive step. Runs by default on deletes.
required: false
default: ${{ github.event_name == 'delete' }}
archive_labels:
description: |-
Labels to archive (separated by newlines).
Example:
with:
archive_labels: |
label1
label2
required: false
default: |
${{ github.event.ref }}

outputs:
buf_version:
Expand Down
100 changes: 43 additions & 57 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45988,8 +45988,6 @@ var core = __nccwpck_require__(2186);
var exec = __nccwpck_require__(1514);
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
var lib_github = __nccwpck_require__(5438);
// EXTERNAL MODULE: ./node_modules/semver/index.js
var semver = __nccwpck_require__(1383);
;// CONCATENATED MODULE: ./node_modules/@bufbuild/protobuf/dist/esm/service-type.js
// Copyright 2021-2024 Buf Technologies, Inc.
//
Expand Down Expand Up @@ -53848,38 +53846,49 @@ const LabelService = {
// See the License for the specific language governing permissions and
// limitations under the License.


// getInputs decodes the inputs from the environment variables.
function getInputs() {
return {
console.log("CONTEXT", lib_github.context);
const inputs = {
version: core.getInput("version"),
username: core.getInput("username"),
token: core.getInput("token") || getEnv("BUF_TOKEN"),
domain: core.getInput("domain"),
github_token: core.getInput("github_token"),
setup_only: core.getBooleanInput("setup_only"),
comment: core.getBooleanInput("comment"),
pr_comment: core.getBooleanInput("pr_comment"),
// Inputs shared between buf steps.
input: core.getInput("input"),
config: core.getInput("config"),
paths: core.getMultilineInput("paths"),
exclude_paths: core.getMultilineInput("exclude_paths"),
exclude_imports: core.getBooleanInput("exclude_imports"),
// Inputs specific to buf steps.
lint: core.getBooleanInput("lint"),
format: core.getBooleanInput("format"),
breaking: core.getBooleanInput("breaking"),
breaking_against: core.getInput("breaking_against"),
breaking_against_config: core.getInput("breaking_against_config"),
breaking_limit_to_input_files: core.getBooleanInput("breaking_limit_to_input_files"),
breaking_against: "",
push: core.getBooleanInput("push"),
push_create: core.getBooleanInput("push_create"),
push_create_visibility: core.getInput("push_create_visibility"),
push_labels: core.getMultilineInput("push_labels"),
push_git_metadata: core.getBooleanInput("push_git_metadata"),
push_source_control_url: core.getInput("push_source_control_url"),
push_disable_create: core.getBooleanInput("push_disable_create"),
archive: core.getBooleanInput("archive"),
archive_labels: core.getMultilineInput("archive_labels"),
archive_labels: [],
};
if (lib_github.context.eventName === "push") {
const event = lib_github.context.payload;
core.info(`The head commit is: ${event.before}`);
inputs.breaking_against = `${event.repository.clone_url}#format=git,commit=${event.before}`;
console.log("BREAKING AGAINST", inputs.breaking_against);
}
if (lib_github.context.eventName === "pull_request") {
const event = lib_github.context.payload;
core.info(`The head commit is: ${event.pull_request.head.sha}`);
inputs.breaking_against = `${event.repository.clone_url}#format=git,commit=${event.pull_request.base.sha}`;
console.log("BREAKING AGAINST", inputs.breaking_against);
}
if (lib_github.context.eventName === "delete") {
const event = lib_github.context.payload;
inputs.archive_labels.push(event.ref);
}
return inputs;
}
// getEnv returns the case insensitive value of the environment variable.
// Prefers the lowercase version of the variable if it exists.
Expand Down Expand Up @@ -53909,6 +53918,8 @@ var Outputs;

// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js
var tool_cache = __nccwpck_require__(7784);
// EXTERNAL MODULE: ./node_modules/semver/index.js
var semver = __nccwpck_require__(1383);
;// CONCATENATED MODULE: ./src/installer.ts
// Copyright 2024 Buf Technologies, Inc.
//
Expand Down Expand Up @@ -54180,11 +54191,11 @@ function parseModuleName(moduleName) {




// main is the entrypoint for the action.
async function main() {
const inputs = getInputs();
const github = (0,lib_github.getOctokit)(inputs.github_token);
console.log("inputs", inputs);
const github = (0,lib_github.getOctokit)(core.getInput("github_token"));
const [bufPath, bufVersion] = await installBuf(github, inputs.version);
core.setOutput(Outputs.BufVersion, bufVersion);
await login(bufPath, inputs);
Expand All @@ -54193,11 +54204,11 @@ async function main() {
return;
}
// Run the buf workflow.
const steps = await runWorkflow(bufPath, bufVersion, inputs);
const steps = await runWorkflow(bufPath, inputs);
// Create a summary of the steps.
const summary = createSummary(inputs, steps);
// Comment on the PR with the summary, if requested.
if (inputs.comment) {
if (inputs.pr_comment) {
await commentOnPR(lib_github.context, github, summary.stringify());
}
// Write the summary to a file defined by GITHUB_STEP_SUMMARY.
Expand Down Expand Up @@ -54239,7 +54250,7 @@ function createSummary(inputs, steps) {
// First, it builds the input. If the build fails, the workflow stops.
// Next, it runs lint, format, and breaking checks. If any of these fail, the workflow stops.
// Finally, it pushes or archives the label to the registry.
async function runWorkflow(bufPath, bufVersion, inputs) {
async function runWorkflow(bufPath, inputs) {
const steps = {};
steps.build = await build(bufPath, inputs);
if (steps.build.status == Status.Failed) {
Expand All @@ -54257,7 +54268,7 @@ async function runWorkflow(bufPath, bufVersion, inputs) {
return steps;
}
const moduleNames = parseModuleNames(inputs.input);
steps.push = await push(bufPath, bufVersion, inputs, moduleNames);
steps.push = await push(bufPath, inputs, moduleNames);
steps.archive = await archive(inputs, moduleNames);
return steps;
}
Expand All @@ -54282,9 +54293,6 @@ async function build(bufPath, inputs) {
if (inputs.input) {
args.push(inputs.input);
}
if (inputs.config != "") {
args.push("--config", inputs.config);
}
for (const path of inputs.paths) {
args.push("--path", path);
}
Expand All @@ -54306,9 +54314,6 @@ async function lint(bufPath, inputs) {
if (inputs.input) {
args.push(inputs.input);
}
if (inputs.config != "") {
args.push("--config", inputs.config);
}
for (const path of inputs.paths) {
args.push("--path", path);
}
Expand All @@ -54333,9 +54338,6 @@ async function format(bufPath, inputs) {
if (inputs.input) {
args.push(inputs.input);
}
if (inputs.config) {
args.push("--config", inputs.config);
}
for (const path of inputs.paths) {
args.push("--path", path);
}
Expand All @@ -54360,12 +54362,6 @@ async function breaking(bufPath, inputs) {
if (inputs.input) {
args.push(inputs.input);
}
if (inputs.breaking_against_config) {
args.push("--against-config", inputs.breaking_against_config);
}
if (inputs.config) {
args.push("--config", inputs.config);
}
for (const path of inputs.paths) {
args.push("--path", path);
}
Expand All @@ -54378,7 +54374,7 @@ async function breaking(bufPath, inputs) {
return run(bufPath, args);
}
// push runs the "buf push" step.
async function push(bufPath, bufVersion, inputs, moduleNames) {
async function push(bufPath, inputs, moduleNames) {
if (!inputs.push) {
core.info("Skipping push");
return skip();
Expand All @@ -54387,29 +54383,19 @@ async function push(bufPath, bufVersion, inputs, moduleNames) {
core.info("Skipping push, no named modules detected");
return skip();
}
const args = ["push", "--error-format", "github-actions"];
// Add --exclude-unnamed on buf versions that support the flag.
if (semver.satisfies(bufVersion, ">=1.33.0")) {
args.push("--exclude-unnamed");
}
const args = [
"push",
"--error-format",
"github-actions",
"--exclude-unnamed",
"--create",
"--create-visibility",
"private",
"--git-metadata",
];
if (inputs.input) {
args.push(inputs.input);
}
if (inputs.push_create) {
args.push("--create");
if (inputs.push_create_visibility) {
args.push("--create-visibility", inputs.push_create_visibility);
}
}
if (inputs.push_git_metadata) {
args.push("--git-metadata");
}
if (inputs.push_source_control_url) {
args.push("--source-control-url", inputs.push_source_control_url);
}
for (const label of inputs.push_labels) {
args.push("--label", label);
}
return run(bufPath, args);
}
// archive runs the "buf archive" step.
Expand Down
Loading

0 comments on commit 49dbce6

Please sign in to comment.