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

Adding prettier command and running it for the first time #7893

Merged
merged 1 commit into from
Oct 18, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
94 changes: 47 additions & 47 deletions .devcontainer/contributor/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
{
"name": "Radius - Contributor",
// For details see https://github.com/radius-project/radius/tree/main/docs/contributing/contributing-code/contributing-code-prerequisites
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
//Git and GitHub Setup
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
//Programming languages
"ghcr.io/devcontainers/features/go:1": {},
"ghcr.io/guiyomh/features/gotestsum:0.1.1": {},
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers-contrib/features/typescript:2": {},
"ghcr.io/devcontainers/features/python:1": {},
//Container and K8s
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
"minikube": "none"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"moby": true
},
//Tools
"ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {},
"ghcr.io/mpriscella/features/kind:1": {},
"ghcr.io/dhoeric/features/stern:1": {},
//Dapr
"ghcr.io/dapr/cli/dapr-cli:0": {}
"name": "Radius - Contributor",
// For details see https://github.com/radius-project/radius/tree/main/docs/contributing/contributing-code/contributing-code-prerequisites
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
//Git and GitHub Setup
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
//Programming languages
"ghcr.io/devcontainers/features/go:1": {},
"ghcr.io/guiyomh/features/gotestsum:0.1.1": {},
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers-contrib/features/typescript:2": {},
"ghcr.io/devcontainers/features/python:1": {},
//Container and K8s
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
"minikube": "none"
},
"customizations": {
"vscode": {
"extensions": [
"redhat.vscode-yaml",
"golang.go",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-bicep",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-dapr",
"ms-vscode.makefile-tools"
]
}
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"moby": true
},
// Prerequisite for Code Generation, see https://github.com/radius-project/radius/tree/main/docs/contributing/contributing-code/contributing-code-prerequisites#code-generation
// Adding workspace as safe directory to avoid permission issues
"postCreateCommand": "git config --global --add safe.directory /workspaces/radius && cd typespec && npm ci && npm install -g autorest && npm install -g oav && go install sigs.k8s.io/controller-tools/cmd/[email protected] && go install go.uber.org/mock/[email protected]",
"hostRequirements": {
"memory": "8gb"
},
}
//Tools
"ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {},
"ghcr.io/mpriscella/features/kind:1": {},
"ghcr.io/dhoeric/features/stern:1": {},
//Dapr
"ghcr.io/dapr/cli/dapr-cli:0": {}
},
"customizations": {
"vscode": {
"extensions": [
"redhat.vscode-yaml",
"golang.go",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-bicep",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-dapr",
"ms-vscode.makefile-tools"
]
}
},
// Prerequisite for Code Generation, see https://github.com/radius-project/radius/tree/main/docs/contributing/contributing-code/contributing-code-prerequisites#code-generation
// Adding workspace as safe directory to avoid permission issues
"postCreateCommand": "git config --global --add safe.directory /workspaces/radius && cd typespec && npm ci && npm install -g autorest && npm install -g oav && go install sigs.k8s.io/controller-tools/cmd/[email protected] && go install go.uber.org/mock/[email protected]",
"hostRequirements": {
"memory": "8gb"
}
}
87 changes: 48 additions & 39 deletions .github/scripts/radius-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,44 @@ limitations under the License.
*/

module.exports = async ({ github, context }) => {
if (context.eventName === 'issue_comment' && context.payload.action === 'created') {
try {
await handleIssueCommentCreate({ github, context });
} catch (error) {
console.log(`[handleIssueCommentCreate] unexpected error: ${error}`);
}
if (
context.eventName === "issue_comment" &&
context.payload.action === "created"
) {
try {
await handleIssueCommentCreate({ github, context });
} catch (error) {
console.log(`[handleIssueCommentCreate] unexpected error: ${error}`);
}
}
}
};

