Skip to content

Commit

Permalink
Merge branch 'stoplightio:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
w3nl committed Apr 19, 2024
2 parents e7f27ff + 300ac00 commit 957d061
Show file tree
Hide file tree
Showing 15 changed files with 473 additions and 299 deletions.
125 changes: 111 additions & 14 deletions .circleci/config.yml
@@ -1,12 +1,12 @@
version: 2.1

orbs:
windows: circleci/windows@2.4.1
windows: circleci/windows@5.0

executors:
linux:
docker:
- image: cimg/base:2021.07
- image: cimg/base:2024.01

defaults:
default-branch: &default-branch develop
Expand All @@ -23,9 +23,10 @@ defaults:
- "12.22"
- "14.21"
- &node-maintenance-lts "16.20"
- &node-active-lts "18.17"
- &node-active-lts "18.18"
- &node-current "20.5"
pkg-cache-path: &pkg-cache-path /tmp/pkg-node-binaries
ldid-version: &ldid-version 2.1.5-procursus7 # https://github.com/ProcursusTeam/ldid

commands:
compute-hashes:
Expand All @@ -37,11 +38,26 @@ commands:
git rev-parse HEAD > /tmp/current-commit-sha
cached-dependencies:
parameters:
install-corepack:
type: boolean
default: false
steps:
- restore_cache:
name: Restore Yarn Package Cache
keys:
- &yarn-cache-key yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
- when:
condition:
equal:
- true
- << parameters.install-corepack >>
steps:
- run:
name: Enable Corepack
command: |
npm install -g corepack
corepack enable
- run:
name: Install Dependencies
command: yarn install --immutable
Expand All @@ -64,12 +80,54 @@ commands:
parameters:
targets:
type: string
node-version:
type: string
default: *node-active-lts
bytecode:
type: boolean
default: true
steps:
- run:
name: Create the Spectral Binary
environment:
PKG_CACHE_PATH: *pkg-cache-path
command: yarn workspace @stoplight/spectral-cli pkg . --public --targets << parameters.targets >> --output binaries/spectral
- restore_cache:
name: Restore pkg cache
keys:
- &pkg-cache-key pkg-cache-<< parameters.targets >>-<< parameters.node-version >>
- when:
condition: &is-windows
equal:
- windows
- << parameters.targets >>
steps:
- run:
name: Create the Spectral Binary
environment:
PKG_CACHE_PATH: *pkg-cache-path
command: |
yarn workspace @stoplight/spectral-cli pkg . --public --public-packages "*" --targets node<< parameters.node-version >>-windows --output binaries/spectral
- unless:
condition: *is-windows
steps:
- run:
name: Create the Spectral Binary
environment:
PKG_CACHE_PATH: *pkg-cache-path
command: |
NODE_VERSION=$(echo "<< parameters.node-version >>" | awk -F "." '{ print $1 }')
TARGETS=$(echo "<< parameters.targets >>" | awk -v node_version="$NODE_VERSION" -F "," '{for (i=1;i<=NF;i++) printf "node" node_version "-" $i "," }' | sed "s/,$/\n/")
export ARCH=$(echo << parameters.targets >> | awk 'match($0, /-(arm64|x64)/){ print substr($0, RSTART+1, RLENGTH-1) }')
if [ "<< parameters.bytecode >>" = true ]
then
yarn workspace @stoplight/spectral-cli pkg . --public --public-packages "*" --targets $TARGETS --output binaries/spectral
else
yarn workspace @stoplight/spectral-cli pkg . --no-bytecode --public --public-packages "*" --targets $TARGETS --output binaries/spectral
fi

(cd packages/cli/binaries && ls . | sed -n -E 's/^(spectral)-(alpine|linux|macos)$/mv "\1-\2" "\1-\2"-$ARCH/p' | sh)
- save_cache:
name: Retain pkg cache
key: *pkg-cache-key
paths:
- *pkg-cache-path

install-and-build:
description: >-
Expand All @@ -78,6 +136,39 @@ commands:
- cached-dependencies
- build

