|
| 1 | +name: Build bootJar on PR comment |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + issues: write |
| 10 | + pull-requests: write |
| 11 | + actions: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-jar: |
| 15 | + # Только если комментарий к PR и в нём есть /buildJar |
| 16 | + if: > |
| 17 | + github.event.issue.pull_request != '' && |
| 18 | + contains(github.event.comment.body, '/buildJar') |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Get PR info |
| 23 | + id: pr |
| 24 | + uses: actions/github-script@v8 |
| 25 | + with: |
| 26 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + script: | |
| 28 | + const prNumber = context.issue.number; |
| 29 | + const pr = await github.rest.pulls.get({ |
| 30 | + owner: context.repo.owner, |
| 31 | + repo: context.repo.repo, |
| 32 | + pull_number: prNumber, |
| 33 | + }); |
| 34 | +
|
| 35 | + core.info(`Base: ${pr.data.base.repo.full_name}@${pr.data.base.ref}`); |
| 36 | + core.info(`Head: ${pr.data.head.repo.full_name}@${pr.data.head.ref}`); |
| 37 | +
|
| 38 | + core.setOutput('head_ref', pr.data.head.ref); |
| 39 | + core.setOutput('head_repo', pr.data.head.repo.full_name); |
| 40 | +
|
| 41 | + - name: Checkout PR head with full history |
| 42 | + uses: actions/checkout@v6 |
| 43 | + with: |
| 44 | + repository: ${{ steps.pr.outputs.head_repo }} |
| 45 | + ref: ${{ steps.pr.outputs.head_ref }} |
| 46 | + fetch-depth: 0 |
| 47 | + fetch-tags: true |
| 48 | + |
| 49 | + - name: Set up JDK with Gradle cache |
| 50 | + uses: actions/setup-java@v5 |
| 51 | + with: |
| 52 | + distribution: 'corretto' |
| 53 | + java-version: 25 |
| 54 | + cache: 'gradle' |
| 55 | + |
| 56 | + - name: Make Gradle wrapper executable (if needed) |
| 57 | + run: chmod +x ./gradlew |
| 58 | + |
| 59 | + - name: Build bootJar |
| 60 | + run: ./gradlew bootJar |
| 61 | + |
| 62 | + - name: List built JARs |
| 63 | + id: list_jars |
| 64 | + run: | |
| 65 | + if ! ls build/libs/*.jar >/dev/null 2>&1; then |
| 66 | + echo "No JAR found in build/libs" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | +
|
| 70 | + echo "Найдены JAR-файлы:" |
| 71 | + ls -1 build/libs/*.jar |
| 72 | +
|
| 73 | + # Собираем список файлов в формате markdown-списка |
| 74 | + { |
| 75 | + for path in build/libs/*.jar; do |
| 76 | + echo "- \`$(basename "$path")\`" |
| 77 | + done |
| 78 | + } > jar_list.txt |
| 79 | +
|
| 80 | + echo 'list<<EOF' >> "$GITHUB_OUTPUT" |
| 81 | + cat jar_list.txt >> "$GITHUB_OUTPUT" |
| 82 | + echo 'EOF' >> "$GITHUB_OUTPUT" |
| 83 | +
|
| 84 | + - name: Upload JAR artifact |
| 85 | + id: upload_jar |
| 86 | + uses: actions/upload-artifact@v5 |
| 87 | + with: |
| 88 | + # имя артефакта; можешь поменять на что-то своё |
| 89 | + name: bootJar-${{ github.run_id }} |
| 90 | + path: build/libs/*.jar |
| 91 | + # retention-days: 7 # при желании |
| 92 | + |
| 93 | + - name: Comment on PR with JAR link |
| 94 | + uses: peter-evans/create-or-update-comment@v5 |
| 95 | + with: |
| 96 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + issue-number: ${{ github.event.issue.number }} |
| 98 | + body: | |
| 99 | + ✅ Собраны JAR-файлы для этого PR по команде `/buildJar`. |
| 100 | +
|
| 101 | + **Артефакт:** [${{ steps.upload_jar.outputs.artifact-id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.upload_jar.outputs.artifact-id }}) |
| 102 | +
|
| 103 | + **Файлы внутри:** |
| 104 | + ${{ steps.list_jars.outputs.list }} |
0 commit comments