Skip to content

Update and rename maven-publish.yml to test-and-email.yml #1

Update and rename maven-publish.yml to test-and-email.yml

Update and rename maven-publish.yml to test-and-email.yml #1

name: Test Spring Application and Send Email
on:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build and test with Maven
run: mvn clean test
- name: Archive test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: target/surefire-reports/
- name: Send email with test summary
if: always()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: "Spring App Test Results - ${{ github.repository }} #${{ github.run_number }}"
to: ${{ secrets.MAIL_RECIPIENT }}
from: ${{ secrets.MAIL_USERNAME }}
content_type: text/html
body: |
<h2>Test Results for ${{ github.repository }} (Run #${{ github.run_number }})</h2>
<p>Workflow: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}">View Run Logs</a></p>
<p>Status: <b>${{ job.status }}</b></p>
<p>Commit: ${{ github.sha }}</p>
<p>Branch: ${{ github.ref_name }}</p>
<p>Summary of test results:</p>
<pre>
${{ steps.test.outputs }}
</pre>
attachments: target/surefire-reports/*.xml