install-ldid:
description: Install ldid
parameters:
version:
type: string
default: *ldid-version
steps:
- restore_cache:
name: Restore built ldid binary
keys:
- ldid-binary-<< parameters.version >>-{{ arch }}
- run:
name: Build ldid
working_directory: /tmp
command: |
sudo apt-get update -y
sudo apt-get -y install libplist-dev
if [ ! -d ldid ]
then
curl -L https://github.com/ProcursusTeam/ldid/archive/refs/tags/v<< parameters.version >>.tar.gz | tar -xz
mv ldid-<< parameters.version >> ldid
make -C ldid
fi
- save_cache:
name: Retain ldid binary
key: ldid-binary-<< parameters.version >>-{{ arch }}
paths:
- /tmp/ldid
- run:
name: Install ldid
working_directory: /tmp/ldid
command: make install

lint-code:
steps:
- run:
Expand Down Expand Up @@ -130,6 +221,7 @@ commands:
- test-harness-{{ checksum "/tmp/previous-commit-sha" }}-<< parameters.os >>-<< parameters.node-version >>
- build-binary:
targets: << parameters.os >>
node-version: << parameters.node-version >>
- run:
name: Run harness tests
command: yarn test.harness --maxWorkers=<< parameters.max-workers >>
Expand All @@ -138,7 +230,6 @@ commands:
key: test-harness-{{ checksum "/tmp/current-commit-sha" }}-<< parameters.os >>-<< parameters.node-version >>
paths:
- ./.cache/spectral-test-harness
- *pkg-cache-path
- ./test-harness/tests/
when: always

Expand Down Expand Up @@ -203,23 +294,28 @@ jobs:
name: windows/default
steps:
- checkout
- cached-dependencies
- cached-dependencies:
install-corepack: true
- build
- test-node:
max-workers: 3
- test-harness:
os: windows
node-version: current
max-workers: 3
node-version: *node-active-lts
max-workers: 2

build-nix-binaries:
docker:
- image: cimg/node:lts
steps:
- checkout
- install-ldid
- install-and-build
- build-binary:
targets: linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64
targets: linux-x64,macos-x64,alpine-x64
- build-binary:
targets: macos-arm64,linux-arm64,alpine-arm64
bytecode: false
- persist_to_workspace:
root: ./packages/cli/
paths:
Expand All @@ -230,7 +326,8 @@ jobs:
name: windows/default
steps:
- checkout
- cached-dependencies
- cached-dependencies:
install-corepack: true
- run: yarn build
- build-binary:
targets: windows
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/jira-issue-label-added.yaml
@@ -0,0 +1,13 @@
name: Jira Issue Label Added

on:
issues:
types:
- labeled

