Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined steps for partial workflow #5

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.32.1"
BUF_VERSION: "1.32.2"
jobs:
build:
runs-on: ubuntu-latest
Expand Down
35 changes: 10 additions & 25 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37788,7 +37788,6 @@ async function commentOnPR(context, github, comment) {

async function main() {
const inputs = getInputs();
core.debug(`inputs: ${JSON.stringify(inputs, null, 2)}`);
const github = (0,lib_github.getOctokit)(inputs.github_token);
const bufPath = await installBuf(github, inputs.version);
await login(bufPath, inputs);
Expand Down Expand Up @@ -37819,47 +37818,33 @@ async function main() {
// NB: Write empties the buffer must be after the comment.
await summary.write();
// Finally, set the status of the action.
for (const key of Object.keys(steps)) {
if (steps[key].status == Status.Failed) {
for (const [key, value] of Object.entries(steps)) {
if (value?.status == Status.Failed) {
core.setFailed(`Failed ${key}`);
}
}
}
main()
.catch((err) => core.setFailed(err.message))
.then(() => core.debug(`done in ${process.uptime()} s`));
class Steps {
build;
lint;
format;
breaking;
push;
archive;
}
// runWorkflow runs the buf workflow. It returns the results of each step.
// 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, inputs) {
const steps = new Steps();
const steps = {};
steps.build = await build(bufPath, inputs);
if (steps.build.status == Status.Failed) {
return steps;
}
const checks = await Promise.all([
lint(bufPath, inputs).then((result) => {
steps.lint = result;
return result;
}),
format(bufPath, inputs).then((result) => {
steps.format = result;
return result;
}),
breaking(bufPath, inputs).then((result) => {
steps.breaking = result;
return result;
}),
lint(bufPath, inputs),
format(bufPath, inputs),
breaking(bufPath, inputs),
]);
steps.lint = checks[0];
steps.format = checks[1];
steps.breaking = checks[2];
if (checks.some((result) => result.status == Status.Failed)) {
return steps;
}
Expand Down Expand Up @@ -37908,7 +37893,7 @@ async function build(bufPath, inputs) {
async function lint(bufPath, inputs) {
if (!inputs.lint) {
core.info("Skipping lint");
return Promise.resolve(skip());
return skip();
}
const args = ["lint", "--error-format", "github-actions"];
if (inputs.input) {
Expand Down
44 changes: 20 additions & 24 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { commentOnPR } from "./comment";

async function main() {
const inputs = getInputs();
core.debug(`inputs: ${JSON.stringify(inputs, null, 2)}`);
const github = getOctokit(inputs.github_token);
const bufPath = await installBuf(github, inputs.version);
await login(bufPath, inputs);
Expand Down Expand Up @@ -55,8 +54,11 @@ async function main() {
// NB: Write empties the buffer must be after the comment.
await summary.write();
// Finally, set the status of the action.
for (const key of Object.keys(steps)) {
if (steps[key].status == Status.Failed) {
for (const [key, value] of Object.entries(steps) as [
keyof Steps,
Result | undefined,
][]) {
if (value?.status == Status.Failed) {
core.setFailed(`Failed ${key}`);
}
}
Expand All @@ -66,39 +68,33 @@ main()
.catch((err) => core.setFailed(err.message))
.then(() => core.debug(`done in ${process.uptime()} s`));

class Steps {
build: Result;
lint: Result;
format: Result;
breaking: Result;
push: Result;
archive: Result;
interface Steps {
build?: Result;
lint?: Result;
format?: Result;
breaking?: Result;
push?: Result;
archive?: Result;
}

// runWorkflow runs the buf workflow. It returns the results of each step.
// 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: string, inputs: Inputs): Promise<Steps> {
const steps = new Steps();
const steps: Steps = {};
steps.build = await build(bufPath, inputs);
if (steps.build.status == Status.Failed) {
return steps;
}
const checks = await Promise.all([
lint(bufPath, inputs).then((result) => {
steps.lint = result;
return result;
}),
format(bufPath, inputs).then((result) => {
steps.format = result;
return result;
}),
breaking(bufPath, inputs).then((result) => {
steps.breaking = result;
return result;
}),
lint(bufPath, inputs),
format(bufPath, inputs),
breaking(bufPath, inputs),
]);
steps.lint = checks[0];
steps.format = checks[1];
steps.breaking = checks[2];
if (checks.some((result) => result.status == Status.Failed)) {
return steps;
}
Expand Down Expand Up @@ -154,7 +150,7 @@ async function build(bufPath: string, inputs: Inputs): Promise<Result> {
async function lint(bufPath: string, inputs: Inputs): Promise<Result> {
if (!inputs.lint) {
core.info("Skipping lint");
return Promise.resolve(skip());
return skip();
}
const args = ["lint", "--error-format", "github-actions"];
if (inputs.input) {
Expand Down
Loading