CI / Compile (pull_request) Has been cancelled
CI / Test (pull_request) Has been cancelled
CI / Package (pull_request) Has been cancelled
CI / Docker Build and Push (main) (pull_request) Has been cancelled
CI / Docker Build and Push (release) (pull_request) Has been cancelled
202 lines
6.2 KiB
YAML
202 lines
6.2 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "main"
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- "main"
|
|
|
|
env:
|
|
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=${{ github.workspace }}/.m2/repository -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
|
|
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version --no-transfer-progress -DinstallAtEnd=true -DdeployAtEnd=true"
|
|
# Docker image name; expects REGISTRY_URL like registry.example.com
|
|
CI_REGISTRY_IMAGE: "${{ secrets.REGISTRY_URL }}/${{ github.repository }}"
|
|
|
|
jobs:
|
|
compile:
|
|
name: Compile
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: '25'
|
|
cache: 'maven'
|
|
|
|
- name: Cache Maven local repo and wrapper
|
|
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
|
|
with:
|
|
path: |
|
|
${{ github.workspace }}/.m2/repository
|
|
.mvn
|
|
key: m2-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
|
|
restore-keys: |
|
|
m2-${{ runner.os }}-
|
|
|
|
- name: Compile
|
|
run: |
|
|
chmod +x ./mvnw
|
|
./mvnw $MAVEN_CLI_OPTS compile
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
needs: compile
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: '25'
|
|
cache: 'maven'
|
|
|
|
- name: Cache Maven local repo and wrapper
|
|
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
|
|
with:
|
|
path: |
|
|
${{ github.workspace }}/.m2/repository
|
|
.mvn
|
|
key: m2-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
|
|
restore-keys: |
|
|
m2-${{ runner.os }}-
|
|
|
|
- name: Run tests
|
|
run: |
|
|
chmod +x ./mvnw
|
|
./mvnw $MAVEN_CLI_OPTS test
|
|
|
|
- name: Upload test reports (artifact)
|
|
if: always()
|
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
|
|
with:
|
|
name: junit-reports
|
|
path: |
|
|
**/target/*-reports/TEST-*.xml
|
|
if-no-files-found: ignore
|
|
|
|
package:
|
|
name: Package
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: '25'
|
|
cache: 'maven'
|
|
|
|
- name: Cache Maven local repo and wrapper
|
|
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
|
|
with:
|
|
path: |
|
|
${{ github.workspace }}/.m2/repository
|
|
.mvn
|
|
key: m2-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
|
|
restore-keys: |
|
|
m2-${{ runner.os }}-
|
|
|
|
- name: Build package (skip tests)
|
|
run: |
|
|
chmod +x ./mvnw
|
|
./mvnw $MAVEN_CLI_OPTS package -DskipTests=true
|
|
|
|
- name: Upload Maven artifacts
|
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
|
|
with:
|
|
name: maven-artifacts
|
|
path: |
|
|
target/netneutrality.jar
|
|
startup.sh
|
|
if-no-files-found: error
|
|
|
|
docker-main:
|
|
name: Docker Build and Push (main)
|
|
runs-on: ubuntu-latest
|
|
needs: package
|
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
|
|
- name: Download build artifacts
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: maven-artifacts
|
|
path: .
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
|
|
with:
|
|
registry: ${{ secrets.REGISTRY_URL }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push (main)
|
|
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
tags: "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/netneutrality:main"
|
|
|
|
docker-release:
|
|
name: Docker Build and Push (release)
|
|
runs-on: ubuntu-latest
|
|
needs: package
|
|
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
|
|
- name: Download build artifacts
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: maven-artifacts
|
|
path: .
|
|
|
|
- name: Compute release version
|
|
id: rel
|
|
shell: bash
|
|
run: |
|
|
# Strip leading 'v' if present (e.g., v1.2.3 -> 1.2.3)
|
|
ver="${GITHUB_REF_NAME#v}"
|
|
echo "version=$ver" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
|
|
with:
|
|
registry: ${{ secrets.REGISTRY_URL }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push (release + latest)
|
|
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/netneutrality:${{ steps.rel.outputs.version }}
|
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/netneutrality:latest
|