Skip to content

Commit

Permalink
feat: initial implementation (#1)
Browse files Browse the repository at this point in the history
This is the initial implementation of Schemar.
  • Loading branch information
johnnyreilly authored Jan 2, 2024
1 parent 2b12e80 commit a3e8624
Show file tree
Hide file tree
Showing 41 changed files with 41,146 additions and 160 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INPUT_URLS="https://johnnyreilly.com" # will pass
# INPUT_URLS="https://news.ycombinator.com/" # will fail
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
!.*
lib
dist
node_modules
pnpm-lock.yaml
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
{ enforceForIfStatements: true },
],
"operator-assignment": "error",
"@typescript-eslint/consistent-type-imports": "error",
},
},
{
Expand Down
5 changes: 4 additions & 1 deletion .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ name: Prepare
runs:
steps:
- uses: pnpm/action-setup@v2

- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: "18"
node-version: "20"

- run: pnpm install --frozen-lockfile
shell: bash

using: composite
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm build
- run: node ./lib/index.js
- run: pnpm build:release

name: Build

Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# In TypeScript actions, `dist/` is a special directory. When you reference
# an action with the `uses:` property, `dist/index.js` is the code that will be
# run. For this project, the `dist/index.js` file is transpiled from other
# source files. This workflow ensures the `dist/` directory contains the
# expected transpiled code.
#
# If this workflow is run from a feature branch, it will act as an additional CI
# check and fail if the checked-in `dist/` directory does not match what is
# expected from the build.
name: Check transpiled JavaScript in dist is up to date

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
check-dist:
name: check dist
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare

- name: Build dist directory
id: build
run: pnpm run build:release

# This will fail the workflow if the PR wasn't created by Dependabot.
- name: Compare directories
id: diff
run: |
if [ "$(git diff --ignore-space-at-eol --text dist/index.js | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build."
echo "You may need to run 'pnpm run build:release' locally and commit the changes."
echo ""
echo "See diff below:"
echo ""
git diff --ignore-space-at-eol --text dist/index.js
echo ""
# say this again in case the diff is long
echo "You may need to run 'pnpm run build:release' locally and commit the changes."
echo ""
exit 1
fi
# If `dist/` was different than expected, and this was not a Dependabot
# PR, upload the expected version as a workflow artifact.
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
name: Upload artifact
id: upload
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm run test

- name: Test local action
id: test-action
uses: ./
with:
urls: https://johnnyreilly.com

name: Test

on:
pull_request: ~
push:
branches:
- main
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
pnpm run build:release
git add dist
npx lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/
dist/
pnpm-lock.yaml
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Action",
"skipFiles": ["<node_internals>/**"],
"program": "lib/index.js",
"preLaunchTask": "build:debug",
"envFile": "${workspaceFolder}/.env"
}
]
}
11 changes: 11 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build:debug",
"label": "build:debug",
"detail": "Build the project for debugging"
}
]
}
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,51 @@
<a href="https://github.com/johnnyreilly/schemar/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/johnnyreilly/schemar?color=21bb42"></a>
<img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />
<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />
<img alt="npm package version" src="https://img.shields.io/npm/v/schemar?color=21bb42" />
</p>

## Usage

This action works by:

1. Checking the supplied URL features structured data using the [Schema.org validator](https://validator.schema.org/)
2. If no structured data is found, the action fails. It also fails if the structured data is invalid.

```yml
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: johnnyreilly/[email protected]
with:
urls: https://johnnyreilly.com

name: Validate structured data

on:
pull_request: ~
push:
branches:
- main
```
## Development
To develop this GitHub Action, you'll need Node.js 20 and pnpm. Then install the dependencies:
```shell
npm i schemar
pnpm i
```

```ts
import { greet } from "schemar";
To run the action locally you can either use the `debug` script:

greet("Hello, world! 💖");
```shell
pnpm run debug
```

Or debug in VS Code using the `Debug Action` launch configuration.

Whichever you use, you configure inputs using the [.env](./.env) file.

<!-- You can remove this notice if you don't want it 🙂 no worries! -->

> 💙 This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app).
26 changes: 26 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Schemar"
description: "Validate structured data on a website"
author: "johnnyreilly"

# Add your action's branding here. This will appear on the GitHub Marketplace.
branding:
icon: "check-square"
color: "green"

# Define your inputs here.
inputs:
urls:
description: "List of URL(s) to analyze"
required: true

# Define your outputs here.
outputs:
results:
description: "An array of the results: Result[]"

processedValidationResult:
description: "The processed validation result"

runs:
using: node20
main: dist/index.js
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./validationResult.js";
1 change: 1 addition & 0 deletions dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a3e8624

Please sign in to comment.