validate-package #7
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: Validate Package Workflow | |
| on: | |
| repository_dispatch: | |
| types: [validate-package] | |
| jobs: | |
| process-message: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - name: Generate GitHub App token | |
| id: generate-token | |
| uses: tibdex/github-app-token@v2 | |
| with: | |
| app_id: ${{ secrets.HATCH_WORKFLOW_APP_ID }} | |
| private_key: ${{ secrets.HATCH_WORKFLOW_APP_PRIVATE_KEY }} | |
| - name: Download package artifact | |
| uses: dawidd6/action-download-artifact@v9 | |
| with: | |
| github_token: ${{ steps.generate-token.outputs.token }} | |
| workflow: ${{ github.event.client_payload.workflow_id }} | |
| run_id: ${{ github.event.client_payload.run_id }} | |
| name: ${{ github.event.client_payload.artifact_name }} | |
| repo: ${{ github.event.client_payload.repository }} | |
| path: downloaded-package | |
| - name: Print received package content | |
| run: | | |
| echo "Processing package: ${{ github.event.client_payload.package_name }}" | |
| echo "Package contents:" | |
| ls -la downloaded-package | |
| - name: Install pip | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install Hatch-Registry | |
| run: | | |
| pip install -r requirements.txt | |
| pip install . | |
| - name: Validate package | |
| id: validation | |
| continue-on-error: true | |
| run: | | |
| REPO="${{ github.event.client_payload.repository }}" | |
| hatch-registry validate-package --repository-name ${REPO##*/} --package-dir ./downloaded-package > validation_log.txt 2>&1 | |
| if [ $? -eq 0 ]; then | |
| echo "validation_result=success" >> $GITHUB_OUTPUT | |
| else | |
| echo "validation_result=failure" >> $GITHUB_OUTPUT | |
| fi | |
| cat validation_log.txt | |
| - name: Comment on PR with validation results | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.generate-token.outputs.token }} | |
| script: | | |
| const fs = require('fs'); | |
| const validationLog = fs.readFileSync('validation_log.txt', 'utf8'); | |
| const validation_result = '${{ steps.validation.outputs.validation_result }}'; | |
| const repository = '${{ github.event.client_payload.repository }}'; | |
| const [owner, repo] = repository.split('/'); | |
| const prNumber = ${{ github.event.client_payload.pr_number }}; | |
| let commentBody; | |
| if (validation_result === 'success') { | |
| commentBody = `## ✅ Package Validation Success\n\nYour package has been successfully validated! It is now ready for review.\n\n<details><summary>Validation Log</summary>\n\n\`\`\`\n${validationLog}\n\`\`\`\n</details>`; | |
| // Add success label | |
| await github.rest.issues.addLabels({ | |
| owner, | |
| repo, | |
| issue_number: prNumber, | |
| labels: ['validation-passed', 'ready-for-review'] | |
| }); | |
| } else { | |
| commentBody = `## ❌ Package Validation Failed\n\nYour package did not pass validation. Please see the log below for details and make the necessary changes.\n\n<details><summary>Validation Log</summary>\n\n\`\`\`\n${validationLog}\n\`\`\`\n</details>`; | |
| // Add failure label | |
| await github.rest.issues.addLabels({ | |
| owner, | |
| repo, | |
| issue_number: prNumber, | |
| labels: ['validation-failed'] | |
| }); | |
| } | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number: prNumber, | |
| body: commentBody | |
| }); |