Repository navigation
Add minimize-pragma workflow #6830
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # Keeps Solidity pragma floors minimal (`npm run pragma`), opening a PR when any can be lowered. | ||
| # | ||
| # SETUP (one-time, org admin): a short-lived GitHub App token is minted so the opened PR triggers CI | ||
| # (the default GITHUB_TOKEN can't — events it creates don't start workflow runs). Create a GitHub App | ||
| # with Contents + Pull requests set to Read-and-write, install it on this repo, and add two secrets: | ||
| # PRAGMA_BOT_APP_ID and PRAGMA_BOT_PRIVATE_KEY. Reuse an existing org CI-bot App if one exists. | ||
| name: minimize-pragma | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 6 * * 1' # Mondays 06:00 UTC | ||
| workflow_dispatch: {} | ||
|
|
||
| concurrency: | ||
| group: minimize-pragma | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read # checkout only; the App token pushes the branch and opens the PR | ||
|
|
||
| env: | ||
| NODE_OPTIONS: --max_old_space_size=8192 | ||
| DEFAULT_BRANCH: master | ||
|
|
||
| jobs: | ||
| minimize-pragma: | ||
| runs-on: ubuntu-latest | ||
|
Collaborator
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. No |
||
| if: github.event_name == 'workflow_dispatch' || github.repository == 'OpenZeppelin/openzeppelin-contracts' | ||
|
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. Why disable the cron if we aren't in vanilla? I'd like to symlink this into confidential and have the same behavior.
Member
Author
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. Yes I thought about that but I wanted something pretty scoped for this first try. If updated here we want to skip if upgradeable repo or other vanilla forks which didn't opt-in for that.
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. I believe that forks automatically have actions disabled. Upgradeable also has actions disabled. If a dev has explicitly enabled actions, I don't see why there would be an issue with running this weekly. |
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| with: | ||
| ref: ${{ env.DEFAULT_BRANCH }} | ||
| submodules: recursive # foundry libs, needed by the pragma tooling | ||
| # Read-only checkout: don't persist the token. The write-capable App token is minted after | ||
| # the build (below), so nothing usable sits in .git/config while untrusted deps run. | ||
| persist-credentials: false | ||
| - name: Set up environment | ||
| uses: ./.github/actions/setup | ||
| with: | ||
| foundry: 'on' # needed by the pragma scripts (see checks.yml) | ||
|
|
||
| - name: Minimize pragmas | ||
| run: npm run pragma | ||
|
Collaborator
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. Nit: might be worth running |
||
|
|
||
| - name: Detect changes | ||
| id: diff | ||
| continue-on-error: true # exits 1 when pragmas changed | ||
| run: git diff --quiet -- contracts | ||
|
Collaborator
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. When there's no diff the job exits early, but it doesn't close an already-open bot PR. If the pragmas get fixed manually on master (as in #6825) while the bot PR is open, that PR stays around with stale/conflicting changes and could get merged by mistake. Maybe close it ( Also, |
||
|
|
||
| # Minted after the build and only when there's a PR to open, so build deps never see it. | ||
|
Collaborator
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. "build deps never see it" isn't really true: To actually isolate the token, split into two jobs: one that runs |
||
| # Scoped to the two permissions needed, not everything the (possibly shared) App installation grants. | ||
| - name: Generate app token | ||
| if: steps.diff.outcome == 'failure' | ||
| id: app-token | ||
| uses: actions/create-github-app-token@v2 | ||
| with: | ||
| app-id: ${{ secrets.PRAGMA_BOT_APP_ID }} | ||
| private-key: ${{ secrets.PRAGMA_BOT_PRIVATE_KEY }} | ||
| permission-contents: write # push the automation branch | ||
| permission-pull-requests: write # open/update the PR | ||
|
|
||
| - name: Open or update PR | ||
| if: steps.diff.outcome == 'failure' | ||
| env: | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token }} # App token: opens the PR and lets its CI run | ||
| APP_SLUG: ${{ steps.app-token.outputs.app-slug }} | ||
| BRANCH: automation/minimize-pragma | ||
| BASE: ${{ env.DEFAULT_BRANCH }} | ||
| run: | | ||
| uid="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)" | ||
| git config user.name "${APP_SLUG}[bot]" | ||
| git config user.email "${uid}+${APP_SLUG}[bot]@users.noreply.github.com" | ||
| git switch -c "$BRANCH" | ||
| git add contracts | ||
| git commit -m "chore: minimize Solidity pragmas" | ||
| # Auth via the token in the remote URL, not persisted git credentials. | ||
|
Collaborator
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. Rather than embedding the token in the remote URL (where it ends up on the |
||
| git push --force "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" | ||
|
Collaborator
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. Two issues with the unconditional force-push:
Suggest comparing against |
||
| if [ -n "$(gh pr list --head "$BRANCH" --base "$BASE" --state open --json number --jq '.[0].number')" ]; then | ||
|
Collaborator
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. Only |
||
| echo "PR already open for $BRANCH -> $BASE; the force-push updated it." | ||
| else | ||
| gh pr create --base "$BASE" --head "$BRANCH" \ | ||
| --label ignore-changeset \ | ||
| --title "chore: minimize Solidity pragmas" \ | ||
| --body "Automated \`npm run pragma\`: lowers pragma floors to the lowest compiler that still builds each file." | ||
| fi | ||
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.
Nit:
${{ github.event.repository.default_branch }}avoids hardcodingmaster.