Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
chore: switch to using node-setup for caching (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
prescottprue authored Nov 25, 2021
1 parent 9082f38 commit fa9d1e4
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 103 deletions.
69 changes: 37 additions & 32 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,41 @@ on:
branches:
- main
- next
- next-major
- alpha
- beta
# N.x (maintenance release branches)
- '[0-9]+.x'

concurrency:
group: publish

env:
NODE_VERSION: 14.x

jobs:
build:
name: Release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: [14.x]
publish:
name: publish
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2.3.4
- name: Checkout code
uses: actions/checkout@v2.4.0

- name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
uses: actions/[email protected].1
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/[email protected].0
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Configure Package Manager
- name: Configure package manager
run: |
echo Configuring NPM_READ_TOKEN globally for .npmrc
npm config set '//registry.npmjs.org/:_authToken' ${{ secrets.NPM_PUBLISH_TOKEN }}
echo Configuring NPM_TOKEN globally for .npmrc
npm config set '//registry.npmjs.org/:_authToken' ${{ env.NPM_TOKEN }}
npm whoami
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/[email protected]
# Use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

- name: Install Dependencies
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Lint
Expand All @@ -54,16 +48,27 @@ jobs:
- name: Test
run: yarn test --coverage --silent

- uses: codecov/[email protected]
with:
fail_ci_if_error: true
# TODO: [PLAT-1191] Re-enable once support for no comment
# - name: Report Coverage
# uses: reside-eng/code-coverage-action@v1
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
with:
branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main',
'next',
'next-major',
{name: 'beta', prerelease: true},
{name: 'alpha', prerelease: true}
]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Push updates to branch for major version
# If a new version is published, i.e. v1.2.3 then this step will update
Expand Down
42 changes: 12 additions & 30 deletions .github/workflows/verify-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,43 @@ on:
branches:
- main

env:
NODE_VERSION: 14.x

jobs:
build:
name: Build and Verify
runs-on: ${{ matrix.os }}
name: build
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
strategy:
matrix:
os: [ubuntu-latest]
node-version: [14.x]
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout Code
uses: actions/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Configure Package Manager
run: |
echo Configuring NPM_READ_TOKEN globally for .npmrc
npm config set '//registry.npmjs.org/:_authToken' ${{ secrets.NPM_READ_TOKEN }}
npm whoami
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/[email protected]
# Use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

- name: Test
uses: raulanatol/[email protected]
run: yarn test --coverage --coverageReporters="json-summary"

- name: Comment + Report Coverage
uses: reside-eng/code-coverage-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
jest-command: yarn test --coverage --silent

- name: Build
run: yarn build
45 changes: 18 additions & 27 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,50 @@ name: Verify

on: [pull_request]

env:
NODE_VERSION: 14.x

jobs:
build:
name: Build and Test
runs-on: ${{ matrix.os }}
name: build
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
strategy:
matrix:
os: [ubuntu-latest]
node-version: [14.x]
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout Code
uses: actions/[email protected]

- name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Configure Package Manager
run: |
echo Configuring NPM_READ_TOKEN globally for .npmrc
npm config set '//registry.npmjs.org/:_authToken' ${{ secrets.NPM_READ_TOKEN }}
npm whoami
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/[email protected]
# Use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

- name: Test
run: yarn test --coverage

- name: Comment test coverage
uses: raulanatol/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
jest-command: yarn test --coverage --silent
use-existing-reports: true

# TODO: Re-enable once publishing is fixed
# - name: Comment + Report Coverage
# uses: reside-eng/code-coverage-action@v1
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: yarn build
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# code-coverage-action

> Comments and uploads code coverage
> Comments and uploads code coverage for global reporting
## Use

1. Make sure to have an npm script for running your tests in package.json:

```json
[![NPM version][npm-image]][npm-url]
[![Build Status][build-status-image]][build-status-url]
[![Code Coverage][coverage-image]][coverage-url]
[![License][license-image]][license-url]
[![semantic-release][semantic-release-icon]][semantic-release-url]
[![Code Style][code-style-image]][code-style-url]

```
## Use

1. Call action in your workflow:
1. Call action in your workflow after running tests with coverage report generation:

```yml
name: Verify
Expand All @@ -20,15 +21,11 @@ on: [pull_request]
jobs:
build:
name: build
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
node-version: [14.x]
if: github.actor != 'dependabot[bot]'
outputs:
project: ${{ steps.set-environment.outputs.project }}
env: ${{ steps.set-environment.outputs.env }}
steps:
- name: Checkout Code
uses: actions/[email protected]
Expand All @@ -53,3 +50,16 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
```
[npm-image]: https://img.shields.io/npm/v/@side/code-coverage-action.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@side/code-coverage-action
[build-status-image]: https://img.shields.io/github/workflow/status/reside-eng/code-coverage-action/Publish?style=flat-square
[build-status-url]: https://github.com/reside-eng/code-coverage-action/actions
[coverage-image]: https://img.shields.io/codecov/c/github/reside-eng/code-coverage-action.svg?style=flat-square
[coverage-url]: https://codecov.io/gh/reside-eng/code-coverage-action
[license-image]: https://img.shields.io/npm/l/@side/code-coverage-action.svg?style=flat-square
[license-url]: https://github.com/reside-eng/code-coverage-action/blob/main/LICENSE
[code-style-image]: https://img.shields.io/badge/code%20style-airbnb-blue.svg?style=flat-square
[code-style-url]: https://github.com/airbnb/javascript
[semantic-release-icon]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square
[semantic-release-url]: https://github.com/semantic-release/semantic-release
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ module.exports = {
verbose: true,
collectCoverageFrom: ['src/**/*.ts'],
modulePathIgnorePatterns: ['dist'],
coverageThreshold: {
global: {
lines: 15,
statements: 15,
},
},
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"moduleResolution": "node"
},
"exclude": ["node_modules", "**/*.test.ts"],
"include": ["src"]
"include": ["src", "__tests__/comments.test.ts"]
}

0 comments on commit fa9d1e4

Please sign in to comment.