Skip to content

Commit d63fcbf

Browse files
authored
feat: new attribution github workflow (#9856)
## **Description** This pull request introduces a GitHub Action workflow dedicated to managing attributions effectively within our project. The key components of this new workflow include: - Local Scripts for Attributions Management: - `yarn build:attribution`: Updates attributions to reflect current dependencies. - `yarn test:attribution-check`: Checks if attributions are up-to-date with the latest changes. - GitHub Actions: - A check to ensure attributions are up-to-date on all pull requests. - An action that allows team members to update attributions directly by commenting `@metamskbot update-attributions` on any PR. ## **Related issues** Fixes: [#1550](MetaMask/mobile-planning#1550) ## **Manual testing steps** ### ***Locally*** - Run `yarn build:attribution` to update the attributions file. - Run `yarn test:attribution-check` to ensure all attributions are current. - ### ***On GitHub (CI/PR)*** - Open and push changes to a PR. - Intentionally remove an entry from attribution.txt to simulate an error. - Observe that CI fails due to missing attributions. - Comment `@metmaskbot update-attributions` on the PR. - A bot will respond with a thumbs up, followed by a comment indicating whether the attributions were successfully updated. For a practical demonstration, refer to the pull request in my fork: [PR Demonstration](cryptodev-2s#4) ### ***Note*** This functionality is currently operational only on a fork as it depends on the integration of the bot action into the develop branch. ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent b9bfc7c commit d63fcbf

File tree

8 files changed

+6013
-4009
lines changed

8 files changed

+6013
-4009
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check Attributions
2+
3+
on:
4+
push:
5+
branches: release/*
6+
pull_request:
7+
branches: release/*
8+
types:
9+
- opened
10+
- reopened
11+
- synchronize
12+
- ready_for_review
13+
14+
jobs:
15+
check-attributions:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version-file: '.nvmrc'
24+
cache: 'yarn'
25+
- name: Install dependencies from cache
26+
run: yarn --immutable
27+
- name: Check attributions changes
28+
run: yarn test:attribution-check
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
name: Update Attibutions
2+
3+
on:
4+
issue_comment:
5+
types: created
6+
7+
jobs:
8+
react-to-comment:
9+
name: React to the comment
10+
runs-on: ubuntu-latest
11+
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot update-attributions') }}
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
- name: React to the comment
16+
run: |
17+
gh api \
18+
--method POST \
19+
-H "Accept: application/vnd.github+json" \
20+
-H "X-GitHub-Api-Version: 2022-11-28" \
21+
"/repos/${REPO}/issues/comments/${COMMENT_ID}/reactions" \
22+
-f content='+1'
23+
env:
24+
COMMENT_ID: ${{ github.event.comment.id }}
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
REPO: ${{ github.repository }}
27+
28+
prepare:
29+
name: Prepare dependencies
30+
runs-on: ubuntu-latest
31+
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot update-attributions') }}
32+
outputs:
33+
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
- name: Checkout pull request
38+
run: gh pr checkout "${PR_NUMBER}"
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
PR_NUMBER: ${{ github.event.issue.number }}
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version-file: '.nvmrc'
46+
cache: 'yarn'
47+
- name: Install Yarn dependencies
48+
run: yarn --immutable
49+
- name: Get commit SHA
50+
id: commit-sha
51+
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
52+
53+
update-attributions:
54+
name: Update Attributions
55+
runs-on: ubuntu-latest
56+
needs:
57+
- prepare
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
- name: Checkout pull request
62+
run: gh pr checkout "${PR_NUMBER}"
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
PR_NUMBER: ${{ github.event.issue.number }}
66+
- name: Setup Node.js
67+
uses: actions/setup-node@v4
68+
with:
69+
node-version-file: '.nvmrc'
70+
cache: 'yarn'
71+
- name: Install dependencies from cache
72+
run: yarn --immutable --immutable-cache
73+
- name: Generate Atributions
74+
run: yarn build:attribution
75+
- name: Cache attributions file
76+
uses: actions/cache/save@v3
77+
with:
78+
path: attribution.txt
79+
key: cache-build-${{ needs.prepare.outputs.COMMIT_SHA }}
80+
81+
commit-updated-attributions:
82+
name: Commit the updated Attributions
83+
runs-on: ubuntu-latest
84+
needs:
85+
- prepare
86+
- update-attributions
87+
steps:
88+
- name: Checkout repository
89+
uses: actions/checkout@v4
90+
with:
91+
# Use PAT to ensure that the commit later can trigger status check workflows
92+
token: ${{ secrets.GITHUB_TOKEN }}
93+
- name: Checkout pull request
94+
run: gh pr checkout "${PR_NUMBER}"
95+
env:
96+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
PR_NUMBER: ${{ github.event.issue.number }}
98+
- name: Get commit SHA
99+
id: commit-sha
100+
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
101+
- name: Restore attributions file
102+
uses: actions/cache/restore@v3
103+
with:
104+
path: attribution.txt
105+
key: cache-build-${{ needs.prepare.outputs.COMMIT_SHA }}
106+
fail-on-cache-miss: true
107+
- name: Check whether there are attributions changes
108+
id: attributions-changes
109+
run: |
110+
if git diff --exit-code
111+
then
112+
echo "HAS_CHANGES=false" >> "$GITHUB_OUTPUT"
113+
else
114+
echo "HAS_CHANGES=true" >> "$GITHUB_OUTPUT"
115+
fi
116+
- name: Commit the updated attributions
117+
if: steps.attributions-changes.outputs.HAS_CHANGES == 'true'
118+
run: |
119+
git config --global user.name 'MetaMask Bot'
120+
git config --global user.email '[email protected]'
121+
git commit -am "Update Attributions"
122+
git push
123+
- name: Post comment
124+
run: |
125+
if [[ $HAS_CHANGES == 'true' ]]
126+
then
127+
gh pr comment "${PR_NUMBER}" --body 'Attributions updated'
128+
else
129+
gh pr comment "${PR_NUMBER}" --body 'No attributions changes'
130+
fi
131+
env:
132+
HAS_CHANGES: ${{ steps.attributions-changes.outputs.HAS_CHANGES }}
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
PR_NUMBER: ${{ github.event.issue.number }}
135+
136+
check-status:
137+
name: Check whether the attributions update succeeded
138+
runs-on: ubuntu-latest
139+
needs:
140+
- commit-updated-attributions
141+
outputs:
142+
PASSED: ${{ steps.set-output.outputs.PASSED }}
143+
steps:
144+
- name: Set PASSED output
145+
id: set-output
146+
run: echo "PASSED=true" >> "$GITHUB_OUTPUT"
147+
148+
failure-comment:
149+
name: Comment about the attributions update failure
150+
runs-on: ubuntu-latest
151+
needs:
152+
- check-status
153+
steps:
154+
- uses: actions/checkout@v4
155+
with:
156+
token: ${{ secrets.GITHUB_TOKEN }}
157+
- name: Post comment if the update failed
158+
run: |
159+
passed="${{ needs.check-status.outputs.PASSED }}"
160+
if [[ $passed != "true" ]]; then
161+
gh pr comment "${PR_NUMBER}" --body "Attributions update failed. You can [review the logs or retry the attributions update here](${ACTION_RUN_URL})"
162+
fi
163+
env:
164+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165+
PR_NUMBER: ${{ github.event.issue.number }}
166+
ACTION_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'

0 commit comments

Comments
 (0)