Skip to content

Commit 06f8532

Browse files
authored
Adapt package to latest module template standards (#249)
* 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
1 parent 1081f7d commit 06f8532

File tree

13 files changed

+438
-163
lines changed

13 files changed

+438
-163
lines changed

.editorconfig

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
# http://editorconfig.org
21
root = true
32

43
[*]
5-
charset = utf-8
6-
end_of_line = lf
7-
indent_size = 2
84
indent_style = space
9-
insert_final_newline = true
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
108
trim_trailing_whitespace = true
11-
12-
[*.md]
13-
indent_size = 4
14-
trim_trailing_whitespace = false
9+
insert_final_newline = true

.github/workflows/create-release-pr.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,22 @@ jobs:
2121
contents: write
2222
pull-requests: write
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525
with:
2626
# This is to guarantee that the most recent tag is fetched.
2727
# This can be configured to a more reasonable value by consumers.
2828
fetch-depth: 0
2929
# We check out the specified branch, which will be used as the base
3030
# branch for all git operations and the release PR.
3131
ref: ${{ github.event.inputs.base-branch }}
32-
- name: Get Node.js version
33-
id: nvm
34-
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
35-
- uses: actions/setup-node@v2
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v3
3634
with:
37-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
35+
node-version-file: '.nvmrc'
3836
- uses: MetaMask/action-create-release-pr@v1
3937
env:
4038
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4139
with:
4240
release-type: ${{ github.event.inputs.release-type }}
4341
release-version: ${{ github.event.inputs.release-version }}
42+
artifacts-path: gh-action__release-authors

.github/workflows/lint-test.yml

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,88 @@ on:
66
pull_request:
77

88
jobs:
9-
lint-test:
10-
name: Lint and Test
11-
runs-on: ubuntu-20.04
9+
prepare:
10+
name: Prepare
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Use Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version-file: '.nvmrc'
18+
cache: 'yarn'
19+
- name: Install Yarn dependencies
20+
run: yarn --immutable
21+
22+
lint:
23+
name: Lint
24+
runs-on: ubuntu-latest
25+
needs:
26+
- prepare
1227
strategy:
1328
matrix:
14-
node-version: [14.x, 16.x, 18.x]
29+
node-version: [14.x, 16.x, 18.x, 19.x]
1530
steps:
16-
- uses: actions/checkout@v2
31+
- uses: actions/checkout@v3
1732
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v2
33+
uses: actions/setup-node@v3
1934
with:
2035
node-version: ${{ matrix.node-version }}
21-
- name: Get Yarn cache directory
22-
run: echo "::set-output name=YARN_CACHE_DIR::$(yarn config get cacheFolder)"
23-
id: yarn-cache-dir
24-
- name: Get Yarn version
25-
run: echo "::set-output name=YARN_VERSION::$(yarn --version)"
26-
id: yarn-version
27-
- name: Cache yarn dependencies
28-
uses: actions/cache@v2
29-
with:
30-
path: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
31-
key: yarn-cache-${{ runner.os }}-${{ steps.yarn-version.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}
32-
- run: yarn --immutable
33-
- run: yarn lint # "Testing" (i.e. config validation) is also done here
36+
cache: 'yarn'
37+
- run: yarn --immutable --immutable-cache
38+
- run: yarn lint
3439
- name: Validate RC changelog
35-
if: ${{ startsWith(github.ref, 'release/') }}
36-
run: yarn workspaces foreach --exclude root run auto-changelog validate --rc
40+
if: ${{ startsWith(github.head_ref, 'release/') }}
41+
run: yarn lint:changelogs --rc
3742
- name: Validate changelog
38-
if: ${{ !startsWith(github.ref, 'release/') }}
39-
run: yarn workspaces foreach --exclude root run auto-changelog validate
43+
if: ${{ !startsWith(github.head_ref, 'release/') }}
44+
run: yarn lint:changelogs
4045
- name: Require clean working directory
4146
shell: bash
4247
run: |
4348
if ! git diff --exit-code; then
4449
echo "Working tree dirty at end of job"
4550
exit 1
4651
fi
52+
53+
check-workflows:
54+
name: Check workflows
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v3
58+
- name: Download actionlint
59+
id: download-actionlint
60+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.22
61+
shell: bash
62+
- name: Check workflow files
63+
run: ${{ steps.download-actionlint.outputs.executable }} -color
64+
shell: bash
65+
4766
all-jobs-pass:
4867
name: All jobs pass
49-
runs-on: ubuntu-20.04
68+
runs-on: ubuntu-latest
5069
needs:
51-
- lint-test
70+
- lint
71+
- check-workflows
5272
steps:
5373
- run: echo "Great success!"
74+
75+
is-release:
76+
# release merge commits come from github-actions
77+
if: startsWith(github.event.commits[0].author.name, 'github-actions')
78+
needs:
79+
- all-jobs-pass
80+
outputs:
81+
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: MetaMask/action-is-release@v1
85+
id: is-release
86+
87+
publish-release:
88+
needs: is-release
89+
if: needs.is-release.outputs.IS_RELEASE == 'true'
90+
name: Publish release
91+
permissions:
92+
contents: write
93+
uses: ./.github/workflows/publish-release.yml
Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,71 @@
11
name: Publish Release
22

33
on:
4-
pull_request:
5-
types: [closed]
4+
workflow_call:
65

76
jobs:
87
publish-release:
98
permissions:
109
contents: write
11-
if: |
12-
github.event.pull_request.merged == true &&
13-
startsWith(github.event.pull_request.head.ref, 'release/')
1410
runs-on: ubuntu-latest
1511
steps:
16-
- uses: actions/checkout@v2
17-
with:
18-
# We check out the release pull request's base branch, which will be
19-
# used as the base branch for all git operations.
20-
ref: ${{ github.event.pull_request.base.ref }}
21-
- name: Get Node.js version
22-
id: nvm
23-
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
24-
- uses: actions/setup-node@v2
25-
with:
26-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
27-
- uses: MetaMask/action-publish-release@v1
12+
- uses: actions/checkout@v3
13+
with:
14+
ref: ${{ github.sha }}
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version-file: '.nvmrc'
19+
- uses: MetaMask/action-publish-release@v2
2820
env:
2921
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
- name: Install
23+
run: yarn install
24+
- uses: actions/cache@v3
25+
id: restore-build
26+
with:
27+
path: |
28+
./node_modules/.yarn-state.yml
29+
key: ${{ github.sha }}
30+
31+
publish-npm-dry-run:
32+
runs-on: ubuntu-latest
33+
needs: publish-release
34+
steps:
35+
- uses: actions/checkout@v3
36+
with:
37+
ref: ${{ github.sha }}
38+
- uses: actions/cache@v3
39+
id: restore-build
40+
with:
41+
path: |
42+
./node_modules/.yarn-state.yml
43+
key: ${{ github.sha }}
44+
- name: Dry Run Publish
45+
# omit npm-token token to perform dry run publish
46+
uses: MetaMask/action-npm-publish@v2
47+
env:
48+
SKIP_PREPACK: true
49+
50+
publish-npm:
51+
environment: npm-publish
52+
runs-on: ubuntu-latest
53+
needs: publish-npm-dry-run
54+
steps:
55+
- uses: actions/checkout@v3
56+
with:
57+
ref: ${{ github.sha }}
58+
- uses: actions/cache@v3
59+
id: restore-build
60+
with:
61+
path: |
62+
./node_modules/.yarn-state.yml
63+
key: ${{ github.sha }}
64+
- name: Publish
65+
uses: MetaMask/action-npm-publish@v2
66+
with:
67+
# This `NPM_TOKEN` needs to be manually set per-repository.
68+
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
69+
npm-token: ${{ secrets.NPM_TOKEN }}
70+
env:
71+
SKIP_PREPACK: true

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
*.lerna_backup
2-
*.har
1+
.DS_Store
32
dist/
4-
build-artifacts/
5-
./packages/**/yarn.lock
3+
coverage/
4+
docs/
65

76
# Logs
87
logs

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ This monorepo contains MetaMask's ESLint configurations as npm packages.
44
The different configs are split up into individual packages so that we can
55
correctly specify their peer dependencies.
66

7-
## Updating or Adding Configs
7+
## Contributing
8+
9+
### Setup
10+
11+
- Install [Node.js](https://nodejs.org) version 14
12+
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
13+
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
14+
- Run `yarn install` to install dependencies and run any required post-install scripts
15+
16+
### Testing and Linting
17+
18+
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
19+
20+
### Updating or Adding Configs
821

922
Configs targeting an entirely new environment should be added in a new package.
1023
Our rule validation script (see `./scripts/validate-rules.js`) forbids the
@@ -26,3 +39,41 @@ extended configs, each package has a `rules-snapshot.json` fill which contains
2639
all rules of the particular config and its extended configs in a single
2740
dictionary. When editing a package, always check its rules snapshots after
2841
running `yarn lint:fix` to understand which rules changed.
42+
43+
### Release & Publishing
44+
45+
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.
46+
47+
1. Choose a release version.
48+
49+
- 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.
50+
51+
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).
52+
53+
- 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.
54+
55+
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.
56+
57+
- 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).
58+
- This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
59+
60+
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.
61+
62+
- 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.).
63+
- Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
64+
- Consolidate related changes into one change entry if it makes it easier to explain.
65+
- Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
66+
67+
5. Review and QA the release.
68+
69+
- 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.
70+
71+
6. Squash & Merge the release.
72+
73+
- 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.
74+
75+
7. Publish the release on npm.
76+
77+
- 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.
78+
- Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
79+
- Once the `publish-npm` job has finished, check npm to verify that it has been published.

