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

Fix/attributions #24867

Closed
wants to merge 33 commits into from
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
80f4d6a
feat: add new attributions workflow
cryptodev-2s May 6, 2024
4b82bba
fix: add missing runs-on on update-attributions gh action
cryptodev-2s May 6, 2024
4f86499
fix: update readme
cryptodev-2s May 7, 2024
ae202cd
feat: add attribution check gh action
cryptodev-2s May 7, 2024
2146983
fix: update check attribution action trigger
cryptodev-2s May 7, 2024
6fac431
fix: attributions check gh action
cryptodev-2s May 7, 2024
afec127
fix: check attribution gh action remove useless pr checkout by number
cryptodev-2s May 7, 2024
aba129c
fix: update attribution file
cryptodev-2s May 7, 2024
8dc080f
fix: remove fork check on attributions update
cryptodev-2s May 7, 2024
3c8d14e
fix: attribution script
cryptodev-2s May 9, 2024
256fb51
fix: restore .gitignore
cryptodev-2s May 9, 2024
56f6d84
Update LavaMoat policies
metamaskbot May 9, 2024
ccc3bd6
fix: run yarn dedupe
cryptodev-2s May 9, 2024
8a6ee29
Update LavaMoat policies
metamaskbot May 9, 2024
ee20d14
fix: update attributions
cryptodev-2s May 9, 2024
2ecc8f0
fix: attribution script to use node instead of python
cryptodev-2s May 9, 2024
91051c2
fix: update attributions
cryptodev-2s May 14, 2024
469efeb
fix: update attribution
cryptodev-2s May 16, 2024
d3373d1
Extract yarnrc override script
cryptodev-2s May 20, 2024
9cd958a
Merge remote-tracking branch 'origin/develop' into fix/attributions
cryptodev-2s May 20, 2024
2d31777
Update attributions
cryptodev-2s May 20, 2024
49960b2
Merge remote-tracking branch 'origin/develop' into fix/attributions
cryptodev-2s May 23, 2024
1005376
fix: attributions
cryptodev-2s May 23, 2024
f05f31d
Merge branch 'develop' into fix/attributions
cryptodev-2s May 23, 2024
cf29c2c
fix: refactor check attribution action
cryptodev-2s May 29, 2024
41493b4
Merge remote-tracking branch 'origin/develop' into fix/attributions
cryptodev-2s May 29, 2024
7de46d4
fix: update attribution file
cryptodev-2s May 29, 2024
3a8b245
fix: attribution typo
cryptodev-2s May 29, 2024
4aeb511
fix: attribution typo
cryptodev-2s May 29, 2024
b2ecf5a
fix: attribution check
cryptodev-2s May 29, 2024
5a61bba
Merge branch 'develop' into fix/attributions
cryptodev-2s May 29, 2024
d131569
Update LavaMoat policies
metamaskbot May 29, 2024
db18397
Merge branch 'develop' into fix/attributions
cryptodev-2s May 29, 2024
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
52 changes: 52 additions & 0 deletions .github/workflows/check-attribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Check attribution

on:
pull_request:
branches:
- develop
types:
- opened
- synchronize

jobs:
prepare:
name: Prepare dependencies
runs-on: ubuntu-latest
outputs:
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install Yarn dependencies
run: yarn --immutable
- name: Get commit SHA
id: commit-sha
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

