Skip to content

Commit

Permalink
Adapt package to latest module template standards (#249)
Browse files Browse the repository at this point in the history
* Adapt package to latest module template standards

* Update prettier and run lint:fix

* Add a repository entry to package.json

* Add lint:changelogs script

* Remove lint:changelogs from lint script

* Fix suggestions
  • Loading branch information
Mrtenz committed Nov 11, 2022
1 parent 1081f7d commit 06f8532
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 163 deletions.
13 changes: 4 additions & 9 deletions .editorconfig
@@ -1,14 +1,9 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

[*.md]
indent_size = 4
trim_trailing_whitespace = false
insert_final_newline = true
11 changes: 5 additions & 6 deletions .github/workflows/create-release-pr.yml
Expand Up @@ -21,23 +21,22 @@ jobs:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
# This is to guarantee that the most recent tag is fetched.
# This can be configured to a more reasonable value by consumers.
fetch-depth: 0
# We check out the specified branch, which will be used as the base
# branch for all git operations and the release PR.
ref: ${{ github.event.inputs.base-branch }}
- name: Get Node.js version
id: nvm
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
- uses: actions/setup-node@v2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
node-version-file: '.nvmrc'
- uses: MetaMask/action-create-release-pr@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release-type: ${{ github.event.inputs.release-type }}
release-version: ${{ github.event.inputs.release-version }}
artifacts-path: gh-action__release-authors
90 changes: 65 additions & 25 deletions .github/workflows/lint-test.yml
Expand Up @@ -6,48 +6,88 @@ on:
pull_request:

jobs:
lint-test:
name: Lint and Test
runs-on: ubuntu-20.04
prepare:
name: Prepare
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install Yarn dependencies
run: yarn --immutable

lint:
name: Lint
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [14.x, 16.x, 18.x, 19.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Get Yarn cache directory
run: echo "::set-output name=YARN_CACHE_DIR::$(yarn config get cacheFolder)"
id: yarn-cache-dir
- name: Get Yarn version
run: echo "::set-output name=YARN_VERSION::$(yarn --version)"
id: yarn-version
- name: Cache yarn dependencies
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
key: yarn-cache-${{ runner.os }}-${{ steps.yarn-version.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}
- run: yarn --immutable
- run: yarn lint # "Testing" (i.e. config validation) is also done here
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn lint
- name: Validate RC changelog
if: ${{ startsWith(github.ref, 'release/') }}
run: yarn workspaces foreach --exclude root run auto-changelog validate --rc
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn lint:changelogs --rc
- name: Validate changelog
if: ${{ !startsWith(github.ref, 'release/') }}
run: yarn workspaces foreach --exclude root run auto-changelog validate
if: ${{ !startsWith(github.head_ref, 'release/') }}
run: yarn lint:changelogs
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi
check-workflows:
name: Check workflows
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download actionlint
id: download-actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.22
shell: bash
- name: Check workflow files
run: ${{ steps.download-actionlint.outputs.executable }} -color
shell: bash

all-jobs-pass:
name: All jobs pass
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs:
- lint-test
- lint
- check-workflows
steps:
- run: echo "Great success!"

is-release:
# release merge commits come from github-actions
if: startsWith(github.event.commits[0].author.name, 'github-actions')
needs:
- all-jobs-pass
outputs:
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
runs-on: ubuntu-latest
steps:
- uses: MetaMask/action-is-release@v1
id: is-release

publish-release:
needs: is-release
if: needs.is-release.outputs.IS_RELEASE == 'true'
name: Publish release
permissions:
contents: write
uses: ./.github/workflows/publish-release.yml
76 changes: 59 additions & 17 deletions .github/workflows/publish-release.yml
@@ -1,29 +1,71 @@
name: Publish Release

on:
pull_request:
types: [closed]
workflow_call:

jobs:
publish-release:
permissions:
contents: write
if: |
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# We check out the release pull request's base branch, which will be
# used as the base branch for all git operations.
ref: ${{ github.event.pull_request.base.ref }}
- name: Get Node.js version
id: nvm
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
- uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
- uses: MetaMask/action-publish-release@v1
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- uses: MetaMask/action-publish-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install
run: yarn install
- uses: actions/cache@v3
id: restore-build
with:
path: |
./node_modules/.yarn-state.yml
key: ${{ github.sha }}

publish-npm-dry-run:
runs-on: ubuntu-latest
needs: publish-release
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- uses: actions/cache@v3
id: restore-build
with:
path: |
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Dry Run Publish
# omit npm-token token to perform dry run publish
uses: MetaMask/action-npm-publish@v2
env:
SKIP_PREPACK: true

publish-npm:
environment: npm-publish
runs-on: ubuntu-latest
needs: publish-npm-dry-run
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- uses: actions/cache@v3
id: restore-build
with:
path: |
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Publish
uses: MetaMask/action-npm-publish@v2
with:
# This `NPM_TOKEN` needs to be manually set per-repository.
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
npm-token: ${{ secrets.NPM_TOKEN }}
env:
SKIP_PREPACK: true
7 changes: 3 additions & 4 deletions .gitignore
@@ -1,8 +1,7 @@
*.lerna_backup
*.har
.DS_Store
dist/
build-artifacts/
./packages/**/yarn.lock
coverage/
docs/

# Logs
logs
Expand Down
53 changes: 52 additions & 1 deletion README.md
Expand Up @@ -4,7 +4,20 @@ This monorepo contains MetaMask's ESLint configurations as npm packages.
The different configs are split up into individual packages so that we can
correctly specify their peer dependencies.

## Updating or Adding Configs
## Contributing

### Setup

- Install [Node.js](https://nodejs.org) version 14
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
- Run `yarn install` to install dependencies and run any required post-install scripts

### Testing and Linting

Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.

### Updating or Adding Configs

Configs targeting an entirely new environment should be added in a new package.
Our rule validation script (see `./scripts/validate-rules.js`) forbids the
Expand All @@ -26,3 +39,41 @@ extended configs, each package has a `rules-snapshot.json` fill which contains
all rules of the particular config and its extended configs in a single
dictionary. When editing a package, always check its rules snapshots after
running `yarn lint:fix` to understand which rules changed.

### Release & Publishing

The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.

1. Choose a release version.

- The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.

2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).

- The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.

3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.

- For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
- This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.

4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.

- Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
- Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
- Consolidate related changes into one change entry if it makes it easier to explain.
- Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.

5. Review and QA the release.

- If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.

6. Squash & Merge the release.

- This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.

7. Publish the release on npm.

- Wait for the `publish-release` GitHub Action workflow to finish. This should trigger a second job (`publish-npm`), which will wait for a run approval by the [`npm publishers`](https://github.com/orgs/MetaMask/teams/npm-publishers) team.
- Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
- Once the `publish-npm` job has finished, check npm to verify that it has been published.
34 changes: 20 additions & 14 deletions package.json
Expand Up @@ -2,19 +2,24 @@
"name": "root",
"version": "10.0.0",
"private": true,
"engines": {
"node": ">=14.0.0"
},
"scripts": {
"lint:eslint": "yarn eslint . --ext ts,js",
"lint:config-validation": "node ./scripts/validate-configs.js",
"lint:misc": "prettier '**/*.json' '!**/rules-snapshot.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:config-validation",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:config-validation --write"
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/eslint-config.git"
},
"workspaces": [
"packages/*"
],
"scripts": {
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:config-validation",
"lint:changelogs": "yarn workspaces foreach --parallel --verbose run lint:changelog",
"lint:config-validation": "node ./scripts/validate-configs.js",
"lint:eslint": "yarn eslint . --ext ts,js",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:config-validation --write",
"lint:misc": "prettier '**/*.json' '!**/rules-snapshot.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore"
},
"resolutions": {
"eslint@^8.21.0": "patch:eslint@npm%3A8.21.0#./.yarn/patches/eslint-npm-8.21.0-b57f835038.patch"
},
"devDependencies": {
"@eslint/eslintrc": "^1.3.0",
"@lavamoat/allow-scripts": "^2.0.3",
Expand All @@ -29,15 +34,16 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"fast-deep-equal": "^3.1.3",
"prettier": "^2.2.1"
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.18"
},
"packageManager": "yarn@3.2.4",
"engines": {
"node": ">=14.0.0"
},
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false
}
},
"packageManager": "yarn@3.2.4",
"resolutions": {
"eslint@^8.21.0": "patch:eslint@npm%3A8.21.0#./.yarn/patches/eslint-npm-8.21.0-b57f835038.patch"
}
}

0 comments on commit 06f8532

Please sign in to comment.