diff --git a/.github/workflows/ci2.yml b/.github/workflows/ci2.yml index 73b907d..e894db2 100644 --- a/.github/workflows/ci2.yml +++ b/.github/workflows/ci2.yml @@ -1,5 +1,81 @@ -- name: Trigger Build with Inputs - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: CI Pipeline - inputs: '{ "image_tag": ""}' \ No newline at end of file +name: CI Pipeline + +on: + push: + branches: + - main + pull_request: + + workflow_dispatch: + inputs: + image_tag: + description: 'Image tag name' + required: false + default: 'latest' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: 'maven' + + - name: Compile sysfoo app + run: mvn compile + + test: + runs-on: ubuntu-latest + needs: build + strategy: + matrix: + job: [unit-test, sca, sbom] + name: Run ${{ matrix.job }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: 'maven' + + - name: Run ${{ matrix.job }} + run: | + if [ "${{ matrix.job }}" == "unit-test" ]; then + mvn clean test + elif [ "${{ matrix.job }}" == "sca" ]; then + sleep 4 + elif [ "${{ matrix.job }}" == "sbom" ]; then + sleep 2 + fi + + package: + runs-on: ubuntu-latest + needs: test + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: 'maven' + + - name: Package app + run: mvn package -DskipTests + + - name: Archive JAR + uses: actions/upload-artifact@v4 + with: + name: sysfoo-artifact + path: target/*.jar