// Handle issue comment create event.
async function handleIssueCommentCreate({ github, context }) {
const payload = context.payload;
const issue = context.issue;
const isFromPulls = !!payload.issue.pull_request;
const commentBody = payload.comment.body;
const username = context.actor;
const payload = context.payload;
const issue = context.issue;
const isFromPulls = !!payload.issue.pull_request;
const commentBody = payload.comment.body;
const username = context.actor;

if (!commentBody) {
console.log('[handleIssueCommentCreate] comment body not found, exiting.');
return;
}
if (!commentBody) {
console.log("[handleIssueCommentCreate] comment body not found, exiting.");
return;
}

const commandParts = commentBody.split(/\s+/);
const command = commandParts.shift();
const commandParts = commentBody.split(/\s+/);
const command = commandParts.shift();

switch (command) {
case '/assign':
await cmdAssign(github, issue, isFromPulls, username);
break;
default:
console.log(`[handleIssueCommentCreate] command ${command} not found, exiting.`);
break;
}
switch (command) {
case "/assign":
await cmdAssign(github, issue, isFromPulls, username);
break;
default:
console.log(
`[handleIssueCommentCreate] command ${command} not found, exiting.`,
);
break;
}
}

/**
Expand All @@ -58,18 +63,22 @@ async function handleIssueCommentCreate({ github, context }) {
* @param {*} username is the user who trigger the command
*/
async function cmdAssign(github, issue, isFromPulls, username) {
if (isFromPulls) {
console.log('[cmdAssign] pull requests not supported, skipping command execution.');
return;
} else if (issue.assignees && issue.assignees.length !== 0) {
console.log('[cmdAssign] issue already has assignees, skipping command execution.');
return;
}
if (isFromPulls) {
console.log(
"[cmdAssign] pull requests not supported, skipping command execution.",
);
return;
} else if (issue.assignees && issue.assignees.length !== 0) {
console.log(
"[cmdAssign] issue already has assignees, skipping command execution.",
);
return;
}

await github.rest.issues.addAssignees({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number,
assignees: [username],
});
await github.rest.issues.addAssignees({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number,
assignees: [username],
});
}
22 changes: 21 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "22"
- name: Install TypeSpec compiler
run: |
pushd typespec
Expand Down Expand Up @@ -91,3 +91,23 @@ jobs:
run: |
echo "Generated code is not up to date, run 'make generate' to update generated code."
exit 1
format-check:
name: Format check with Prettier
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Run `make format-check`
id: format-check
run: |
make format-check
- name: Check for formatting failures
if: steps.format-check.outcome == 'failure'
run: |
echo "Format check failed. Please fix the formatting issues. You can run 'make format-write' to update the code."
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍

8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# .prettierignore
pkg/validator/testdata/put-environments-invalid-json.json