package.json

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
"name": "root",
33
"version": "10.0.0",
44
"private": true,
5-
"engines": {
6-
"node": ">=14.0.0"
7-
},
8-
"scripts": {
9-
"lint:eslint": "yarn eslint . --ext ts,js",
10-
"lint:config-validation": "node ./scripts/validate-configs.js",
11-
"lint:misc": "prettier '**/*.json' '!**/rules-snapshot.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
12-
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:config-validation",
13-
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:config-validation --write"
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/MetaMask/eslint-config.git"
148
},
159
"workspaces": [
1610
"packages/*"
1711
],
12+
"scripts": {
13+
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:config-validation",
14+
"lint:changelogs": "yarn workspaces foreach --parallel --verbose run lint:changelog",
15+
"lint:config-validation": "node ./scripts/validate-configs.js",
16+
"lint:eslint": "yarn eslint . --ext ts,js",
17+
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:config-validation --write",
18+
"lint:misc": "prettier '**/*.json' '!**/rules-snapshot.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore"
19+
},
20+
"resolutions": {
21+
"eslint@^8.21.0": "patch:eslint@npm%3A8.21.0#./.yarn/patches/eslint-npm-8.21.0-b57f835038.patch"
22+
},
1823
"devDependencies": {
1924
"@eslint/eslintrc": "^1.3.0",
2025
"@lavamoat/allow-scripts": "^2.0.3",
@@ -29,15 +34,16 @@
2934
"eslint-plugin-node": "^11.1.0",
3035
"eslint-plugin-prettier": "^4.2.1",
3136
"fast-deep-equal": "^3.1.3",
32-
"prettier": "^2.2.1"
37+
"prettier": "^2.7.1",
38+
"prettier-plugin-packagejson": "^2.2.18"
39+
},
40+
"packageManager": "[email protected]",
41+
"engines": {
42+
"node": ">=14.0.0"
3343
},
3444
"lavamoat": {
3545
"allowScripts": {
3646
"@lavamoat/preinstall-always-fail": false
3747
}
38-
},
39-
"packageManager": "[email protected]",
40-
"resolutions": {
41-
"eslint@^8.21.0": "patch:eslint@npm%3A8.21.0#./.yarn/patches/eslint-npm-8.21.0-b57f835038.patch"
4248
}
4349
}

0 commit comments

Comments
 (0)