Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Add GitHub workflows for autopublish (#68)
Browse files Browse the repository at this point in the history
* Adopt 0.0.0 autopublish convention.

* Eliminate CircleCI configuration

* Upgrade aslant + friends

* Add package auto-publication magic

* Avoid double workflows

* Upgrade to NodeJS 18

* Add NPM publication

* Add Cypress version to test matrix
  • Loading branch information
xeger authored Dec 11, 2022
1 parent 6847644 commit 2a922cf
Show file tree
Hide file tree
Showing 11 changed files with 1,783 additions and 1,735 deletions.
37 changes: 0 additions & 37 deletions .circleci/config.yml

This file was deleted.

14 changes: 4 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:cypress/recommended',
'plugin:react/recommended',
// NB: please leave these at the end so they can override all other rules!
'prettier/@typescript-eslint',
// NB: please leave this at the end so it can override all other rules!
'plugin:prettier/recommended'
],
parserOptions: {
Expand All @@ -30,18 +30,12 @@ module.exports = {
sourceType: 'module' // allow `import` statement
},
rules: {
'@typescript-eslint/array-type': 'warn',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/class-name-casing': 'warn',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off', // warns about mandatory param names in function types!
'@typescript-eslint/no-use-before-define': 'off', // pointless rule
'@typescript-eslint/no-explicit-any': 'off', // maybe someday!
'@typescript-eslint/no-namespace': 'off', // Cypress makes us use namespaces
'no-empty': 'warn',
'no-extra-boolean-cast': 'warn',
'no-undef': 'off', // gives false alarms about Cypress globals e.g. JQuery
'no-unused-vars': 'off', // gives false alarms about mandatory TS param names in fn declarations!
'prettier/prettier': ['error', {singleQuote: true, trailingComma: 'es5'}],
'react/prop-types': 'off'
},
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Reusable publish workflow for open-source NPM packages
# - dual publication (to NPM, then GitHub)
# - single package per repo (no mono-repo support)
name: publish

on:
release:
types: [published]

jobs:
publish:
name: publish

runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Establish Version
run: |
release='${{ github.event.release.tag_name }}'
version=`echo $release | cut -b2-`
if ! echo $release | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$'; then
echo "Release name must be in the format of 'vX.Y.Z[-anything]', got '$release'"
exit 1
fi
sed -i -r "s/\"version\": *\".+\"/\"version\": \"$version\"/" package.json
- name: Install Dependencies
run: npm ci
- name: Build Distributables
run: npm run build
- name: Publish to NPM
run: |
touch $HOME/.npmrc
chmod 0600 $HOME/.npmrc
cat << EOF > ~/.npmrc
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
@appfolio:registry=https://registry.npmjs.org/
EOF
npm publish --workspaces
env:
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
- name: Publish to GitHub
run: |
touch $HOME/.npmrc
chmod 0600 $HOME/.npmrc
cat << EOF > ~/.npmrc
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
@appfolio-im:registry=https://npm.pkg.github.com/
EOF
npm publish
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: test

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: test

runs-on: ubuntu-latest

strategy:
matrix:
cypress-version: ["11", "12"]
node-version: ["16.x", "18.x"]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm install --save=false cypress@${{ matrix.cypress-version }}
- run: npm test
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.12.1
13 changes: 6 additions & 7 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import mount from './mount';

gears.add();


// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount
}
namespace Cypress {
interface Chainable {
mount: typeof mount;
}
}

Cypress.Commands.add('mount', mount)
}

Cypress.Commands.add('mount', mount);
4 changes: 2 additions & 2 deletions cypress/support/eventually.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Iteratively call cy.wait() with exponential backoff until something becomes true.
* Iteratively call cy.wait() with exponential backoff until callback returns truthy.
* Break once the backoff reaches 1024ms (regardless of initial backoff).
*/
export default function eventually(cb: Function, backoff = 32) {
export default function eventually(cb: () => any, backoff = 32) {
if (backoff > 1024) throw new Error(`Condition did not become true`);

// eslint-disable-next-line cypress/no-unnecessary-waiting
Expand Down
Loading

0 comments on commit 2a922cf

Please sign in to comment.