|
| 1 | +name: Test Spring Application and Send Email |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + test: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up JDK 17 |
| 17 | + uses: actions/setup-java@v4 |
| 18 | + with: |
| 19 | + distribution: 'temurin' |
| 20 | + java-version: '17' |
| 21 | + |
| 22 | + - name: Cache Maven packages |
| 23 | + uses: actions/cache@v4 |
| 24 | + with: |
| 25 | + path: ~/.m2 |
| 26 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 27 | + restore-keys: | |
| 28 | + ${{ runner.os }}-maven- |
| 29 | +
|
| 30 | + - name: Build and test with Maven |
| 31 | + run: mvn clean test |
| 32 | + |
| 33 | + - name: Archive test results |
| 34 | + if: always() |
| 35 | + uses: actions/upload-artifact@v4 |
| 36 | + with: |
| 37 | + name: test-results |
| 38 | + path: target/surefire-reports/ |
| 39 | + |
| 40 | + - name: Send email with test summary |
| 41 | + if: always() |
| 42 | + uses: dawidd6/action-send-mail@v3 |
| 43 | + with: |
| 44 | + server_address: smtp.gmail.com |
| 45 | + server_port: 465 |
| 46 | + username: ${{ secrets.MAIL_USERNAME }} |
| 47 | + password: ${{ secrets.MAIL_PASSWORD }} |
| 48 | + subject: "Spring App Test Results - ${{ github.repository }} #${{ github.run_number }}" |
| 49 | + to: ${{ secrets.MAIL_RECIPIENT }} |
| 50 | + from: ${{ secrets.MAIL_USERNAME }} |
| 51 | + content_type: text/html |
| 52 | + body: | |
| 53 | + <h2>Test Results for ${{ github.repository }} (Run #${{ github.run_number }})</h2> |
| 54 | + <p>Workflow: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}">View Run Logs</a></p> |
| 55 | + <p>Status: <b>${{ job.status }}</b></p> |
| 56 | + <p>Commit: ${{ github.sha }}</p> |
| 57 | + <p>Branch: ${{ github.ref_name }}</p> |
| 58 | + <p>Summary of test results:</p> |
| 59 | + <pre> |
| 60 | + ${{ steps.test.outputs }} |
| 61 | + </pre> |
| 62 | + attachments: target/surefire-reports/*.xml |
0 commit comments