hack/bicep-types-radius/generated/*

bicep-types/*

swagger/*
ytimocin marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Contributing

Radius is in an early phase of development right now. We welcome feedback in the form of issues that comes from usage and is aligned with the current scope and goals of the project.
Radius is in an early phase of development right now. We welcome feedback in the form of issues that comes from usage and is aligned with the current scope and goals of the project.

## Table of contents

You can find our full **contributor documentation** including instructions at the following links:

- [How to contribute](./docs/contributing/how-to.md)
- [See "good first issues"](https://github.com/radius-project/radius/issues?q=is:issue+is:open+label:%22good+first+issue%22)
- [See "good first issues"](https://github.com/radius-project/radius/issues?q=is:issue+is:open+label:%22good+first+issue%22)
- [Install prerequisites](./docs/contributing/contributing-code/contributing-code-prerequisites/)
- [Create your first commit (full walkthrough)](./docs/contributing/contributing-code/contributing-code-first-commit/)
- [Building the repo](./docs/contributing/contributing-code/contributing-code-building/)
Expand All @@ -21,7 +21,7 @@ You can find our full **contributor documentation** including instructions at th

We welcome small pull request contributions from anyone (docs improvements, bug fixes, minor features.) as long as they follow a few guidelines:

- For very minor changes like correcting a typo feel free to send a pull request. Otherwise ...
- For very minor changes like correcting a typo feel free to send a pull request. Otherwise ...
- Please start by [choosing an existing issue](https://github.com/radius-project/radius/issues), or [opening an issue](https://github.com/radius-project/radius/issues/new/choose) to work on.
- The maintainers will respond to your issue, please work with the maintainers to ensure that what you're doing is in scope for the project before writing any code.
- If you have any doubt whether a contribution would be valuable, feel free to ask.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
ARROW := \033[34;1m=>\033[0m

# order matters for these
include build/help.mk build/version.mk build/build.mk build/util.mk build/generate.mk build/test.mk build/docker.mk build/recipes.mk build/install.mk build/db.mk build/debug.mk
include build/help.mk build/version.mk build/build.mk build/util.mk build/generate.mk build/test.mk build/docker.mk build/recipes.mk build/install.mk build/db.mk build/prettier.mk build/debug.mk
29 changes: 29 additions & 0 deletions build/prettier.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ------------------------------------------------------------
# Copyright 2023 The Radius Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------

.PHONY: prettier-check prettier-format me prettier

PRETTIER_VERSION := 3.3.3

format-check:
@echo "$(ARROW) Checking for formatting issues using prettier..."
@echo ""
@npx prettier@$(PRETTIER_VERSION) --check "*/**/*.{ts,js,mjs,json}"

format-write:
@echo "$(ARROW) Reformatting files using prettier..."
@echo ""
@npx prettier@$(PRETTIER_VERSION) --write "*/**/*.{ts,js,mjs,json}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the experience like if node is not installed? What about when it's an ancient version of node?

35 changes: 16 additions & 19 deletions deploy/devcontainer-feature/src/radcli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{
"name": "Radius CLI",
"id": "radcli",
"version": "0.1.0",
"dependsOn": {
"ghcr.io/dhoeric/features/oras:1": {}
},
"description": "Installs the Radius CLI along with needed dependencies.",
"documentationURL": "https://docs.radapp.io/installation/",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"edge"
],
"default": "latest",
"description": "Select or enter an Radius CLI version. Use 'latest' for the latest stable version, 'edge' for the latest development version, or a specific version number (e.g. 0.28.0)."
}
"name": "Radius CLI",
"id": "radcli",
"version": "0.1.0",
"dependsOn": {
"ghcr.io/dhoeric/features/oras:1": {}
},
"description": "Installs the Radius CLI along with needed dependencies.",
"documentationURL": "https://docs.radapp.io/installation/",
"options": {
"version": {
"type": "string",
"proposals": ["latest", "edge"],
"default": "latest",
"description": "Select or enter an Radius CLI version. Use 'latest' for the latest stable version, 'edge' for the latest development version, or a specific version number (e.g. 0.28.0)."
}
}
}
}
32 changes: 16 additions & 16 deletions deploy/devcontainer-feature/test/radcli/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"edge": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"radcli": {
"version": "edge"
}
}
},
"version": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"radcli": {
"version": "0.27.0"
}
}
"edge": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"radcli": {
"version": "edge"
}
}
}
},
"version": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"radcli": {
"version": "0.27.0"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ You can build the repository with `make build`. This will build all of the packa
The following command will build, run unit tests, and run linters. This command is handy for verifying that your local changes are working correctly.

```sh
make build test lint
make build test lint format-check
```

You should also run `make format-write` if you have errors in the `format-check` command that you ran above or have added new or changed existing TS, JS, MJS, and/or JSON files.

```sh
make format-write
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be less clever about the name?

I think this guidance should be combined with line 14. The idea is that we're giving contributors simple advice. Saying "run make format build test lint" is simpler than saying "run make build test lint and then run make prettier".


- See further information about tests [here](../contributing-code-tests/).
Expand Down
Loading