Fj 2024 lesson 13 CI/CD #9
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: CI/CD Pipeline | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches, ~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Install dependencies and build | |
run: | | |
cd Task10 | |
chmod +x gradlew | |
./gradlew build --no-daemon | |
- name: Run tests | |
run: | | |
cd Task10 | |
./gradlew test --no-daemon | |
- name: Calculate test coverage | |
run: | | |
cd Task10 | |
./gradlew jacocoTestReport --no-daemon | |
- name: Upload coverage report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-report | |
path: Task10/build/reports/jacoco/test/html | |
- name: Static code analysis | |
continue-on-error: true | |
run: | | |
cd Task10 | |
curl -sSLO https://github.com/detekt/detekt/releases/download/v1.23.7/detekt-cli-1.23.7.zip | |
unzip detekt-cli-1.23.7.zip | |
./detekt-cli-1.23.7/bin/detekt-cli | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GH_PAT }} | |
- name: Build Docker image | |
run: | | |
docker build -t ghcr.io/${{ github.repository }}/task-10:${{ github.sha }} Task10/. | |
- name: Push Docker image to GitHub Packages | |
run: | | |
docker push ghcr.io/${{ github.repository }}/task-10:${{ github.sha }} |