Skip to content

Commit

Permalink
Update dependencies and CI workflow (#13)
Browse files Browse the repository at this point in the history
* Update dependencies and ci workflow

* Update apollo cli version
  • Loading branch information
iansu committed Aug 18, 2021
1 parent 3623145 commit e3f0602
Show file tree
Hide file tree
Showing 13 changed files with 2,314 additions and 1,925 deletions.
23 changes: 2 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@ jobs:
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 12
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache node modules
uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
cache: yarn
- name: Install
run: yarn --prefer-offline --frozen-lockfile --no-progress --non-interactive
- name: Lint
Expand All @@ -29,16 +20,6 @@ jobs:
run: yarn build
- name: Test
run: yarn test --coverage
- name: Commit build
if: github.ref == 'refs/heads/master'
uses: endbug/add-and-commit@v4
with:
add: 'build'
force: true
message: 'Add build output'
ref: 'v1'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Apollo Schema Check Action Changelog

## 1.1.0 (August 18, 2021)

- Add `apolloVersion` setting to specify Apollo CLI version
- Update dependencies

## 1.0.0 (July 6, 2020)

Initial release! :tada:
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
When you create a new PR that includes schema changes the results of the schema check will be posted as a comment. Here's an example of what that looks like:
![Screenshot](./screenshot.png)
Note that you won't see a comment if your PR doesn't include any schema changes.
## Settings
Almost all of the settings from the [Apollo CLI `schema:check` command](https://github.com/apollographql/apollo-tooling/tree/master/packages/apollo#apollo-servicecheck) are supported, with the following differences:
Expand Down
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ inputs:
required: false
validationPeriod:
description: 'The size of the time window with which to validate the schema against. You may provide a number (in seconds), or an ISO8601 format duration for more granularity (see: https://en.wikipedia.org/wiki/ISO_8601#Durations)'
required: true
title:
description: The name of the graph which will be shown in the comment
required: false
alwaysComment:
description: Leave a comment on the PR even if there are no schema changes in the PR
default: false
default: 'false'
required: false
failOnError:
description: Fail the check if breaking changes or composition errors are found
default: true
default: 'true'
required: false
apolloVersion:
description: The version of the Apollo CLI to use
default: '2.33.6'
required: false

runs:
Expand Down
46 changes: 24 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "apollo-schema-check-action",
"description": "A GitHub Action to run a schema check and post the results as a comment on a Pull Request",
"version": "1.0.0",
"version": "1.1.0",
"author": "Ian Sutherland <ian@iansutherland.ca>",
"license": "MIT",
"repository": {
Expand All @@ -21,7 +21,9 @@
"clean:modules": "rimraf node_modules",
"lint": "eslint \"**/*.{ts,js}\"",
"format": "prettier --write **/*.ts",
"format:check": "prettier --check **/*.ts"
"format:check": "prettier --check **/*.ts",
"precommit": "lint-staged",
"prepare": "husky install"
},
"keywords": [
"actions",
Expand All @@ -47,26 +49,26 @@
]
},
"devDependencies": {
"@actions/core": "^1.2.4",
"@actions/github": "^4.0.0",
"@octokit/action": "^3.0.1",
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.4",
"@types/jest-when": "^2.7.1",
"@types/node": "^14.0.23",
"@zeit/ncc": "^0.22.3",
"debug": "^4.1.1",
"eslint": "^6.8.0",
"eslint-config-neo": "^0.5.2",
"execa": "^4.0.3",
"husky": "^4.2.5",
"jest": "^26.1.0",
"jest-when": "^2.7.2",
"lint-staged": "^10.2.11",
"prettier": "^1.19.1",
"@actions/core": "^1.4.0",
"@actions/github": "^5.0.0",
"@octokit/action": "^3.15.0",
"@types/debug": "^4.1.7",
"@types/jest": "^27.0.1",
"@types/jest-when": "^2.7.3",
"@types/node": "^16.6.1",
"@vercel/ncc": "0.29.0",
"debug": "^4.3.2",
"eslint": "^7.32.0",
"eslint-config-neo": "^0.6.2",
"execa": "^5.1.1",
"husky": "^7.0.1",
"jest": "^27.0.6",
"jest-when": "^3.3.1",
"lint-staged": "^11.1.2",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"ts-jest": "^26.1.2",
"ts-node-dev": "1.0.0-pre.44",
"typescript": "^3.9.7"
"ts-jest": "^27.0.4",
"ts-node-dev": "1.1.8",
"typescript": "^4.3.5"
}
}
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/get-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const getMessage = async (
debug('existing comment found');
}

