-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ci: refactor maintainer_*.yml workflows to use new helper actions #35110
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 |
|---|---|---|
|
|
@@ -23,19 +23,10 @@ jobs: | |
| COMMENT_REVIEW: ${{ github.event.review.body }} | ||
| PR_NUMBER: ${{ github.event.issue.number }}${{ github.event.pull_request.number }} | ||
| HAS_DELEGATED_LABEL: ${{ contains(github.event.issue.labels.*.name, 'delegated') }} | ||
| HAS_TRIAGE_SECRET: ${{ secrets.MATHLIB_TRIAGE_APP_ID != '' }} | ||
| name: Add ready-to-merge or delegated label | ||
| runs-on: ubuntu-latest | ||
| if: github.repository == 'leanprover-community/mathlib4' | ||
| steps: | ||
| - name: Generate app token | ||
| if: ${{ env.HAS_TRIAGE_SECRET == 'true' }} | ||
| id: app-token | ||
| uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1 | ||
| with: | ||
| app-id: ${{ secrets.MATHLIB_TRIAGE_APP_ID }} | ||
| private-key: ${{ secrets.MATHLIB_TRIAGE_PRIVATE_KEY }} | ||
|
|
||
| - name: Find bors merge/delegate | ||
| id: merge_or_delegate | ||
| run: | | ||
|
|
@@ -72,142 +63,29 @@ jobs: | |
| then | ||
| printf $'bot=true\n' | ||
| printf $'bot=true\n' >> "${GITHUB_OUTPUT}" | ||
| BOT='true' | ||
| else | ||
| printf $'bot=false\n' | ||
| printf $'bot=false\n' >> "${GITHUB_OUTPUT}" | ||
| BOT='false' | ||
| fi | ||
|
|
||
| # write an artifact with all data needed below if we don't have access to necessary secrets | ||
| if [[ -z '${{ secrets.MATHLIB_TRIAGE_APP_ID }}' ]] | ||
| then | ||
| printf 'No access to secrets, writing to file.\n' | ||
| jq -n \ | ||
| --arg author "${AUTHOR}" \ | ||
| --arg pr_number "${PR_NUMBER}" \ | ||
| --arg comment "${COMMENT}" \ | ||
| --arg bot "${BOT}" \ | ||
| --arg remove_labels "${remove_labels}" \ | ||
| --arg m_or_d "${m_or_d}" \ | ||
| '{ | ||
| author: $author, | ||
| pr_number: $pr_number, | ||
| comment: $comment, | ||
| bot: $bot, | ||
| remove_labels: $remove_labels, | ||
| m_or_d: $m_or_d, | ||
| }' > artifact-data.json | ||
| echo "Generated JSON artifact:" | ||
| cat artifact-data.json | ||
|
|
||
| printf 'secrets=' >> "${GITHUB_OUTPUT}" | ||
| exit 0 | ||
| else | ||
| printf 'secrets=true\n' >> "${GITHUB_OUTPUT}" | ||
| fi | ||
|
|
||
| # upload artifact if we have no access to secrets | ||
| - if: ${{ steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' || ! steps.merge_or_delegate.outputs.removeLabels == '') }} | ||
| name: Upload artifact | ||
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 | ||
| with: | ||
| name: workflow-data | ||
| path: artifact-data.json | ||
| retention-days: 5 | ||
|
|
||
| # Run the following steps only if we have access to secrets / write perms on GITHUB_TOKEN | ||
| - name: Check whether user is a mathlib admin | ||
| id: user_permission | ||
| if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' || ! steps.merge_or_delegate.outputs.removeLabels == '') }} | ||
| uses: actions-cool/check-user-permission@7b90a27f92f3961b368376107661682c441f6103 # v2.3.0 | ||
| with: | ||
| require: 'admin' | ||
|
|
||
| - name: Add ready-to-merge or delegated label | ||
| id: add_label | ||
| if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' && | ||
| ( steps.user_permission.outputs.require-result == 'true' || | ||
| steps.merge_or_delegate.outputs.bot == 'true' )) }} | ||
| uses: octokit/request-action@dad4362715b7fb2ddedf9772c8670824af564f0d # v2.4.0 | ||
| with: | ||
| route: POST /repos/:repository/issues/:issue_number/labels | ||
| # Unexpected input warning from the following is expected: | ||
| # https://github.com/octokit/request-action?tab=readme-ov-file#warnings | ||
| repository: ${{ github.repository }} | ||
| issue_number: ${{ github.event.issue.number }}${{ github.event.pull_request.number }} | ||
| labels: '["${{ steps.merge_or_delegate.outputs.mOrD }}"]' | ||
| env: | ||
| # The create-github-app-token README states that this token is masked and will not be logged accidentally. | ||
| GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | ||
|
|
||
| - if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' && | ||
| ( steps.user_permission.outputs.require-result == 'true' || | ||
| steps.merge_or_delegate.outputs.bot == 'true' )) }} | ||
| id: remove_labels | ||
| name: Remove "awaiting-author" and "maintainer-merge" | ||
| # we use curl rather than octokit/request-action so that the job won't fail | ||
| # (and send an annoying email) if the labels don't exist | ||
| run: | | ||
| for label in awaiting-author maintainer-merge; do | ||
| curl --request DELETE \ | ||
| --url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}${{ github.event.pull_request.number }}/labels/${label}" \ | ||
| --header 'authorization: Bearer ${{ steps.app-token.outputs.token }}' | ||
| done | ||
|
|
||
| - name: On bors r/d-, remove ready-to-merge or delegated label | ||
| if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.removeLabels == '' && | ||
| steps.user_permission.outputs.require-result == 'true') }} | ||
| # we use curl rather than octokit/request-action so that the job won't fail | ||
| # (and send an annoying email) if the labels don't exist | ||
| - if: ${{ ! steps.merge_or_delegate.outputs.mOrD == '' || ! steps.merge_or_delegate.outputs.removeLabels == '' }} | ||
| name: Prepare bridge outputs | ||
| run: | | ||
| for label in ready-to-merge delegated; do | ||
| curl --request DELETE \ | ||
| --url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}${{ github.event.pull_request.number }}/labels/${label}" \ | ||
| --header 'authorization: Bearer ${{ steps.app-token.outputs.token }}' | ||
| done | ||
|
|
||
| - name: Set up Python | ||
| if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' && | ||
| ( steps.user_permission.outputs.require-result == 'true' || | ||
| steps.merge_or_delegate.outputs.bot == 'true' )) }} | ||
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | ||
| jq -n \ | ||
| --arg bot "${{ steps.merge_or_delegate.outputs.bot }}" \ | ||
| --arg removeLabels "${{ steps.merge_or_delegate.outputs.removeLabels }}" \ | ||
| --arg mOrD "${{ steps.merge_or_delegate.outputs.mOrD }}" \ | ||
| '{ | ||
| bot: $bot, | ||
| removeLabels: $removeLabels, | ||
| mOrD: $mOrD, | ||
| }' > bridge-outputs.json | ||
|
|
||
| - if: ${{ ! steps.merge_or_delegate.outputs.mOrD == '' || ! steps.merge_or_delegate.outputs.removeLabels == '' }} | ||
| name: Emit bridge artifact | ||
| uses: leanprover-community/privilege-escalation-bridge/emit@v1 | ||
| with: | ||
| python-version: '3.x' | ||
|
|
||
| - name: Install dependencies | ||
| if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' && | ||
| ( steps.user_permission.outputs.require-result == 'true' || | ||
| steps.merge_or_delegate.outputs.bot == 'true' )) }} | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install zulip | ||
|
|
||
| - if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' && | ||
| ( steps.user_permission.outputs.require-result == 'true' || | ||
| steps.merge_or_delegate.outputs.bot == 'true' )) }} | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| ref: master | ||
| sparse-checkout: | | ||
| scripts/zulip_emoji_reactions.py | ||
|
|
||
| - name: update zulip emoji reactions | ||
|
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. I don't see where this has been moved to? Why is it that this used to be present in both workflows?
Contributor
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. Good catch! I need to add these back since they were used to add the :bors: and maintainer merge emoji reactions. |
||
| if: ${{ ! steps.merge_or_delegate.outputs.secrets == '' && | ||
| (! steps.merge_or_delegate.outputs.mOrD == '' && | ||
| ( steps.user_permission.outputs.require-result == 'true' || | ||
| steps.merge_or_delegate.outputs.bot == 'true' )) }} | ||
| env: | ||
| ZULIP_API_KEY: ${{ secrets.ZULIP_API_KEY }} | ||
| ZULIP_EMAIL: github-mathlib4-bot@leanprover.zulipchat.com | ||
| ZULIP_SITE: https://leanprover.zulipchat.com | ||
| run: | | ||
| python scripts/zulip_emoji_reactions.py "$ZULIP_API_KEY" "$ZULIP_EMAIL" "$ZULIP_SITE" "${{ steps.merge_or_delegate.outputs.mOrD }}" "${{ steps.merge_or_delegate.outputs.mOrD }}" "${{ github.event.issue.number }}${{ github.event.pull_request.number }}" | ||
| artifact: workflow-data | ||
| outputs_file: bridge-outputs.json | ||
| include_event: minimal | ||
| retention_days: 5 | ||
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.
I will change this
uses(and the reference in the other file to/consume) to point to a specific commit after I'm more confident that the actions are stable.