-
-
Notifications
You must be signed in to change notification settings - Fork 279
feat: add Update Changelogs workflow with auto-changelog v6 --checkDeps #8443
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
Changes from all commits
61175c2
a83983a
02fd302
14d0298
9c0924f
f3192c6
925ca11
a62d2ee
b6cf542
b516c86
455620a
9069a65
5a137b1
61a4b9e
f4aabbb
e8bd7be
30eec0c
b20f53e
29a5a04
d29dc62
567a53b
0959ecc
bbac608
aa78ed8
f0ea391
219277f
7fc7da9
d307b94
34f945b
3295258
1cf4de8
4f7aeb0
ccae16b
c6e02fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
mcmire marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| name: Update Changelogs | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: | ||
| - created | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| types: | ||
| - opened | ||
|
|
||
| concurrency: | ||
| group: update-changelogs-${{ github.event.issue.number || github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| is-fork: | ||
| name: Determine whether this PR is from a fork | ||
| if: github.event_name == 'pull_request' || (github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot update-changelogs')) | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| is-fork: ${{ steps.is-fork.outputs.is-fork }} | ||
| steps: | ||
| - name: Determine whether this PR is from a fork | ||
| id: is-fork | ||
| run: | | ||
| IS_FORK="$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "$PR_NUMBER" --repo "$GITHUB_REPOSITORY")" | ||
| echo "is-fork=$IS_FORK" >> "$GITHUB_OUTPUT" | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} | ||
|
|
||
| is-release: | ||
| name: Determine whether this PR is a release PR | ||
| needs: is-fork | ||
| if: needs.is-fork.outputs.is-fork == 'false' | ||
| runs-on: ubuntu-latest | ||
| environment: default-branch | ||
| outputs: | ||
| is-release: ${{ steps.is-release.outputs.IS_RELEASE }} | ||
| head-sha: ${{ steps.pr-info.outputs.pr-head-sha }} | ||
| head-ref: ${{ steps.pr-info.outputs.pr-head-ref }} | ||
| base-ref: ${{ steps.pr-info.outputs.pr-base-ref }} | ||
| merge-base: ${{ steps.merge-base.outputs.merge-base }} | ||
| steps: | ||
| - name: Get pull request info | ||
| id: pr-info | ||
| env: | ||
| GH_TOKEN: ${{ secrets.UPDATE_CHANGELOG_TOKEN }} | ||
| PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} | ||
| run: | | ||
| gh pr view "$PR_NUMBER" \ | ||
| --repo "$GITHUB_REPOSITORY" \ | ||
| --json baseRefName,headRefOid,headRefName,title \ | ||
| --jq '"pr-base-ref=\(.baseRefName)\npr-head-sha=\(.headRefOid)\npr-head-ref=\(.headRefName)\npr-title=\(.title)"' \ | ||
| >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| fetch-depth: 0 | ||
| ref: ${{ steps.pr-info.outputs.pr-head-sha }} | ||
|
|
||
| - name: Get merge base | ||
|
Mrtenz marked this conversation as resolved.
Dismissed
Mrtenz marked this conversation as resolved.
Dismissed
|
||
| id: merge-base | ||
| shell: bash | ||
| env: | ||
| BASE_REF: ${{ steps.pr-info.outputs.pr-base-ref }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| MERGE_BASE=$(git merge-base HEAD "refs/remotes/origin/$BASE_REF") | ||
| echo "merge-base=$MERGE_BASE" >> "$GITHUB_OUTPUT" | ||
|
cursor[bot] marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge base is needed to determine the before commit for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense! |
||
|
|
||
| - name: Check if the pull request is a release | ||
| id: is-release | ||
| uses: MetaMask/action-is-release@v2 | ||
| with: | ||
| commit-starts-with: ${{ vars.RELEASE_COMMIT_PREFIX }} | ||
| commit-message: ${{ steps.pr-info.outputs.pr-title }} | ||
| before: ${{ steps.merge-base.outputs.merge-base }} | ||
| skip-checkout: true | ||
|
|
||
| react-to-comment: | ||
| name: React to the comment | ||
| needs: is-release | ||
| if: needs.is-release.outputs.is-release == 'true' && github.event_name == 'issue_comment' | ||
| runs-on: ubuntu-latest | ||
| environment: default-branch | ||
| continue-on-error: true | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| - 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 }} | ||
| GH_TOKEN: ${{ secrets.UPDATE_CHANGELOG_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
|
|
||
| update-changelogs: | ||
| name: Update changelogs | ||
| needs: is-release | ||
| if: ${{ needs.is-release.outputs.is-release == 'true' }} | ||
| runs-on: ubuntu-latest | ||
| environment: default-branch | ||
| env: | ||
| PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| token: ${{ secrets.UPDATE_CHANGELOG_TOKEN }} | ||
|
|
||
| - name: Checkout pull request | ||
| env: | ||
| PR_HEAD_SHA: ${{ needs.is-release.outputs.head-sha }} | ||
| PR_BASE_REF: ${{ needs.is-release.outputs.base-ref }} | ||
| run: | | ||
| git fetch --no-tags origin "$PR_HEAD_SHA" | ||
| git fetch --no-tags origin "$PR_BASE_REF" | ||
| git checkout --detach "$PR_HEAD_SHA" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommended by CodeQL. |
||
|
|
||
| - name: Setup environment | ||
| uses: MetaMask/action-checkout-and-setup@v3 | ||
| with: | ||
| is-high-risk-environment: false | ||
|
|
||
| - name: Ensure required dependency bump entries exist across all changelogs | ||
| id: update-changelogs | ||
| env: | ||
| MERGE_BASE: ${{ needs.is-release.outputs.merge-base }} | ||
| run: yarn changelog:validate --checkDeps --fix --currentPr "$PR_NUMBER" --fromRef "$MERGE_BASE" | ||
| continue-on-error: true | ||
|
|
||
| - name: Commit and push updated changelogs | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| id: push-changes | ||
| env: | ||
| PR_HEAD_REF: ${{ needs.is-release.outputs.head-ref }} | ||
| run: | | ||
| if git diff --quiet; then | ||
|
mcmire marked this conversation as resolved.
|
||
| echo "changes-pushed=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| git diff --stat | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
Mrtenz marked this conversation as resolved.
|
||
| git add -- '**/CHANGELOG.md' | ||
| git commit -m "chore: Update dependency bump changelog entries" | ||
| git push origin "HEAD:$PR_HEAD_REF" | ||
|
|
||
| echo "changes-pushed=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Comment result | ||
| if: always() | ||
| uses: actions/github-script@v9 | ||
| env: | ||
| CHANGES_PUSHED: ${{ steps.push-changes.outputs.changes-pushed }} | ||
| PUSH_CHANGES_OUTCOME: ${{ steps.push-changes.outcome }} | ||
| UPDATE_CHANGELOGS_OUTCOME: ${{ steps.update-changelogs.outcome }} | ||
| PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} | ||
| with: | ||
| github-token: ${{ secrets.UPDATE_CHANGELOG_TOKEN }} | ||
| script: | | ||
| const { | ||
| CHANGES_PUSHED, | ||
| PUSH_CHANGES_OUTCOME, | ||
| UPDATE_CHANGELOGS_OUTCOME, | ||
| PR_NUMBER, | ||
| } = process.env; | ||
|
|
||
| // List and minimize any existing changelog update comments. | ||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: process.env.PR_NUMBER, | ||
| }); | ||
|
|
||
| for (const comment of comments) { | ||
| if (comment.body.includes('<!-- Changelog update comment -->')) { | ||
| await github.graphql(` | ||
| mutation($commentId: ID!, $classifier: ReportedContentClassifiers!) { | ||
| minimizeComment(input: {subjectId: $commentId, classifier: $classifier}) { | ||
| minimizedComment { | ||
| isMinimized | ||
| } | ||
| } | ||
| } | ||
| `, { | ||
| commentId: comment.node_id, | ||
| classifier: 'OUTDATED', | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function getCommentBody() { | ||
| if (CHANGES_PUSHED === 'true' && UPDATE_CHANGELOGS_OUTCOME === 'failure') { | ||
| return `⚠️ Changelogs updated and pushed, but some validation errors remain. Check the [workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.`; | ||
| } else if (CHANGES_PUSHED === 'true') { | ||
| return '✅ Changelogs updated and pushed.'; | ||
| } else if (PUSH_CHANGES_OUTCOME === 'failure') { | ||
| return `❌ Failed to push changelog fixes. Check the [workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.`; | ||
| } else if (UPDATE_CHANGELOGS_OUTCOME === 'failure') { | ||
| return `❌ Changelog validation failed. Check the [workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.`; | ||
| } else if (UPDATE_CHANGELOGS_OUTCOME === 'skipped' || PUSH_CHANGES_OUTCOME === 'skipped') { | ||
| return `❌ Workflow failed before changelog validation. Check the [workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.`; | ||
| } else { | ||
| return '✅ No changelog changes needed.'; | ||
| } | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: process.env.PR_NUMBER, | ||
| body: `${getCommentBody()}\n\n<!-- Changelog update comment -->`, | ||
| }); | ||
|
Mrtenz marked this conversation as resolved.
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actions don't have access to
varsdirectly.