generate-and-validate-attribution:
name: Generate and Validate Attribution
runs-on: ubuntu-latest
needs: prepare
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
COMMIT_SHA: ${{ needs.prepare.outputs.COMMIT_SHA }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies from cache
run: yarn --immutable --immutable-cache
- name: Generate Attribution
run: yarn generate:attribution
- name: Check attribution changes
run: yarn test:attribution-check
166 changes: 166 additions & 0 deletions .github/workflows/update-attribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: Update Attibutions

on:
issue_comment:
types: created

jobs:
react-to-comment:
name: React to the comment
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot update-attribution') }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: React to the comment
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPO}/issues/comments/${COMMENT_ID}/reactions" \
-f content='+1'
env:
COMMENT_ID: ${{ github.event.comment.id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}

prepare:
name: Prepare dependencies
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot update-attribution') }}
outputs:
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install Yarn dependencies
run: yarn --immutable
- name: Get commit SHA
id: commit-sha
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

update-attribution:
name: Update Attribution
runs-on: ubuntu-latest
needs:
- prepare
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies from cache
run: yarn --immutable --immutable-cache
- name: Generate Atributions
run: yarn generate:attribution
- name: Cache attribution file
uses: actions/cache/save@v3
with:
path: attribution.txt
key: cache-build-${{ needs.prepare.outputs.COMMIT_SHA }}

commit-updated-attribution:
name: Commit the updated Attribution
runs-on: ubuntu-latest
needs:
- prepare
- update-attribution
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Use PAT to ensure that the commit later can trigger status check workflows
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout pull request
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
- name: Get commit SHA
id: commit-sha
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Restore attribution file
uses: actions/cache/restore@v3
with:
path: attribution.txt
key: cache-build-${{ needs.prepare.outputs.COMMIT_SHA }}
fail-on-cache-miss: true
- name: Check whether there are attribution changes
id: attribution-changes
run: |
if git diff --exit-code
then
echo "HAS_CHANGES=false" >> "$GITHUB_OUTPUT"
else
echo "HAS_CHANGES=true" >> "$GITHUB_OUTPUT"
fi
- name: Commit the updated attribution
if: steps.attribution-changes.outputs.HAS_CHANGES == 'true'
run: |
git config --global user.name 'MetaMask Bot'
git config --global user.email '[email protected]'
git commit -am "Update Attribution"
git push
- name: Post comment
run: |
if [[ $HAS_CHANGES == 'true' ]]
then
gh pr comment "${PR_NUMBER}" --body 'Attribution updated'
else
gh pr comment "${PR_NUMBER}" --body 'No attribution changes'
fi
env:
HAS_CHANGES: ${{ steps.attribution-changes.outputs.HAS_CHANGES }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}

check-status:
name: Check whether the attribution update succeeded
runs-on: ubuntu-latest
needs:
- commit-updated-attribution
outputs:
PASSED: ${{ steps.set-output.outputs.PASSED }}
steps:
- name: Set PASSED output
id: set-output
run: echo "PASSED=true" >> "$GITHUB_OUTPUT"

failure-comment:
name: Comment about the attribution update failure
runs-on: ubuntu-latest
needs:
- check-status
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Post comment if the update failed
run: |
passed="${{ needs.check-status.outputs.PASSED }}"
if [[ $passed != "true" ]]; then
gh pr comment "${PR_NUMBER}" --body "Attribution update failed. You can [review the logs or retry the attribution update here](${ACTION_RUN_URL})"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
ACTION_RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ test-results/
!.yarn/releases
!.yarn/sdks
!.yarn/versions
**/.yarn/*

# MMI Playwright
public/playwright
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -219,6 +219,9 @@ Whenever you change dependencies (adding, removing, or updating, either in `pack
- `rm -rf node_modules/ && yarn && yarn lavamoat:auto`
- Keep in mind that any kind of dynamic import or dynamic use of globals may elude LavaMoat's static analysis.
Refer to the LavaMoat documentation or ask for help if you run into any issues.
- The Attribution file
- If you are a MetaMask team member and your PR is on a repository branch, you can use the bot command `@metamaskbot update-attribution` to ask the MetaMask bot to automatically update the attribution file for you.
- Manual update: run `yarn generate:attribution`.

## Architecture

33,102 changes: 33,102 additions & 0 deletions attribution.txt

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions development/attribution-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
yarn generate:attribution

ATTRIBUTION_TXT="./attribution.txt"

# check to see if there's changed to ATTRIBUTION_TXT
if ! git diff --exit-code "$ATTRIBUTION_TXT"; then
echo "attribution.txt has changed!"
echo "run \`yarn generate:attribution\` and commit changes."
exit 1
fi
44 changes: 44 additions & 0 deletions development/generate-attribution.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

SCRIPT_DIRECTORY=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
PROJECT_DIRECTORY=$(cd "${SCRIPT_DIRECTORY}" && cd ../ && pwd)

# Generate attribution file
#
# Generate the file `attribution.txt`, which is a list of packages that we use
# along with their licenses. This should include only production dependencies.
main() {
# Switching to the project directory explicitly, so that we can use paths
# relative to the project root irrespective of where this script was run.
cd "${PROJECT_DIRECTORY}"

# Save .yarnrc.yml to temp file
local tmp=".yarnrc.tmp.yml"
cp ".yarnrc.yml" "$tmp"

# Remove the .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs plugin from yarnrc.
# This is a workaround for an issue where the allow scripts plugin, defined in devDependencies,
# is not needed for the attribution generation script.
node "${SCRIPT_DIRECTORY}/generate-attribution/remove-yarn-allow-scripts-plugin.js" "${PROJECT_DIRECTORY}/${tmp}"

yarn workspaces focus --production

# Restore original .yarnrc.yml
mv "$tmp" ".yarnrc.yml"

# Change directory to the sub-project
cd "${SCRIPT_DIRECTORY}/generate-attribution"

# Install sub-project that just contains attribution generation package
# so that it can be used without installing `devDependencies` in root.
yarn && yarn allow-scripts

# Generate attribution file
yarn generate-attribution -o "${PROJECT_DIRECTORY}" -b "${PROJECT_DIRECTORY}"
}

main "$@"
22 changes: 22 additions & 0 deletions development/generate-attribution/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "metamask-extension-generate-attribution",
"version": "1.0.0",
"private": true,
"scripts": {
"generate:attribution": "generate-attribution"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^3.0.4",
"@lavamoat/preinstall-always-fail": "^2.0.0",
"@metamask/oss-attribution-generator": "^2.0.2"
},
"engines": {
"node": ">= 20",
"yarn": "^4.0.2"
},
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require('fs');

const targetPath = '.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs';
const yarnrcPath = process.argv[2];
const lines = fs.readFileSync(yarnrcPath, 'utf8').split('\n');
let inPluginsSection = false;
let inTargetPluginBlock = false;
const result = [];
lines.forEach((line) => {
if (line.trim() === 'plugins:') {
inPluginsSection = true;
result.push(line);
return;
}
if (inPluginsSection) {
if (line.trim().startsWith('- path:') && line.includes(targetPath)) {
inTargetPluginBlock = true;
return;
}
if (line.trim().startsWith('- path:')) {
inTargetPluginBlock = false;
}
if (line.trim() === '' || !line.startsWith(' ')) {
inPluginsSection = false;
inTargetPluginBlock = false;
}
if (!inTargetPluginBlock) {
result.push(line);
}
} else {
result.push(line);
}
});
fs.writeFileSync('.yarnrc.yml', result.join('\n'));
2,129 changes: 2,129 additions & 0 deletions development/generate-attribution/yarn.lock

Large diffs are not rendered by default.

281 changes: 173 additions & 108 deletions lavamoat/browserify/beta/policy.json

Large diffs are not rendered by default.

297 changes: 181 additions & 116 deletions lavamoat/browserify/desktop/policy.json

Large diffs are not rendered by default.

297 changes: 181 additions & 116 deletions lavamoat/browserify/flask/policy.json

Large diffs are not rendered by default.

297 changes: 181 additions & 116 deletions lavamoat/browserify/main/policy.json

Large diffs are not rendered by default.

297 changes: 181 additions & 116 deletions lavamoat/browserify/mmi/policy.json

Large diffs are not rendered by default.

1,368 changes: 768 additions & 600 deletions lavamoat/build-system/policy.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
"dapp-chain": "GANACHE_ARGS='-b 2' concurrently -k -n ganache,dapp -p '[{time}][{name}]' 'yarn ganache:start' 'sleep 5 && yarn dapp'",
"forwarder": "node ./development/static-server.js ./node_modules/@metamask/forwarder/dist/ --port 9010",
"dapp-forwarder": "concurrently -k -n forwarder,dapp -p '[{time}][{name}]' 'yarn forwarder' 'yarn dapp'",
"test:attribution-check": "./development/attribution-check.sh",
"test:unit": "node ./test/run-unit-tests.js --mocha --jestGlobal --jestDev",
"test:unit:jest": "node ./test/run-unit-tests.js --jestGlobal --jestDev",
"test:unit:jest:watch": "node --inspect ./node_modules/.bin/jest --watch",
@@ -94,6 +95,7 @@
"storybook:deploy": "storybook-to-ghpages --existing-output-dir storybook-build --remote storybook --branch master",
"update-changelog": "auto-changelog update",
"generate:migration": "./development/generate-migration.sh",
"generate:attribution": "./development/generate-attribution.sh",
"lavamoat:build": "lavamoat development/build/index.js --policy lavamoat/build-system/policy.json --policyOverride lavamoat/build-system/policy-override.json",
"lavamoat:build:auto": "yarn lavamoat:build --writeAutoPolicy",
"lavamoat:debug:build": "yarn lavamoat:build --writeAutoPolicyDebug --policydebug lavamoat/build-system/policy-debug.json",
@@ -703,7 +705,10 @@
"@lavamoat/lavadome-react>@lavamoat/preinstall-always-fail": false,
"tsx>esbuild": false,
"@metamask/eth-trezor-keyring>@trezor/connect-web>@trezor/connect>@trezor/protobuf>protobufjs": false,
"firebase>@firebase/firestore>@grpc/proto-loader>protobufjs": false
"firebase>@firebase/firestore>@grpc/proto-loader>protobufjs": false,
"@lavamoat/lavadome-core>@lavamoat/preinstall-always-fail": false,
"@metamask/desktop>ws>bufferutil": false,
"@metamask/desktop>ws>utf-8-validate": false
}
},
"packageManager": "yarn@4.0.2"
3 changes: 2 additions & 1 deletion test/e2e/mmi/specs/navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@ const supportContactUs =
const mmiHomePage = 'https://metamask.io/institutions/';
const privacyAndPolicy = 'https://consensys.io/privacy-policy';
const openSeaTermsOfUse = 'https://opensea.io/securityproviderterms';
const metamaskAttributions = 'https://metamask.io/attributions/';
const metamaskAttributions =
'https://github.com/MetaMask/metamask-extension/blob/develop/attribution.txt';
const termsOfUse = 'https://consensys.io/terms-of-use';
const learnMoreArticles = 'https://support.metamask.io/hc/en-us/articles';

Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@ Step,Test Steps,Test Data,Expected Result,Notes
9,Click on the link for the 'Privacy policy',,Privacy policy 'https://consensys.io/privacy-policy' page is loaded,Critical because it's the only way to access privacy policy
10,Click on the link for the 'Terms of use',,Terms of use page 'https://consensys.io/terms-of-use' is loaded,
11,Click on the link for the 'Visit our support center',,Support page 'https://support.metamask.io/hc/en-us' is loaded,
12,Click on the link for the 'Attributions',,Attributions 'https://metamask.io/attributions/' page is loaded,
12,Click on the link for the 'Attributions',,Attributions 'https://github.com/MetaMask/metamask-extension/blob/develop/attribution.txt' page is loaded,
13,Click on the link for the 'Visit our website',,Visit our website 'https://metamask.io/' page is loaded,
14,Click on the link for the 'Contact us',,Contact us 'https://support.metamask.io/hc/en-us' code page is loaded,
14,Click on the link for the 'Contact us',,Contact us 'https://support.metamask.io/hc/en-us' code page is loaded,
2 changes: 1 addition & 1 deletion ui/pages/settings/info-tab/info-tab.component.js
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ export default class InfoTab extends PureComponent {
<div ref={this.settingsRefs[4]} className="info-tab__link-item">
<Button
type="link"
href="https://metamask.io/attributions.html"
href="https://github.com/MetaMask/metamask-extension/blob/develop/attribution.txt"
target="_blank"
rel="noopener noreferrer"
className="info-tab__link-text"
2 changes: 1 addition & 1 deletion ui/pages/settings/info-tab/info-tab.test.tsx
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ describe('InfoTab', () => {
const attributionsLink = getByText('Attributions');
expect(attributionsLink).toHaveAttribute(
'href',
'https://metamask.io/attributions.html',
'https://github.com/MetaMask/metamask-extension/blob/develop/attribution.txt',
);
});

7,298 changes: 3,954 additions & 3,344 deletions yarn.lock

Large diffs are not rendered by default.