Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
feat: custom action (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
prescottprue authored Mar 7, 2022
1 parent e7825e5 commit 1c06433
Show file tree
Hide file tree
Showing 16 changed files with 769 additions and 85 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist
dist
coverage
node_modules
55 changes: 35 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- main
- next
- next-major
- alpha
- beta
# N.x (maintenance release branches)
Expand All @@ -21,25 +20,23 @@ jobs:
publish:
name: publish
runs-on: ubuntu-latest
# TODO: Remove if from release workflow once library is ready to release
if: ${{ false }}
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3.0.0

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.0.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
cache: yarn

- name: Configure package manager
run: |
echo Configuring NPM_TOKEN globally for .npmrc
npm config set '//registry.npmjs.org/:_authToken' ${{ env.NPM_TOKEN }}
npm whoami
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
# NOTE: Skipped since we only publish to Github Packages
# - name: Configure package manager
# run: |
# npm config set '//registry.npmjs.org/:_authToken' ${{ env.NPM_TOKEN }}
# npm whoami
# env:
# NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

- name: Install dependencies
run: yarn install --frozen-lockfile
Expand All @@ -49,15 +46,17 @@ jobs:

- name: Test
run: yarn test --coverage --silent

- name: Build
run: yarn build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload coverage to Coveralls
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: yarn build

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
Expand All @@ -74,16 +73,32 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_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
# branch "v1" to this commit.
# https://github.com/reside-eng/workflow-status-notification-action/branches
# The dist folder (built) is included so that action can be used directly from Github
# ref (where exact versions can pull from npm)
if: steps.semantic.outputs.new_release_published == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NOTE: Git user must be set in order for amend of commit to add dist folder
# --force is used because dist is within gitignore
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add --force dist
git commit -C HEAD --amend
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/v${{steps.semantic.outputs.new_release_major_version}}
notification:
# TODO: Remove if from release workflow once library is ready to release
if: ${{ false }}
# if: always()
if: always()
name: notification
needs: [publish]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v2.4.0

- uses: technote-space/[email protected]

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3.0.0

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.0.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
Expand All @@ -49,7 +49,7 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build app
- name: Build action
run: yarn build

notification:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*

coverage
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
coverage
node_modules
151 changes: 113 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,128 @@
<!-- Replace this title and any other reference to `template-library` with
the UI library's name – i.e. fastify-tools -->

<div align="center">
<h1>@side/apollo-tools</h1>
<!-- TODO: Replace with actual description of the UI application -->
<div>Library created from reside-eng/template-library</div>
<h1>@side/upload-coverage-base-action</h1>
<div>Custom github action for uploading base branch coverage on pull_request close event (instead of default branch push)</div>
</br>
</div>

<div align="center">

<!-- TODO: Uncomment package specific badges below -->
<!-- [![NPM version][npm-image]][npm-url]
[![License][license-image]][license-url] -->

[![Build Status][build-status-image]][build-status-url]
[![semantic-release][semantic-release-icon]][semantic-release-url]
[![Code Style][code-style-image]][code-style-url]

</div>

This is the template repository for creating additional Next.js UI applications.
Once a new repository has been created off this template, follow the steps below
to finalize the initial setup process:

1. Replace all references of `template-library` with the name of this application
1. Create a new file starting your functionality using `src/placeholder.ts` and `src/placeholder.test.ts` as an example
1. Remove `src/placeholder.ts` and `src/placeholder.test.ts` files
1. Find all relevant `TODO:` references and make adjustments accordingly
1. Set general repository settings:
a. Only allow squash and merge
a. Allow auto-merge
a. Allow deletion of head branches
1. Manage access to the repo by adding the teams that need permissions. This is required for automatic PR review assignment.
1. Set branch permissions for `main` to set required PR verifications for CI
1. Start making PRs with basic functionality - continue to next section once library is publishable

## Enable Publishing

1. Add your new repository to the repositories with access to [`NPM_PUBLISH_TOKEN` org level secret](https://github.com/organizations/reside-eng/settings/secrets/actions/NPM_PUBLISH_TOKEN)
1. Create a PR removing `if: ${{ false }}` from release workflow
1. Merge above mentioned PR to create first release - this will take a while since all PRs up until this first release will be marked as released by semantic-release

[npm-image]: https://img.shields.io/npm/v/@side/template-library.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@side/template-library
[build-status-image]: https://img.shields.io/github/workflow/status/reside-eng/template-library/Release?style=flat-square
[build-status-url]: https://github.com/reside-eng/template-library/actions
[license-image]: https://img.shields.io/npm/l/@side/template-library.svg?style=flat-square
[license-url]: https://github.com/reside-eng/template-library/blob/main/LICENSE
## Use

An artifact should be uploaded during the verify stage so that base can be set on closed event of the PR:

**verify.yml**

```yaml
name: Verify

on:
pull_request:
branches:
- develop

concurrency:
group: verify-${{ github.head_ref }}
cancel-in-progress: true

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: ${{ inputs.GIT_REF }}

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

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

- name: Verify lint
run: yarn lint

- name: Test app
run: yarn test:cov

# Used in merge-main.yml workflow to upload base branch coverage once merged
# NOTE: Temporary - planned to be replaced by custom workflow in workflow-templates
- name: Upload coverage artifact
uses: actions/upload-artifact@v2
with:
name: coverage-${{ github.event.pull_request.head.sha }}
path: coverage/lcov.info
```
**merge-main.yml**
```yaml
name: Merge to main

on:
pull_request:
types: [closed]
branches:
- main

jobs:
promote-deploy-prod:
name: promote-deploy-prod
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: ${{ inputs.GIT_REF }}

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

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

- name: Verify lint
run: yarn lint

- name: Test app
run: yarn test:cov

# Download coverage artifact from verify.yml workflow and send as base to Coveralls
- name: Upload base coverage to Coveralls
uses: reside-eng/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
coveralls-token: ${{ secrets.COVERALLS_API_TOKEN }}
```
## Inputs
| name | required | default | description |
| ------------------------ | -------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| github-token | `true` | `undefined` | GITHUB_TOKEN secret (for authentication with Github API) |
| coveralls-token | `true` | `undefined` | Coveralls API token |
| base-branch | `false` | `pull_request.head.ref \|\| 'main'` | Base branch (defaults to pull_request.head.ref falling back to "main") |
| coverage-artifact-name | `false` | `'coverage'` | Name of coverage artifact (useful for multiple artifacts). NOTE: Each workflow run has it's own artifacts, so name only has to be unique compared to orther artifacts in the single workflow run. |
| lcov-path | `false` | `'coverage/lcov.info'` | Path to lcov.info file |
| upload-workflow-filename | `false` | `'verify.yml'` | Filename of workflow which uploaded coverage artifact |

[build-status-image]: https://github.com/reside-eng/upload-coverage-base-action/actions/workflows/release.yml/badge.svg
[build-status-url]: https://github.com/reside-eng/upload-coverage-base-action/actions
[license-image]: https://img.shields.io/npm/l/@side/upload-coverage-base-action.svg?style=flat-square
[license-url]: https://github.com/reside-eng/upload-coverage-base-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
Expand Down
29 changes: 29 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Upload Coverage Base Action'
description: 'Custom github action for uploading base branch coverage on pull_request close event (instead of default branch push)'
inputs:
github-token:
description: 'GITHUB_TOKEN secret (for authentication with Github API)'
required: true
coveralls-token:
description: 'Coveralls API token'
required: true
base-branch:
description: 'Base branch (defaults to pull_request.head.ref falling back to "main")'
required: false
lcov-path:
description: 'Path to lcov.info file'
default: 'coverage/lcov.info'
required: false
coverage-artifact-name:
description: >
'Name of coverage artifact (useful for multiple artifacts). NOTE: Each workflow run has it's own artifacts, so name only has to be unique compared to orther artifacts in the single workflow run.'
default: 'coverage'
required: false
upload-workflow-filename:
description: 'Filename of workflow which uploaded coverage artifact'
default: 'verify.yml'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
post-if: 'success()'
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@side/template-library",
"name": "@side/upload-coverage-base-action",
"version": "0.0.0-development",
"description": "Library created from reside-eng/template-library",
"description": "Custom github action for uploading base branch coverage on pull_request close event (instead of default branch push)",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -16,9 +16,14 @@
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint . --ext .ts,.js",
"build": "rimraf dist/* && tsc",
"build": "rimraf dist && ncc build src/index.ts",
"test": "jest"
},
"dependencies": {
"@actions/core": "1.6.0",
"@actions/github": "5.0.0",
"coveralls-api": "1.2.4"
},
"devDependencies": {
"@commitlint/cli": "16.2.1",
"@side/commitlint-config": "0.1.10",
Expand All @@ -30,6 +35,7 @@
"@types/node": "16.11.26",
"@typescript-eslint/eslint-plugin": "5.13.0",
"@typescript-eslint/parser": "5.13.0",
"@vercel/ncc": "0.33.3",
"eslint": "8.10.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jsdoc": "37.9.6",
Expand Down Expand Up @@ -61,5 +67,8 @@
"prettier --write"
],
"*.{json,md,yaml,yml,graphql}": "prettier --write"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
}
}
Loading

0 comments on commit 1c06433

Please sign in to comment.