jobs:
call-workflow:
uses: stoplightio/.github/.github/workflows/jira-issue-label-added.yaml@master
with:
team-name: ${{ contains(github.event.pull_request.labels.*.name, 'team/bear-claws') && 'Bear Claws' || contains(github.event.pull_request.labels.*.name, 'team/honey-hackers') && 'Honey Hackers' || '' }}
secrets: inherit
27 changes: 24 additions & 3 deletions docs/guides/2-cli.md
Expand Up @@ -31,9 +31,9 @@ Other options include:
--help Show help [boolean]
-e, --encoding text encoding to use
[string] [choices: "utf8", "ascii", "utf-8", "utf16le", "ucs2", "ucs-2", "base64", "latin1"] [default: "utf8"]
-f, --format formatters to use for outputting results, more than one can be given joining them with
a comma
[string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"]
-f, --format formatters to use for outputting results, more than one can be provided by using
multiple flags
[string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"]
[default: "stylish"]
-o, --output where to output results, can be a single file name, multiple "output.<format>" or
missing to print to stdout [string]
Expand Down Expand Up @@ -176,6 +176,27 @@ title: Example

<!-- type: tab-end -->

### Multiple formatters

If you wish to output results in multiple formats, you can do so by passing multiple `-f` flags.
In order to output results in multiple formats, you must also pass the `-o` flag with a filename for each format.

```bash
spectral lint "specs/**/*.yaml" -f json -f junit -o.json results.json -o.junit junit.xml
```

You can also pipe an output to stdout.

```bash
spectral lint "specs/**/*.yaml" -f stylish -f junit -o.junit junit.xml -o.stylish "<stdout>"
```

It's possible to output each format to stdout.

```bash
spectral lint "specs/**/*.yaml" -f text -f stylish -o.text "<stdout>" -o.stylish "<stdout>"
```

## Proxying

To have requests made from Spectral be proxied through a server, you'd need to specify the `PROXY` environment variable:
Expand Down
14 changes: 12 additions & 2 deletions docs/reference/functions.md
Expand Up @@ -94,16 +94,26 @@ Regular expressions!
| match | if provided, value must match this regex | `string` | no |
| notMatch | if provided, value must _not_ match this regex | `string` | no |

The regex pattern provided can be just the pattern itself (e.g.: `"[a-z]"`) or you can include start/end delimiters if you would like to use regex modifiers like `/i` (e.g.: `"/[a-z]/i"`).

<!-- title: example -->

```yaml
no-x-headers:
message: "Header {{property}} should not start with `X-`."
given: "$..parameters[?(@.in === 'header')].name"
then:
function: pattern
functionOptions:
notMatch: "/^x-/i"

path-no-trailing-slash:
description: Paths should not end with `#/`.
description: "Paths should not end with `/`."
given: "$.paths[*]~"
then:
function: pattern
functionOptions:
notMatch: ".+\/$"
notMatch: "\/$"
```

## casing
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
@@ -1,3 +1,10 @@
## @stoplight/spectral-cli [6.11.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-6.11.0...@stoplight/spectral-cli-6.11.1) (2024-04-04)


### Bug Fixes

* **cli:** clarify usage of --format ([#2575](https://github.com/stoplightio/spectral/issues/2575)) ([96eee89](https://github.com/stoplightio/spectral/commit/96eee89d3210931b8ffeffe44c44d7e9f610c0b0))

# @stoplight/spectral-cli [6.11.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-6.10.1...@stoplight/spectral-cli-6.11.0) (2023-09-15)


Expand Down
9 changes: 4 additions & 5 deletions packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-cli",
"version": "6.11.0",
"version": "6.11.1",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <support@stoplight.io>",
Expand Down Expand Up @@ -53,21 +53,20 @@
"pony-cause": "^1.0.0",
"stacktracey": "^2.1.7",
"tslib": "^2.3.0",
"yargs": "17.3.1"
"yargs": "~17.7.2"
},
"devDependencies": {
"@types/es-aggregate-error": "^1.0.2",
"@types/xml2js": "^0.4.9",
"@types/yargs": "^17.0.8",
"@yao-pkg/pkg": "^5.11.1",
"es-aggregate-error": "^1.0.7",
"nock": "^13.1.3",
"pkg": "^5.8.0",
"xml2js": "^0.5.0"
},
"pkg": {
"scripts": [
"./dist/**/*.js",
"../../node_modules/vm2/lib/*.js"
"./dist/**/*.js"
],
"assets": [
"./dist/**/*.json",
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/lint.ts
Expand Up @@ -42,7 +42,7 @@ const lintCommand: CommandModule = {
},
})
.middleware((argv: Dictionary<unknown>) => {
const formats = argv.format as string[] & { 0: string };
const formats = argv.format as [string, ...string[]];
if (argv.output === void 0) {
argv.output = { [formats[0]]: '<stdout>' };
} else if (typeof argv.output === 'string') {
Expand Down Expand Up @@ -101,7 +101,8 @@ const lintCommand: CommandModule = {
},
format: {
alias: 'f',
description: 'formatters to use for outputting results, more than one can be given joining them with a comma',
description:
'formatters to use for outputting results, more than one can be provided by using multiple flags',
choices: formatOptions,
default: OutputFormat.STYLISH,
type: 'string',
Expand Down
7 changes: 7 additions & 0 deletions packages/parsers/CHANGELOG.md
@@ -1,3 +1,10 @@
## @stoplight/spectral-parsers [1.0.4](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-parsers-1.0.3...@stoplight/spectral-parsers-1.0.4) (2024-04-04)


### Bug Fixes

* **parsers:** update @stoplight/yaml from ~4.2.3 to ~4.3.0 ([91fdded](https://github.com/stoplightio/spectral/commit/91fdded2fcb25880f4ec40091d7d8137f9b64504))

## @stoplight/spectral-parsers [1.0.3](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-parsers-v1.0.2...@stoplight/spectral-parsers-1.0.3) (2023-07-14)


Expand Down
6 changes: 3 additions & 3 deletions packages/parsers/package.json
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-parsers",
"version": "1.0.3",
"version": "1.0.4",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <support@stoplight.io>",
Expand All @@ -19,8 +19,8 @@
},
"dependencies": {
"@stoplight/json": "~3.21.0",
"@stoplight/types": "^13.6.0",
"@stoplight/yaml": "~4.2.3",
"@stoplight/types": "^14.1.1",
"@stoplight/yaml": "~4.3.0",
"tslib": "^2.3.1"
}
}

0 comments on commit 957d061

Please sign in to comment.