Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite internals for v2 release #83

Merged
merged 36 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a44a80a
wip: better behaved npm
mcous Apr 10, 2023
15f5601
wip: continue figuring out the shape of things
mcous Apr 11, 2023
07bd14c
wip: move on to publish
mcous Apr 11, 2023
36d603f
fixup: still going for it
mcous Apr 12, 2023
a4f2efd
wip: continuing along with tdd refactor
mcous Apr 12, 2023
9662ce0
fixup: switch ci to use new unit test suite
mcous Apr 14, 2023
54cc7a3
wip: almost through the rewrite, CLI left
mcous Apr 17, 2023
c3abcae
wip: let's see how this does
mcous Apr 17, 2023
b30569e
wip: fix up auth settings (thanks e2e tests)
mcous Apr 17, 2023
e7698e7
Test and CI fixes
mcous Apr 17, 2023
8c6f5a2
wip: e2e in matrix
mcous Apr 17, 2023
3eab721
wip: e2e node 16 fixes
mcous Apr 17, 2023
2088119
wip: fix ci
mcous Apr 17, 2023
d9fcce5
wip: fix ci
mcous Apr 17, 2023
865edee
wip: e2e registry login
mcous Apr 17, 2023
18f4a9d
wip: simplify normalized options
mcous Apr 17, 2023
b7b2dc9
fixup: test improvements
mcous Apr 18, 2023
28e9467
wip: revert docs changes for separate PR
mcous Apr 18, 2023
55ed2ee
fixup: build updates
mcous Apr 19, 2023
7b42108
fixup: cli usage typo
mcous Apr 19, 2023
409c72f
fixup: fix package paths with spaces
mcous Apr 19, 2023
7cd2fda
fixup: swap minimist for command-line-args due to windows path bugs
mcous Apr 19, 2023
21f93b9
fixup: revert, it was a powershell bug 🤦
mcous Apr 19, 2023
3b10db5
fixup: update e2e test to use spaces in package name
mcous Apr 19, 2023
87ee5ab
fixup: what if I was better at shell?
mcous Apr 19, 2023
28c3b35
fixup: spawn might be a better choice for windows
mcous Apr 19, 2023
bb42c2d
fixup: more windows work
mcous Apr 19, 2023
7dda521
fixup: keep trying to get these e2e tests to work with spaced package…
mcous Apr 20, 2023
9f02b38
fixup: think I got it this time
mcous Apr 20, 2023
676a76b
fixup: actually run these tests on different os's
mcous Apr 20, 2023
c71a30b
fixup: fix environment test on windows
mcous Apr 20, 2023
8578e2b
fixup: check name tweaks
mcous Apr 20, 2023
255f0da
fixup: error name typo
mcous Apr 20, 2023
2ec381c
fixup: build after typo fixes
mcous Apr 20, 2023
bca9d66
fixup: ci tweaks
mcous Apr 20, 2023
2cb1fd6
fixup: add missing sourcemap
mcous Apr 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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