From 39a935e111578ed91f4b01f9ee9cb6d3c656bff7 Mon Sep 17 00:00:00 2001 From: Jack Clancy Date: Tue, 4 Jul 2023 03:41:20 -0400 Subject: [PATCH 1/3] Update CODEOWNERS (#163) --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 50bea790..7fd0cc67 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ # Lines starting with '#' are comments. # Each line is a file pattern followed by one or more owners. -* @MetaMask/devs +* @MetaMask/engineering From 3e093655a3272073dbd9ebab645a91262911c49f Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Sun, 9 Jul 2023 20:44:08 -0700 Subject: [PATCH 2/3] Sync GitHub workflow files with module template (#138) - Instead of running the "build", "lint", and "test" steps in one job, split them up into separate jobs so CI will run faster. - Notify in Slack when a new release is pending approval - Remove the "require additional reviewer" check - Use newer versions of our GitHub Actions - Add a pull request template Note that the workflows to publish and deploy docs are missing because `typedoc` isn't present in this project; that will be added later. --- .github/pull_request_template.md | 11 +++ .github/workflows/build-lint-test.yml | 99 +++++++++++++++++++++++++ .github/workflows/build-test.yml | 49 ------------ .github/workflows/create-release-pr.yml | 15 ++-- .github/workflows/main.yml | 76 +++++++++++++++++++ .github/workflows/publish-release.yml | 82 +++++++++++--------- scripts/get.sh | 21 ++++++ 7 files changed, 260 insertions(+), 93 deletions(-) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/build-lint-test.yml delete mode 100644 .github/workflows/build-test.yml create mode 100644 .github/workflows/main.yml create mode 100755 scripts/get.sh diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..5fc5feac --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,11 @@ + diff --git a/.github/workflows/build-lint-test.yml b/.github/workflows/build-lint-test.yml new file mode 100644 index 00000000..d5507e79 --- /dev/null +++ b/.github/workflows/build-lint-test.yml @@ -0,0 +1,99 @@ +name: Build, Lint, and Test + +on: + workflow_call: + +jobs: + 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 + + build: + name: Build + runs-on: ubuntu-latest + needs: + - prepare + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + - run: yarn --immutable --immutable-cache + - run: yarn build + - 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 + + lint: + name: Lint + runs-on: ubuntu-latest + needs: + - prepare + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + - run: yarn --immutable --immutable-cache + - run: yarn lint + - name: Validate RC changelog + if: ${{ startsWith(github.head_ref, 'release/') }} + run: yarn auto-changelog validate --rc + - name: Validate changelog + if: ${{ !startsWith(github.head_ref, 'release/') }} + run: yarn auto-changelog validate + - 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 + + test: + name: Test + runs-on: ubuntu-latest + needs: + - prepare + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + - run: yarn --immutable --immutable-cache + - run: yarn test + - 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 diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml deleted file mode 100644 index 4edfdab3..00000000 --- a/.github/workflows/build-test.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Build, Lint, and Test - -on: - push: - branches: [main] - pull_request: - -jobs: - build-lint-test: - name: Build, Lint, and Test - runs-on: ubuntu-20.04 - strategy: - matrix: - node-version: [14.x, 16.x, 18.x] - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - name: Get Yarn cache directory - run: echo "::set-output name=YARN_CACHE_DIR::$(yarn cache dir)" - 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 --frozen-lockfile - - run: yarn allow-scripts - - run: yarn build - - run: yarn lint - - run: yarn test - - name: Validate RC changelog - if: ${{ startsWith(github.head_ref, 'release/') }} - run: yarn auto-changelog validate --rc - - name: Validate changelog - if: ${{ !startsWith(github.head_ref, 'release/') }} - run: yarn auto-changelog validate - all-jobs-pass: - name: All jobs pass - runs-on: ubuntu-20.04 - needs: - - build-lint-test - steps: - - run: echo "Great success!" diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml index e27cf3af..681ce6cb 100644 --- a/.github/workflows/create-release-pr.yml +++ b/.github/workflows/create-release-pr.yml @@ -8,7 +8,7 @@ on: default: 'main' required: true release-type: - description: 'A SemVer version diff, i.e. major, minor, patch, prerelease etc. Mutually exclusive with "release-version".' + description: 'A SemVer version diff, i.e. major, minor, or patch. Mutually exclusive with "release-version".' required: false release-version: description: 'A specific version to bump to. Mutually exclusive with "release-type".' @@ -21,7 +21,7 @@ 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. @@ -29,16 +29,13 @@ jobs: # 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 }} - - uses: MetaMask/action-create-release-pr@v1 + node-version-file: '.nvmrc' + - uses: MetaMask/action-create-release-pr@v2 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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..b17972d3 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,76 @@ +name: Main + +on: + push: + branches: [main] + pull_request: + +jobs: + 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.23 + shell: bash + - name: Check workflow files + run: ${{ steps.download-actionlint.outputs.executable }} -color + shell: bash + + build-lint-test: + name: Build, lint, and test + uses: ./.github/workflows/build-lint-test.yml + + all-jobs-completed: + name: All jobs completed + runs-on: ubuntu-latest + needs: + - check-workflows + - build-lint-test + outputs: + PASSED: ${{ steps.set-output.outputs.PASSED }} + steps: + - name: Set PASSED output + id: set-output + run: echo "PASSED=true" >> "$GITHUB_OUTPUT" + + all-jobs-pass: + name: All jobs pass + if: ${{ always() }} + runs-on: ubuntu-latest + needs: all-jobs-completed + steps: + - name: Check that all jobs have passed + run: | + passed="${{ needs.all-jobs-completed.outputs.PASSED }}" + if [[ $passed != "true" ]]; then + exit 1 + fi + + is-release: + # Filtering by `push` events ensures that we only release from the `main` branch, which is a + # requirement for our npm publishing environment. + # The commit author should always be 'github-actions' for releases created by the + # 'create-release-pr' workflow, so we filter by that as well to prevent accidentally + # triggering a release. + if: github.event_name == 'push' && startsWith(github.event.head_commit.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 + secrets: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 1940058c..6f851486 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,39 +1,27 @@ name: Publish Release on: - push: - branches: [main] + workflow_call: + secrets: + NPM_TOKEN: + required: true + SLACK_WEBHOOK_URL: + required: true jobs: - is-release: - # release merge commits come from github-actions - if: startsWith(github.event.commits[0].author.name, 'github-actions') - outputs: - IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }} - runs-on: ubuntu-latest - steps: - - uses: MetaMask/action-is-release@v1.0 - id: is-release - publish-release: permissions: contents: write - if: needs.is-release.outputs.IS_RELEASE == 'true' runs-on: ubuntu-latest - needs: is-release steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 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 + ref: ${{ github.sha }} + - name: Setup Node.js + uses: actions/setup-node@v3 with: - node-version: ${{ steps.nvm.outputs.NODE_VERSION }} - - uses: MetaMask/action-publish-release@v2.0.0 + node-version-file: '.nvmrc' + - uses: MetaMask/action-publish-release@v3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Install @@ -43,43 +31,67 @@ jobs: - uses: actions/cache@v3 id: restore-build with: - path: ./dist + path: | + ./dist + ./node_modules/.yarn-state.yml key: ${{ github.sha }} publish-npm-dry-run: runs-on: ubuntu-latest needs: publish-release steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: ${{ github.sha }} - uses: actions/cache@v3 id: restore-build with: - path: ./dist + path: | + ./dist + ./node_modules/.yarn-state.yml key: ${{ github.sha }} - # Set `ignore-scripts` to skip `prepublishOnly` because the release was built already in the previous job - - run: npm config set ignore-scripts true - name: Dry Run Publish # omit npm-token token to perform dry run publish - uses: MetaMask/action-npm-publish@v1.1.0 + uses: MetaMask/action-npm-publish@v4 + with: + slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} + subteam: S042S7RE4AE # @metamask-npm-publishers + env: + SKIP_PREPACK: true publish-npm: environment: npm-publish runs-on: ubuntu-latest needs: publish-npm-dry-run steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: ${{ github.sha }} - uses: actions/cache@v3 id: restore-build with: - path: ./dist + path: | + ./dist + ./node_modules/.yarn-state.yml key: ${{ github.sha }} - # Set `ignore-scripts` to skip `prepublishOnly` because the release was built already in the previous job - - run: npm config set ignore-scripts true - name: Publish - uses: MetaMask/action-npm-publish@v1.1.0 + 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 + + get-release-version: + runs-on: ubuntu-latest + needs: publish-npm + outputs: + RELEASE_VERSION: ${{ steps.get-release-version.outputs.RELEASE_VERSION }} + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.sha }} + - id: get-release-version + shell: bash + run: ./scripts/get.sh ".version" "RELEASE_VERSION" diff --git a/scripts/get.sh b/scripts/get.sh new file mode 100755 index 00000000..b1c6917d --- /dev/null +++ b/scripts/get.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -x +set -e +set -u +set -o pipefail + +KEY="${1}" +OUTPUT="${2}" + +if [[ -z $KEY ]]; then + echo "Error: KEY not specified." + exit 1 +fi + +if [[ -z $OUTPUT ]]; then + echo "Error: OUTPUT not specified." + exit 1 +fi + +echo "$OUTPUT=$(jq --raw-output "$KEY" package.json)" >> "$GITHUB_OUTPUT" From 84374b8f0721b0443ded6bb470ed7ef6b5dfc8eb Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Sun, 9 Jul 2023 20:44:35 -0700 Subject: [PATCH 3/3] Replace placeholders in README (#144) The module template README contains placeholder content that is designed to be replaced when a new library is created from the template. This updates the README to suit this library. --- README.md | 16 ++++------------ package.json | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f01e8b9d..72c87753 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,14 @@ -# MetaMask Module Template +# `@metamask/smart-transactions-controller` -This TypeScript module is maintained in the style of the MetaMask team. +Improves success rates for swaps by trialing transactions privately and finding minimum fees. ## Installation -`yarn add @metamask/this-module` +`yarn add @metamask/smart-transactions-controller` or -`npm install @metamask/this-module` - -## Usage - -_Add examples here_ - -## API - -_Add examples here_ +`npm install @metamask/smart-transactions-controller` ## Contributing diff --git a/package.json b/package.json index bc3d4f03..501d6b23 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@metamask/smart-transactions-controller", "version": "3.1.0", - "description": "MetaMask controller for Smart Transactions.", + "description": "Improves success rates for swaps by trialing transactions privately and finding minimum fees", "repository": { "type": "git", "url": "https://github.com/MetaMask/smart-transactions-controller.git"