handle concurrence in bot #247
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Assign XLS Number | |
| on: | |
| pull_request_target: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| concurrency: | |
| group: assign-xls-number-${{ github.repository }} | |
| cancel-in-progress: false | |
| jobs: | |
| assign-xls-number: | |
| runs-on: ubuntu-latest | |
| name: Assign XLS Number to Draft | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Checkout script from base branch | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.pull_request.base.ref }} | |
| sparse-checkout: | | |
| .github/scripts/assign_xls_number.py | |
| sparse-checkout-cone-mode: false | |
| path: base-repo | |
| - name: Get added files | |
| id: added-files | |
| uses: tj-actions/changed-files@v47 | |
| with: | |
| files: | | |
| XLS-draft*/README.md | |
| xls-draft*/README.md | |
| # Only look at added files, not modified ones | |
| include_all_old_new_renamed_files: false | |
| - name: Check for draft XLS files | |
| id: check-drafts | |
| run: | | |
| ADDED_FILES="${{ steps.added-files.outputs.added_files }}" | |
| echo $ADDED_FILES | |
| if [ -z "$ADDED_FILES" ]; then | |
| echo "No XLS draft files added in this PR" | |
| echo "has_drafts=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Found draft XLS files: $ADDED_FILES" | |
| echo "has_drafts=true" >> $GITHUB_OUTPUT | |
| echo "draft_files=$ADDED_FILES" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Python | |
| if: steps.check-drafts.outputs.has_drafts == 'true' | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Assign XLS number | |
| if: steps.check-drafts.outputs.has_drafts == 'true' | |
| id: assign-number | |
| env: | |
| REPO_ROOT: ${{ github.workspace }} | |
| run: | | |
| echo ${{ steps.check-drafts.outputs.draft_files }} | |
| python base-repo/.github/scripts/assign_xls_number.py ${{ steps.check-drafts.outputs.draft_files }} | |
| - name: Check for existing assignment comment | |
| if: steps.check-drafts.outputs.has_drafts == 'true' | |
| id: find-comment | |
| uses: peter-evans/find-comment@v4 | |
| with: | |
| issue-number: ${{ github.event.pull_request.number }} | |
| comment-author: "github-actions[bot]" | |
| body-includes: "XLS Number Assignment" | |
| - name: Post or update PR comment | |
| if: steps.check-drafts.outputs.has_drafts == 'true' | |
| uses: peter-evans/create-or-update-comment@v5 | |
| with: | |
| issue-number: ${{ github.event.pull_request.number }} | |
| comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
| body: | | |
| ## 🎫 XLS Number Assignment | |
| This PR adds a new XLS draft. The next available XLS number has been determined: | |
| | Draft Directory | Assigned Number | New Directory Name | | |
| |-----------------|-----------------|-------------------| | |
| | `${{ steps.assign-number.outputs.draft_dir }}` | **XLS-${{ steps.assign-number.outputs.xls_number }}** | `${{ steps.assign-number.outputs.new_dir_name }}` | | |
| ### Next Steps for XLS Editors | |
| Before merging this PR, please: | |
| 1. **Rename the directory** from `${{ steps.assign-number.outputs.draft_dir }}` to `${{ steps.assign-number.outputs.new_dir_name }}` | |
| 2. **Update the preamble** in the README.md: | |
| - Set `xls:` to `${{ steps.assign-number.outputs.xls_number }}` | |
| - Set `status:` to `Draft` | |
| --- | |
| *This comment was automatically generated. The XLS number below is reserved for this PR based on existing XLS numbers in the repository and other open draft PRs.* | |
| <!-- XLS_NUMBER:${{ steps.assign-number.outputs.xls_number }} --> | |
| - name: Add has-xls-number label | |
| if: steps.check-drafts.outputs.has_drafts == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| curl -sS \ | |
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -X POST \ | |
| -d '{"labels":["has-xls-number"]}' \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels" |