All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates..github.workflows.ci-build.yml Maven / Gradle / Ivy

The newest version!
name: CI Build
on:
  push:
    branches: ["main"]
  pull_request:
  workflow_dispatch:

jobs:
  build-and-test:
    runs-on: $ciBuildRunnerOS
    defaults:
      run:
        shell: "bash"
    permissions:
      contents: read
      issues: read # Required for PK verify-release
    concurrency:
      group: ${{ github.workflow }}-build-and-test-${{ github.ref }}
      cancel-in-progress: true
    outputs:
      release-required: ${{ steps.check-release.outputs.release-required }}
    steps:
      - name: Free Disk Space
        id: free-disk-space
        if: ${{ $freeDiskSpace }}
        run: |
          sudo rm -rf /usr/local/lib/android
          sudo rm -rf /usr/share/dotnet
      - name: Checkout the repository
        id: checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Set up JDKs
        id: setup-java
        uses: actions/setup-java@v4
        with:
          distribution: "temurin"
          java-version: |
            11
            17
          cache: "maven"
      - name: Cache SonarCloud packages
        id: cache-sonar
        uses: actions/cache@v4
        with:
          path: ~/.sonar/cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Enable testcontainer reuse
        id: enable-testcontainer-reuse
        run: echo 'testcontainers.reuse.enable=true' > "$HOME/.testcontainers.properties"
      - name: Run tests and build with Maven
        id: build-pk-verify
        run: |
          mvn --batch-mode clean verify \
              -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
              -DtrimStackTrace=false
      - name: Sonar analysis
        id: sonar-analysis
        if: ${{ env.SONAR_TOKEN != null }}
        run: |
          mvn --batch-mode org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
              -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
              -DtrimStackTrace=false \
              -Dsonar.token=$SONAR_TOKEN
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

      - name: Verify Release Artifacts
        id: verify-release-artifacts
        run: |
          print_message() {
              local -r message=$1
              echo "$message"
              echo "$message" >> "$GITHUB_STEP_SUMMARY"
          }

          print_message "### Release Artifacts"

          IFS=$'\n' artifacts_array=($ARTIFACTS)
          missing_files=()
          for file in "${artifacts_array[@]}";
          do  
              echo "Checking if file $file exists..."
              if ! [[ -f "$file" ]]; then
                  print_message "* ⚠️ \`$file\` does not exist ⚠️"
                  echo "Content of directory $(dirname "$file"):"
                  ls "$(dirname "$file")"
                  missing_files+=("$file")
              else
                  print_message "* \`$file\` ✅" 
              fi
          done
          print_message ""
          number_of_missing_files=${#missing_files[@]}
          if [[ $number_of_missing_files -gt 0 ]]; then
              print_message "⚠️ $number_of_missing_files release artifact(s) missing ⚠️"
              exit 1
          fi
        env:
          ARTIFACTS: ${{ steps.build-pk-verify.outputs.release-artifacts }}

      - name: Upload artifacts
        id: upload-artifacts
        uses: actions/upload-artifact@v4
        with:
          name: artifacts
          path: ${{ steps.build-pk-verify.outputs.release-artifacts }}
          retention-days: 5

      - name: Configure link check
        id: configure-link-check
        run: |
          mkdir -p ./target
          echo '{"aliveStatusCodes": [429, 200], "ignorePatterns": [' \
               '{"pattern": "^https?://(www|dev).mysql.com/"},' \
               '{"pattern": "^https?://(www.)?opensource.org"}' \
               '{"pattern": "^https?://(www.)?eclipse.org"}' \
               '{"pattern": "^https?://projects.eclipse.org"}' \
               ']}' > ./target/broken_links_checker.json
      - uses: gaurav-nelson/github-action-markdown-link-check@v1
        id: run-link-check
        with:
          use-quiet-mode: "yes"
          use-verbose-mode: "yes"
          config-file: ./target/broken_links_checker.json

  next-java-compatibility:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: "bash"
    permissions:
      contents: read
    concurrency:
      group: ${{ github.workflow }}-next-java-${{ github.ref }}
      cancel-in-progress: true
    steps:
      - name: Checkout the repository
        id: checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Set up JDK $nextJavaVersion
        id: setup-java
        uses: actions/setup-java@v4
        with:
          distribution: "temurin"
          java-version: $nextJavaVersion
          cache: "maven"
      - name: Run tests and build with Maven $nextJavaVersion
        id: build-next-java
        run: mvn --batch-mode clean package -DtrimStackTrace=false -Djava.version=$nextJavaVersion

  build:
    needs:
      - build-and-test
      - next-java-compatibility
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: "bash"
    permissions:
      contents: read
      issues: read # Required for PK verify-release
    outputs:
      release-required: ${{ steps.check-release.outputs.release-required }}
    steps:
      - name: Checkout the repository
        id: checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Set up JDKs
        id: setup-java
        uses: actions/setup-java@v4
        with:
          distribution: "temurin"
          java-version: |
            11
            17
          cache: "maven"
      - name: Check if release is needed
        id: check-release
        if: ${{ github.ref == 'refs/heads/main' }}
        run: |
          if mvn --batch-mode com.exasol:project-keeper-maven-plugin:verify-release --projects .; then
              echo "### ✅ Release preconditions met, start release" >> "$GITHUB_STEP_SUMMARY"
              echo "release-required=true" >> "$GITHUB_OUTPUT"
          else
              echo "### 🛑 Not all release preconditions met, skipping release" >> "$GITHUB_STEP_SUMMARY"
              echo "See log output for details." >> "$GITHUB_STEP_SUMMARY"
              echo "release-required=false" >> "$GITHUB_OUTPUT"
          fi
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  # [impl->dsn~release-workflow.ci-build-starts-release~2]
  start_release:
    needs: build
    if: ${{ github.ref == 'refs/heads/main' && needs.build.outputs.release-required == 'true' }}
    concurrency:
      cancel-in-progress: false
      group: "release"
    secrets: inherit
    permissions:
      contents: write
      actions: read
      issues: read
    uses: ./.github/workflows/release.yml
    with:
      started-from-ci: true




© 2015 - 2025 Weber Informatics LLC | Privacy Policy