Skip to content

Commit

Permalink
Rewrite internals for v2 release (#83)
Browse files Browse the repository at this point in the history
Addresses #15, #35, #36, #47, #51, and #59
  • Loading branch information
mcous authored Apr 20, 2023
1 parent b992c2e commit c5f37b9
Show file tree
Hide file tree
Showing 73 changed files with 9,628 additions and 12,545 deletions.
53 changes: 14 additions & 39 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extends:
- "plugin:@typescript-eslint/strict"
- "plugin:import/recommended"
- "plugin:import/typescript"
- "plugin:jsdoc/recommended-typescript"
- "plugin:jsdoc/recommended-typescript-error"
- "plugin:n/recommended"
- "plugin:promise/recommended"
- "plugin:sonarjs/recommended"
Expand All @@ -27,49 +27,24 @@ env:
es2021: true
node: true

rules:
unicorn/prefer-top-level-await: "off"
jsdoc/tag-lines: "off"

overrides:
- files: ["**/*.js"]
rules:
"@typescript-eslint/no-var-requires": "off"
"unicorn/prefer-module": "off"
unicorn/prefer-module: "off"

- files: ["test/**/*"]
env:
mocha: true
- files: ["**/__tests__/**/*"]
rules:
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-unsafe-argument": "off"
"@typescript-eslint/no-unsafe-assignment": "off"
sonarjs/no-duplicate-string: "off"
unicorn/no-useless-undefined: "off"

rules:
n/no-unpublished-import: ["error", { "allowModules": ["@actions/core"] }]

# temporary rule overrides
# TODO(mc, 2023-04-12): fix problems, remove overrides, and remove --quiet
prefer-const: "warn"
no-regex-spaces: "warn"
"@typescript-eslint/no-floating-promises": "warn"
"@typescript-eslint/no-unsafe-argument": "warn"
"@typescript-eslint/no-unsafe-assignment": "warn"
"@typescript-eslint/no-unsafe-call": "warn"
"@typescript-eslint/no-unsafe-member-access": "warn"
"@typescript-eslint/no-unsafe-return": "warn"
"@typescript-eslint/require-await": "warn"
"@typescript-eslint/restrict-plus-operands": "warn"
"@typescript-eslint/restrict-template-expressions": "warn"
"@typescript-eslint/unbound-method": "warn"
n/no-missing-import: "warn"
n/no-missing-require: "warn"
n/no-process-exit: "warn"
unicorn/better-regex: "warn"
unicorn/catch-error-name: "warn"
unicorn/import-style: "warn"
unicorn/no-array-push-push: "warn"
unicorn/no-process-exit: "warn"
unicorn/no-useless-undefined: "warn"
unicorn/prefer-export-from: "warn"
unicorn/prefer-module: "warn"
unicorn/prefer-node-protocol: "warn"
unicorn/prefer-optional-catch-binding: "warn"
unicorn/prefer-spread: "warn"
unicorn/prefer-top-level-await: "warn"
unicorn/prevent-abbreviations: "warn"
unicorn/text-encoding-identifier-case: "warn"
- files: ["src/action/**/*"]
rules:
n/no-unpublished-import: "off"
70 changes: 33 additions & 37 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,8 @@ on:
- cron: "25 12 * * 1"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Install Node.js and dependencies
uses: ./.github/actions/setup

- name: Run linters
run: npm run lint

test:
name: Run tests using Node ${{ matrix.node }} on ${{ matrix.os }}
name: Unit tests / Node.js ${{ matrix.node-version }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
Expand All @@ -38,9 +23,8 @@ jobs:
os:
- ubuntu-latest
- macos-latest
# TODO(mc, 2023-04-07): investigate and fix coverage-related failures on Windows
# - windows-latest
node:
- windows-latest
node-version:
- 16
- 18

Expand All @@ -51,10 +35,7 @@ jobs:
- name: Install Node.js ${{ matrix.node }} and dependencies
uses: ./.github/actions/setup
with:
node-version: ${{ matrix.node }}

- name: Build the code
run: npm run build
node-version: ${{ matrix.node-version }}

- name: Run tests
run: npm run coverage
Expand All @@ -78,7 +59,7 @@ jobs:
parallel-finished: true

build:
name: Build
name: Build and lint
runs-on: ubuntu-latest
timeout-minutes: 10

Expand All @@ -92,18 +73,33 @@ jobs:
- name: Build
run: npm run build

- name: Verify no un-staged changes
run: |
git status --porcelain
git diff-files --quiet
- name: Run lints
run: npm run lint

- name: Upload publish artifact
uses: actions/upload-artifact@v3
with:
name: publish-artifact
path: lib

e2e:
name: Run end-to-end tests
name: E2E tests / Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
timeout-minutes: 10
needs: build

strategy:
fail-fast: false
matrix:
node-version:
- 16
- 18

services:
verdaccio:
image: verdaccio/verdaccio:5
Expand All @@ -117,6 +113,7 @@ jobs:
- name: Install Node.js and dependencies
uses: ./.github/actions/setup
with:
node-version: ${{ matrix.node-version }}
install-command: npm install --production

- name: Download publish artifact
Expand All @@ -130,20 +127,20 @@ jobs:
shell: bash
run: |
echo "token=$(./e2e/00-login.sh)" >> "$GITHUB_OUTPUT"
echo "package=$(./e2e/01-setup-package.sh ./e2e/fixture 0.0.1)" >> "$GITHUB_OUTPUT"
echo "package=$(./e2e/01-setup-package.sh ./e2e/fixture/cool\ package 0.0.1)" >> "$GITHUB_OUTPUT"
- name: Run CLI end-to-end test
shell: bash
env:
TOKEN: ${{ steps.setup.outputs.token }}
PACKAGE: ${{ steps.setup.outputs.package }}
run: |
./e2e/02-publish.sh ${PACKAGE} ${TOKEN}
./e2e/03-verify.sh ${PACKAGE}
./e2e/02-publish.sh ${PACKAGE} ${TOKEN}
./e2e/01-setup-package.sh ${PACKAGE} 0.0.2
./e2e/02-publish.sh ${PACKAGE} ${TOKEN}
./e2e/03-verify.sh ${PACKAGE}
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
./e2e/03-verify.sh "${PACKAGE}"
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
./e2e/01-setup-package.sh "${PACKAGE}" 0.0.2
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
./e2e/03-verify.sh "${PACKAGE}"
- id: action-no-publish
name: Publish with already published version
Expand All @@ -154,14 +151,14 @@ jobs:
token: ${{ steps.setup.outputs.token }}

- name: Check action output
if: ${{ steps.action-no-publish.outputs.type != 'none' }}
if: ${{ steps.action-no-publish.outputs.type }}
run: |
echo "::error::Expected release type to be 'none', got '${{ steps.action-no-publish.outputs.type }}'"
echo "::error::Expected release type to be '', got '${{ steps.action-no-publish.outputs.type }}'"
exit 1
- name: Create new version for Action end-to-end test
shell: bash
run: ./e2e/01-setup-package.sh ${{ steps.setup.outputs.package }} 0.0.3
run: ./e2e/01-setup-package.sh "${{ steps.setup.outputs.package }}" 0.0.3

- id: action-publish
name: Publish a new version
Expand All @@ -179,11 +176,10 @@ jobs:
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
name: Publish to NPM
name: Publish
runs-on: ubuntu-latest
timeout-minutes: 10
needs:
- lint
- test
- build
- e2e
Expand Down
13 changes: 0 additions & 13 deletions .mocharc.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .nycrc.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins:
- prettier-plugin-jsdoc
tsdoc: true
13 changes: 8 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ git clone https://github.com/JS-DevTools/npm-publish.git
# Install dependencies*
npm install

# Build the code
npm run build

# Run the tests
npm test
# Run all checks, builds, and unit tests
npm run all
```

There are also various code quality checks and tests you can run:

```shell
# Run builds and typechecking
npm run build

# Run the unit tests in watch mode
npm run test

# Autoformat the code
npm run format

Expand Down
71 changes: 46 additions & 25 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# GitHub Action
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/metadata-syntax-for-github-actions

name: NPM Publish
description: Fast, easy publishing to NPM

Expand All @@ -17,49 +14,73 @@ inputs:
registry:
description: The NPM registry URL to use
required: false
default: https://registry.npmjs.org/

package:
description: The path of your package.json file
description: The path to your package or its package.json file
required: false
default: package.json

tag:
description: The tag to publish to. This allows people to install the package using "npm install <package-name>@<tag>".
description: The distribution tag to publish
required: false
default: "latest"

access:
description:
Determines whether the published package should be publicly visible, or restricted to members of your NPM organization.
This only applies to scoped packages.
description: >
Determines whether the published package should be publicly visible,
or restricted to members of your NPM organization.
required: false

dry-run:
description: If true, run with the --dry-run flag
required: false
default: "false"
strategy:
description: >
Version check and release strategy.
If "all" (default), package will be published if its version is simply not yet published.
If "upgrade", package will be published if its version is higher than the existing tag,
according to semantic versioning.
check-version:
description: Only publish if the version in package.json differs from the latest on NPM
required: false
default: "true"

greater-version-only:
description: Only publish to NPM if the version number in package.json is greater than the latest on NPM
dry-run:
description: Run npm with the --dry-run flag to avoid actually publishing anything.
required: false
default: "false"

outputs:
id:
description: >
The identifier of the published package.
If a release was published, format is `${name}@${version}.
If no release occurred, will be an empty string.
type:
description: The type of version change that occurred ("none", "major", "minor", "patch", etc.)
description: >
The type of version change that occurred on the published tag.
If release was an upgrade, will be a semver release type ("major", "minor", ...).
If the published tag had no previous version, will be "initial".
If version was change was not an upgrade, will be "different".
If no release occurred, will be an empty string.
name:
description: Name of the package.

version:
description: The version that was published
description: Version of the package.

old-version:
description: The version number that was previously published to NPM
description: >
The previous version on the distribution tag.
If there was no previous version on the tag, will be an empty string.
registry:
description: The registry used for version checking and publishing.

tag:
description: The distribution tag used for version checking and publishing.

access:
description: >
The package access setting used.
If configured by the action or package.json, will be "public" or "protected".
If not configured for a non-scoped package, will be "public".
If not configured for a scoped package, will be "default".
runs:
using: node16
main: dist/index.js
main: dist/main.js
Loading

0 comments on commit c5f37b9

Please sign in to comment.