const redactedArgs = args.map(arg =>
const redactedArgs = args.map((arg) =>
arg.startsWith('--key') ? arg.replace(/:[^:]+$/, '***') : arg
);

console.log(
'Apollo CLI command',
['npx', 'apollo@2.28.3', 'schema:check', ...redactedArgs].join(' ')
['npx', 'apollo@2.33.6', 'schema:check', ...redactedArgs].join(' ')
);

try {
const output = (await execa('npx', ['apollo@2.28.3', 'schema:check', ...args])).stdout;
const output = (await execa('npx', ['apollo@2.33.6', 'schema:check', ...args])).stdout;

console.log(output);

Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/camelcase */

import { setFailed } from '@actions/core';
import { context } from '@actions/github';
import { Octokit } from '@octokit/action';
Expand Down Expand Up @@ -37,23 +35,25 @@ const run = async (): Promise<void> => {
const comments = await octokit.issues.listComments({
owner,
repo,
issue_number: pullRequestNumber
issue_number: pullRequestNumber,
});
const existingComment = comments.data.find(comment => comment.body.includes(commentIdentifier));
const existingComment = comments.data.find((comment) =>
comment?.body?.includes(commentIdentifier)
);
const message = await getMessage(commentIdentifier, !!existingComment);

if (message) {
if (existingComment) {
octokit.issues.updateComment({
...context.repo,
comment_id: existingComment.id,
body: message
body: message,
});
} else {
octokit.issues.createComment({
...context.repo,
issue_number: pullRequestNumber,
body: message
body: message,
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/success-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#### Customer API

🔄 Validated your local schema against metrics from variant `production` for graph `user-service` on graph `neo-customer-api@production`.
🔄 Validated your local schema against metrics from variant `production` for graph `my-service` on graph `my-customer-api@production`.
🔢 Compared **3 schema changes** against **191 operations** seen over the **last 30 days**.
✅ Found **no breaking changes**.

🔗 [View your service check details](https://studio.apollographql.com/service/neo-customer-api/check/0bb7c024-f920-4a15-9e05-88135788f328?schemaTag=production&graphCompositionID=15195be7-e333-400a-8e79-44a458909edb).
🔗 [View your service check details](https://studio.apollographql.com/service/my-customer-api/check/0bb7c025-f921-4a15-9e05-88135788f328?schemaTag=production&graphCompositionID=15195be7-e334-400a-8e79-44a458909ddb).
6 changes: 3 additions & 3 deletions test/fixtures/success-response.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Loading Apollo Project
Found 0 graph composition errors for service bank-service on graph neo-customer-api@production
Found 0 graph composition errors for service my-service on graph my-customer-api@production
Compared 0 schema changes against 206 operations over the last 30 days
Found 0 breaking changes and 0 compatible changes

### Apollo Service Check
🔄 Validated your local schema against metrics from variant `production` for graph `bank-service` on graph `neo-customer-api@production`.
🔄 Validated your local schema against metrics from variant `production` for graph `my-service` on graph `my-customer-api@production`.
🔢 Compared **0 schema changes** against **206 operations** seen over the **last 30 days**.
✅ Found **no changes**.

🔗 [View your service check details](https://studio.apollographql.com/service/neo-customer-api/check/e242c939-88de-47ce-8c09-25151e1588d3?schemaTag=production&graphCompositionID=c9535a0f-ba98-4226-96bb-8727a8fa0660).
🔗 [View your service check details](https://studio.apollographql.com/service/my-customer-api/check/e242c939-88df-47ce-8c19-25151e1588d3?schemaTag=production&graphCompositionID=c9535a0f-bc98-4226-96ba-8727a8fa0660).
Loading

0 comments on commit e3f0602

Please sign in to comment.