Build Test Client

name: Build Test Client

on:
  push:
    branches:
    - "release_test"

jobs:
  release:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: windows-latest
            file_extension: ".exe"
            file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test%20Setup%2099.0.${{ github.run_id }}-Test.exe"
            build_arg: "--win --x64"
          - os: macos-latest
            arch: x86_64
            file_name: "https://download.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.dmg"
            file_extension: ".dmg"
            build_arg: "--mac --x64"
          - os: macos-latest
            arch: arm64
            file_name: "https://download.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test-arm64.dmg"
            file_extension: ".dmg"
            build_arg: "--mac --arm64"
          - os: ubuntu-latest
            file_name: "https://download.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.AppImage"
            file_extension: ".AppImage"
            build_arg: "--linux"
    runs-on: ${{ matrix.os }}

    steps:
      - name: Check out git repository
        uses: actions/checkout@main

      # Install JRE
      - name: Install JRE
        uses: actions/setup-java@main
        with:
          java-version: "17"
          distribution: "temurin"
          java-package: "jre"
          # architecture: ${{ matrix.arch == 'arm64' && 'aarch64' || 'x64' }}

      # OpenTLS
      - name: Enable TLS 1.0 and 1.1 in java.security
        run: |
          if [ "$RUNNER_OS" = "Windows" ]; then
            sed -i "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\(TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "$JAVA_HOME/conf/security/java.security"
          elif [ "$RUNNER_OS" = "Linux" ]; then
            sed -i "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\(TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "$JAVA_HOME/conf/security/java.security"
          elif [ "$RUNNER_OS" = "macOS" ]; then
            sed -i '' "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\(TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "$JAVA_HOME/conf/security/java.security"
          fi
        shell: bash
        env:
          RUNNER_OS: ${{ runner.os }}
          JAVA_HOME: ${{ env.JAVA_HOME }}

      # Copy JRE to the front-end static directory
      - name: Copy JRE to static directory
        run: |
          mkdir -p chat2db-client/static
          cp -r "$JAVA_HOME"/ chat2db-client/static/jre
          if [ "${{ runner.os }}" != "Windows" ]; then
            chmod -R 777 chat2db-client/static/jre
          fi
        shell: bash
        env:
          JAVA_HOME: ${{ env.JAVA_HOME }}

      # Delete related files in jre in Linux
      - if: ${{ runner.os == 'Linux' }}
        name: Delete File on Linux
        run: |
          cd chat2db-client/static/jre/
          ls -la
          rm -rf legal
          ls -la

      # Install Node.js
      - name: Install Node.js
        uses: actions/setup-node@main
        with:
          node-version: "16"
          cache: "yarn"
          cache-dependency-path: chat2db-client/yarn.lock

      # Install Java
      - name: Install Java and Maven
        uses: actions/setup-java@main
        with:
          java-version: "17"
          distribution: "temurin"
          cache: "maven"

      # Packaging web front-end resources
      - name: Build FE Static
        run: |
          cd chat2db-client
          yarn
          yarn run build:web:prod --app_version=99.0.${{ github.run_id }} --app_port=10822
          cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front
          cp -r dist/index.html ../chat2db-server/chat2db-server-start/src/main/resources/thymeleaf/
          cd src/main
          yarn
          yarn run build

      # Package backend project & send to frontend
      - name: Build BE Static
        run: |
          mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml
          mkdir -p chat2db-client/versions/99.0.${{ github.run_id }}/static
          echo -n 99.0.${{ github.run_id }} > chat2db-client/version
          cp -r chat2db-client/version chat2db-client/versions/
          cp chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-client/versions/99.0.${{ github.run_id }}/static/

      # Packaging desktop front-end resources
      - name: Prepare Build Electron
        run: |
          cd chat2db-client
          yarn run build:web:desktop --app_version=99.0.${{ github.run_id }} --app_port=10822
          cp -r dist ./versions/99.0.${{ github.run_id }}/
          rm -r dist

      # Packaging Electron
      - name: Build/release Electron app
        uses: samuelmeuli/action-electron-builder@v1
        with:
          package_root: "chat2db-client/"
          GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
          mac_certs: ${{ secrets.mac_certs_temp }}
          mac_certs_password: ${{ secrets.mac_certs_password_temp }}
          skip_build: true
          args: >
            -c.appId=com.chat2db.test
            -c.productName=Chat2DB-Test
            -c.win.publisherName=Chat2DB-Test
            -c.nsis.shortcutName=Chat2DB-Test
            -c.extraMetadata.version=99.0.${{ github.run_id }}-Test
            ${{ matrix.build_arg}}

      # Notarization & Signature Mac App
      - name: Notarize MacOS x86_64 App
        if: matrix.os == 'macos-latest' && matrix.arch == 'x86_64'
        run: |
          xcrun notarytool store-credentials "Chat2DB" --apple-id "${{ secrets.MAC_APPLE_ID }}" --password "${{ secrets.MAC_APPLE_PASSWORD }}" --team-id "${{ secrets.MAC_TEAM_ID }}"
          xcrun notarytool submit chat2db-client/release/Chat2DB-Test-99.0.${{ github.run_id }}-Test.dmg --keychain-profile "Chat2DB"

      - name: Notarize MacOS ARM64 App
        if: matrix.os == 'macos-latest' && matrix.arch == 'arm64'
        run: |
          xcrun notarytool store-credentials "Chat2DB" --apple-id "${{ secrets.MAC_APPLE_ID }}" --password "${{ secrets.MAC_APPLE_PASSWORD }}" --team-id "${{ secrets.MAC_TEAM_ID }}"
          xcrun notarytool submit chat2db-client/release/Chat2DB-Test-99.0.${{ github.run_id }}-Test-arm64.dmg --keychain-profile "Chat2DB"

      # Build Jar
      - name: Prepare upload for Jar
        if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }}
        run: |
          mkdir -p oss_temp_file
          cp chat2db-client/versions/99.0.${{ github.run_id }}/static/chat2db-server-start.jar   ./oss_temp_file
          cp -r chat2db-client/release/*.dmg ./oss_temp_file
          cp -r chat2db-client/versions/99.0.${{ github.run_id }}/dist ./oss_temp_file/dist
          cd chat2db-client/versions/99.0.${{ github.run_id }}/ && zip -r 99.0.${{ github.run_id }}.zip ./
          cp -r 99.0.${{ github.run_id }}.zip ../../../oss_temp_file
          cd static/ && zip -r chat2db-server-start.zip ./
          cp -r chat2db-server-start.zip ../../../../oss_temp_file

      # Prepare files to be sent to OSS
      - name: Prepare upload for OSS
        run: |
          mkdir -p oss_temp_file
          cp -r chat2db-client/release/*${{ matrix.file_extension }} ./oss_temp_file

      # Set up OSS
      - name: Set up oss utils
        uses: yizhoumo/setup-ossutil@v1
        with:
          endpoint: "oss-accelerate.aliyuncs.com"
          access-key-id: ${{ secrets.OSS_ACCESS_KEY_ID }}
          access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
          ossutil-version: "1.7.16"

      # Upload to OSS
      - name: Upload to OSS
        run: |
          ossutil cp -rf --acl=public-read ./oss_temp_file/ oss://chat2db-client/test/99.0.${{ github.run_id }}/

      # Configure SSH to be uploaded to the server
      - name: Install ssh key
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SERVER_DOWNLOAD_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan -t rsa ${{ secrets.SERVER_DOWNLOAD_HOST }} >> ~/.ssh/known_hosts
          eval `ssh-agent -s`
          ssh-add ~/.ssh/id_rsa
      # upload to server
      - name: Upload package
        run: |
          ssh -t ${{ secrets.SERVER_DOWNLOAD_USERNAME }}@${{ secrets.SERVER_DOWNLOAD_HOST }} "mkdir -p ${{ secrets.SERVER_DOWNLOAD_PATH }}/test//99.0.${{ github.run_id }}"
          scp ./oss_temp_file/* ${{ secrets.SERVER_DOWNLOAD_USERNAME }}@${{ secrets.SERVER_DOWNLOAD_HOST }}:${{ secrets.SERVER_DOWNLOAD_PATH }}/test//99.0.${{ github.run_id }}/

      # Send to DingTalk
      - name: Send dingtalk message
        uses: ghostoy/dingtalk-action@master
        with:
          webhook: ${{ secrets.DINGTALK_WEBHOOK }}
          msgtype: markdown
          content: |
            {
              "title": "${{ matrix.os }}-test-打包完成通知",
              "text": "# ${{ matrix.os }}-test-打包完成通知\n !\n ###  任务id：[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }})\n ### 下载地址：[${{matrix.file_name}}](${{matrix.file_name}})"
            }

      # Send Jar package address to DingTalk
      - if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }}
        name: Send dingtalk message
        uses: ghostoy/dingtalk-action@master
        with:
          webhook: ${{ secrets.DINGTALK_WEBHOOK }}
          msgtype: markdown
          content: |
            {
              "title": "Jar-test-构建完成通知",
              "text": "### jar包下载地址：[https://download.sqlgpt.cn/test/99.0.${{ github.run_id }}/chat2db-server-start.zip](https://download.sqlgpt.cn/test/99.0.${{ github.run_id }}/chat2db-server-start.zip) "
            }


Build Test Client 2

name: Build Test Client 2

on:
  push:
    branches:
    - "release_test_2"

jobs:
  release:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: windows-latest
            file_extension: ".exe"
            file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test%20Setup%2099.0.${{ github.run_id }}-Test.exe"
            build_arg: "--win --x64"
          - os: macos-latest
            arch: x86_64
            file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.dmg"
            file_extension: ".dmg"
            build_arg: "--mac --x64"
          - os: macos-latest
            arch: arm64
            file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test-arm64.dmg"
            file_extension: ".dmg"
            build_arg: "--mac --arm64"
          - os: ubuntu-latest
            file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.AppImage"
            file_extension: ".AppImage"
            build_arg: "--linux"
    runs-on: ${{ matrix.os }}

    steps:
      - name: Check out git repository
        uses: actions/checkout@main

      # Install JRE
      - name: Install JRE
        uses: actions/setup-java@main
        with:
          java-version: "17"
          distribution: "temurin"
          java-package: "jre"
          # architecture: ${{ matrix.arch == 'arm64' && 'aarch64' || 'x64' }}

      # Open TLS
      - name: Enable TLS 1.0 and 1.1 in java.security
        run: |
          if [ "$RUNNER_OS" = "Windows" ]; then
            sed -i "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\(TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "$JAVA_HOME/conf/security/java.security"
          elif [ "$RUNNER_OS" = "Linux" ]; then
            sed -i "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\(TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "$JAVA_HOME/conf/security/java.security"
          elif [ "$RUNNER_OS" = "macOS" ]; then
            sed -i '' "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\(TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "$JAVA_HOME/conf/security/java.security"
          fi
        shell: bash
        env:
          RUNNER_OS: ${{ runner.os }}
          JAVA_HOME: ${{ env.JAVA_HOME }}

      # Copy JRE to the front-end static directory
      - name: Copy JRE to static directory
        run: |
          mkdir -p chat2db-client/static
          cp -r "$JAVA_HOME"/ chat2db-client/static/jre
          if [ "${{ runner.os }}" != "Windows" ]; then
            chmod -R 777 chat2db-client/static/jre
          fi
        shell: bash
        env:
          JAVA_HOME: ${{ env.JAVA_HOME }}

      # Delete related files in jre in Linux
      - if: ${{ runner.os == 'Linux' }}
        name: Delete File on Linux
        run: |
          cd chat2db-client/static/jre/
          ls -la
          rm -rf legal
          ls -la

      # Install Node.js
      - name: Install Node.js
        uses: actions/setup-node@main
        with:
          node-version: "16"
          cache: "yarn"
          cache-dependency-path: chat2db-client/yarn.lock

      # Install Java
      - name: Install Java and Maven
        uses: actions/setup-java@main
        with:
          java-version: "17"
          distribution: "temurin"
          cache: "maven"

      # Packaging web front-end resources
      - name: Build FE Static
        run: |
          cd chat2db-client
          yarn
          yarn run build:web:prod --app_version=99.0.${{ github.run_id }} --app_port=10822
          cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front
          cp -r dist/index.html ../chat2db-server/chat2db-server-start/src/main/resources/thymeleaf/
          cd src/main
          yarn
          yarn run build

      # Package backend project & send to frontend
      - name: Build BE Static
        run: |
          mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml
          mkdir -p chat2db-client/versions/99.0.${{ github.run_id }}/static
          echo -n 99.0.${{ github.run_id }} > chat2db-client/version
          cp -r chat2db-client/version chat2db-client/versions/
          cp chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-client/versions/99.0.${{ github.run_id }}/static/

      # Packaging desktop front-end resources
      - name: Prepare Build Electron
        run: |
          cd chat2db-client
          yarn run build:web:desktop --app_version=99.0.${{ github.run_id }} --app_port=10822
          cp -r dist ./versions/99.0.${{ github.run_id }}/
          rm -r dist

      # Packing Electron
      - name: Build/release Electron app
        uses: samuelmeuli/action-electron-builder@v1
        with:
          package_root: "chat2db-client/"
          GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
          mac_certs: ${{ secrets.mac_certs }}
          mac_certs_password: ${{ secrets.mac_certs_password }}
          skip_build: true
          args: >
            -c.appId=com.chat2db.test
            -c.productName=Chat2DB-Test
            -c.win.publisherName=Chat2DB-Test
            -c.nsis.shortcutName=Chat2DB-Test
            -c.extraMetadata.version=99.0.${{ github.run_id }}-Test
            ${{ matrix.build_arg}}

      # Notarization & Signature Mac App
      - name: Notarize MacOS x86_64 App
        if: matrix.os == 'macos-latest' && matrix.arch == 'x86_64'
        run: |
          xcrun notarytool store-credentials "Chat2DB" --apple-id "${{ secrets.MAC_APPLE_ID }}" --password "${{ secrets.MAC_APPLE_PASSWORD }}" --team-id "${{ secrets.MAC_TEAM_ID }}"
          xcrun notarytool submit chat2db-client/release/Chat2DB-Test-99.0.${{ github.run_id }}-Test.dmg --keychain-profile "Chat2DB"

      # Build Jar
      - name: Prepare upload for Jar
        if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }}
        run: |
          mkdir -p oss_temp_file
          cp chat2db-client/versions/99.0.${{ github.run_id }}/static/chat2db-server-start.jar   ./oss_temp_file
          cp -r chat2db-client/release/*.dmg ./oss_temp_file
          cp -r chat2db-client/versions/99.0.${{ github.run_id }}/dist ./oss_temp_file/dist
          cd chat2db-client/versions/99.0.${{ github.run_id }}/ && zip -r 99.0.${{ github.run_id }}.zip ./
          cp -r 99.0.${{ github.run_id }}.zip ../../../oss_temp_file
          cd static/ && zip -r chat2db-server-start.zip ./
          cp -r chat2db-server-start.zip ../../../../oss_temp_file

      # Prepare files to be sent to OSS
      - name: Prepare upload for OSS
        run: |
          mkdir -p oss_temp_file
          cp -r chat2db-client/release/*${{ matrix.file_extension }} ./oss_temp_file

      # Set up OSS
      - name: Set up oss utils
        uses: yizhoumo/setup-ossutil@v1
        with:
          endpoint: "oss-accelerate.aliyuncs.com"
          access-key-id: ${{ secrets.OSS_ACCESS_KEY_ID }}
          access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
          ossutil-version: "1.7.16"

      # Upload to OSS
      - name: Upload to OSS
        run: |
          ossutil cp -rf --acl=public-read ./oss_temp_file/ oss://chat2db-client/test/99.0.${{ github.run_id }}/

      # Send to DingTalk
      - name: Send dingtalk message
        uses: ghostoy/dingtalk-action@master
        with:
          webhook: ${{ secrets.DINGTALK_WEBHOOK }}
          msgtype: markdown
          content: |
            {
              "title": "${{ matrix.os }}-test-打包完成通知",
              "text": "# ${{ matrix.os }}-test-打包完成通知\n ![bang](https://oss.sqlgpt.cn/static/bang100.gif)\n ###  任务id：[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }})\n ### 下载地址：[${{matrix.file_name}}](${{matrix.file_name}})"
            }

      # Send Jar address to DingTalk
      - if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }}
        name: Send dingtalk message
        uses: ghostoy/dingtalk-action@master
        with:
          webhook: ${{ secrets.DINGTALK_WEBHOOK }}
          msgtype: markdown
          content: |
            {
              "title": "Jar-test-构建完成通知",
              "text": "### jar包下载地址：[https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/chat2db-server-start.zip](https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/chat2db-server-start.zip) "
            }


tests

name: tests
on: [push, pull_request, workflow_dispatch]

jobs:
  checkstyle:
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: true
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v3

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 17

      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2
          key: ${{ matrix.job.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ matrix.job.os }}-m2

      - name: Run checkstyle
        run: mvn checkstyle:check

  run_unit_tests:
    needs: checkstyle
    runs-on: ${{ matrix.job.os }}
    strategy:
      fail-fast: false
      matrix:
        job:
          - os: ubuntu-22.04
          - os: macos-12
          - os: windows-latest
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v3

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 17

      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2
          key: ${{ matrix.job.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ matrix.job.os }}-m2

      - name: Run Andy unit tests
        run: mvn test -pl andy -DexcludedGroups=assignments

  run_assignment_tests:
    needs: checkstyle
    runs-on: ${{ matrix.job.os }}
    strategy:
      fail-fast: false
      matrix:
        job:
          - os: ubuntu-22.04
          - os: macos-12
          - os: windows-latest
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v3

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 17

      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2
          key: ${{ matrix.job.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ matrix.job.os }}-m2

      - name: Run Andy in all assignments
        run: mvn test -pl andy -Dgroups=assignments

  run_weblab_runner_tests:
    needs: checkstyle
    runs-on: ${{ matrix.job.os }}
    strategy:
      fail-fast: false
      matrix:
        job:
          - os: ubuntu-22.04
          - os: macos-12
          - os: windows-latest
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name

    steps:
      - name: Checkout the repository # Anchors not available in github actions :(
        uses: actions/checkout@v3

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 17

      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2
          key: ${{ matrix.job.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ matrix.job.os }}-m2

      - name: Run Weblab runner tests
        run: mvn test -pl weblab-runner -am -DexcludedGroups=selenium


name: assignments_test_docker
on: [push, pull_request, workflow_dispatch]
env:
  # PR: github.sha is the SHA of the PR, not commit, we can't check this out
  GHA_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
  # PR: github.repository is the repository the PR is made in, not the fork
  GHA_REPO: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}
jobs:
  run_assignments_docker:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v3

      - name: Setup python
        uses: actions/setup-python@v4
        with:
          python-version: 3.8

      - name: Configure Makefile.inc to use tar instead of gtar
        working-directory: ./weblab-docker
        run: |
          sed -i 's/gtar/tar/' Makefile.inc

      - name: Build Docker image
        working-directory: ./weblab-docker
        env:
          BUILD_ARGS: "--build-arg ANDY_BRANCH=${{ env.GHA_SHA }} --build-arg ANDY_REPO=${{ env.GHA_REPO }}"
        run: |
          make

      - name: Run the reference solutions of one assignment per category and verify the scores are 100/100
        env:
          # github.repository contains owner, we don't want that
          REPO_NAME: ${{ github.event.repository.name }}
          COMMIT_HASH: ${{ env.GHA_SHA }}
        run: |
          python ./.github/scripts/assignments_test_docker.py


CI Check

name: CI Check

on: [ push ]

concurrency:
  group: ${{ github.ref }}-check
  cancel-in-progress: true

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
      - name: Checkout Extension SDK
        run: |
          git clone https://github.com/hivemq/hivemq-extension-sdk.git ../hivemq-extension-sdk
          cd ../hivemq-extension-sdk
          git checkout ${GITHUB_REF#refs/heads/} || true
          git clone https://github.com/hivemq/hivemq-edge-extension-sdk.git ../hivemq-edge-extension-sdk
          cd ../hivemq-edge-extension-sdk
          git checkout ${GITHUB_REF#refs/heads/} || true
          git clone https://github.com/hivemq/hivemq-edge-adapter-sdk.git ../hivemq-edge-adapter-sdk
          cd ../hivemq-edge-adapter-sdk
          git checkout ${GITHUB_REF#refs/heads/} || true
          cd ../hivemq-edge
      - name: Setup Java
        uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4
        with:
          distribution: 'adopt'
          java-version: '11'
      - name: Check
        run: ./gradlew test :hivemq-edge:forbiddenApis :hivemqEdgeZip


Frontend - React Testing Pyramid

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Frontend - React Testing Pyramid

on:
  push:
    paths:
      - hivemq-edge/src/frontend/**
      - .github/workflows/frontend-cli.yml
      - .github/actions/setup_node/action.yml
env:
  GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

defaults:
  run:
    working-directory: ./hivemq-edge/src/frontend/

# Cancel previous workflow on a follow-up push event
# https://stackoverflow.com/a/72408109
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: 👓 Checkout repository
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

      - name: 🏗 Setup node environment
        uses: ./.github/actions/setup_node
        with:
          working-directory: ./hivemq-edge/src/frontend/

      - name: 🧪 Run Prettier
        run: pnpm lint:prettier

      - name: 🧪 Run ESLint
        run: pnpm lint:eslint

  unit_tests:
    runs-on: ubuntu-latest
    steps:
      - name: 👓 Checkout repository
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

      - name: 🏗 Setup node environment
        uses: ./.github/actions/setup_node
        with:
          working-directory: ./hivemq-edge/src/frontend/

      - name: 🧪 Run Test
        run: pnpm test

  build_production:
    runs-on: ubuntu-latest
    steps:
      - name: 👓 Checkout repository
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

      - name: 🏗 Setup node environment
        uses: ./.github/actions/setup_node
        with:
          working-directory: ./hivemq-edge/src/frontend/

      - name: 🏗 Build Application
        run: pnpm run build

      - name: Upload artifact
        uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
        with:
          name: application
          path: hivemq-edge/src/frontend/dist
          retention-days: 1

  component_tests:
    runs-on: ubuntu-latest
    needs: [ build_production ]
    steps:
      - name: 👓 Checkout repository
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

      - name: 🏗 Setup node environment
        uses: ./.github/actions/setup_node
        with:
          working-directory: ./hivemq-edge/src/frontend/
          run-install: true

      - name: Download artifact
        uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
        with:
          name: application
          path: hivemq-edge/src/frontend/dist

      - name: 🧪 Run Cypress Component
        uses: cypress-io/github-action@v6
        with:
          component: true
          start: pnpm preview
          working-directory: ./hivemq-edge/src/frontend/
          quiet: true

      # after the test run completes store videos
      - name: 💾 Upload Component videos
        if: failure()
        uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
        with:
          name: cypress-component-videos
          path: hivemq-edge/src/frontend/cypress/videos
          if-no-files-found: ignore
          retention-days: 1

  e2e_tests:
    runs-on: ubuntu-latest
    needs: [ build_production ]
    steps:
      - name: 👓 Checkout repository
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

      - name: 🏗 Setup node environment
        uses: ./.github/actions/setup_node
        with:
          working-directory: ./hivemq-edge/src/frontend/
          run-install: true

      - name: Download artifact
        uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
        with:
          name: application
          path: hivemq-edge/src/frontend/dist

      - name: 🧪 Run Cypress E2E
        uses: cypress-io/github-action@v6
        with:
          start: pnpm preview --port 3000
          working-directory: ./hivemq-edge/src/frontend/
          quiet: true
      - name: 💾 Upload E2E videos
        if: failure()
        uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
        with:
          name: cypress-e2e-videos
          path: hivemq-edge/src/frontend/cypress/videos
          if-no-files-found: ignore
          retention-days: 1

  lighthouse:
    runs-on: ubuntu-latest
    needs: [ build_production ]
    steps:
      - name: 👓 Checkout repository
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

      - name: Download artifact
        uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
        with:
          name: application
          path: hivemq-edge/src/frontend/dist

      - name: 🚥 Run Lighthouse audits
        uses: treosh/lighthouse-ci-action@72f881228236981b625ed765b928efb1786a1f55 # v11
        id: lighthouse
        with:
          temporaryPublicStorage: true # upload lighthouse report to the temporary storage
          ## budgetPath: ./budget.json # test performance budgets
          uploadArtifacts: true # save results as an action artifacts
          configPath: 'hivemq-edge/src/frontend/.lighthouserc.cjs'

#      - name: 📸 Run Percy visual tests
#        run: echo "Check the Percy tests on the other workflow"


Frontend - Visual Testing (Percy)

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Frontend - Visual Testing (Percy)

on:
  pull_request:
    branches: [master]
    paths:
      - hivemq-edge/src/frontend/**
env:
  GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./hivemq-edge/src/frontend/
    strategy:
      matrix:
        node-version: [18.16.0]

    steps:
      - name: 👓 Checkout repository
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

      - name: 🚚 Setup pnpm
        uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
        with:
          version: 8.4.0

      - name: 🔻 Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: 📦 Install dependencies
        run: pnpm install

      - name: 🏗 Build Application
        run: pnpm run build

      - name: 🧪 Run Cypress E2E
        uses: cypress-io/github-action@v6
        with:
          quiet: true
          working-directory: ./hivemq-edge/src/frontend/
          start: pnpm dev

      - name: 🧪 Run Cypress Component
        uses: cypress-io/github-action@v6
        with:
          quiet: true
          working-directory: ./hivemq-edge/src/frontend/
          component: true
          start: pnpm dev

      - name: 📸 Run Percy visual tests
        run: pnpm cypress:percy
        ## Percy should block the pipeline except if no money left on the plan :-)
        continue-on-error: true
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}


Build

name: Build
on: [push, pull_request, merge_group]
jobs:
  build:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-java@v3
        with:
          distribution: 'microsoft'
          java-version: '17'
      - uses: gradle/wrapper-validation-action@v1
      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2
        with:
          gradle-home-cache-cleanup: true
          gradle-home-cache-excludes: |
            gradle.properties
      - name: Setup gradle.properties
        env:
          GRADLE_PROPERTIES: ${{ vars.GRADLE_PROPERTIES }}
        shell: bash
        run: |
          mkdir -p ~/.gradle/
          echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV
          echo "${GRADLE_PROPERTIES}" > ~/.gradle/gradle.properties
      - name: Create placeholder assets dir
        run: mkdir -p ${{ env.GRADLE_USER_HOME }}/caches/fabric-loom/assets
      - run: ./gradlew check build publishToMavenLocal --stacktrace
      - uses: Juuxel/publish-checkstyle-report@v1
        if: ${{ failure() }}
        with:
          reports: |
            **/build/reports/checkstyle/*.xml
      - uses: actions/upload-artifact@v3
        with:
          name: Artifacts
          path: build/libs/
      - uses: actions/upload-artifact@v3
        with:
          name: Artifacts
          path: ./*/build/libs/
      - uses: actions/upload-artifact@v3
        with:
          name: Maven Local
          path: ~/.m2/repository

#  client_test:
#    runs-on: ubuntu-22.04
#    steps:
#      - uses: actions/checkout@v3
#        with:
#          fetch-depth: 0
#      - uses: actions/setup-java@v3
#        with:
#          distribution: 'microsoft'
#          java-version: '17'
#      - name: Run Auto test Client
#        uses: modmuss50/xvfb-action@v1
#        with:
#          run: ./gradlew runProductionAutoTestClient --stacktrace --warning-mode=fail
#      - uses: actions/upload-artifact@v3
#        if: always()
#        with:
#          name: Test Screenshots
#          path: run/screenshots

#  server_test:
#    runs-on: ubuntu-22.04
#    steps:
#      - uses: actions/checkout@v3
#        with:
#          fetch-depth: 0
#      - uses: actions/setup-java@v3
#        with:
#          distribution: 'microsoft'
#          java-version: '17'
#      - run: mkdir run && echo "eula=true" >> run/eula.txt
#      - run: ./gradlew runProductionAutoTestServer --stacktrace --warning-mode=fail

  check_resources:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-java@v3
        with:
          distribution: 'microsoft'
          java-version: '17'
      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2
        with:
          gradle-home-cache-cleanup: true
          gradle-home-cache-excludes: |
            gradle.properties
      - name: Setup gradle.properties
        env:
          GRADLE_PROPERTIES: ${{ vars.GRADLE_PROPERTIES }}
        shell: bash
        run: |
          mkdir -p ~/.gradle/
          echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV
          echo "${GRADLE_PROPERTIES}" > ~/.gradle/gradle.properties
      - name: Create placeholder assets dir
        run: mkdir -p ${{ env.GRADLE_USER_HOME }}/caches/fabric-loom/assets
      - run: ./gradlew generateResources --stacktrace
      - run: if [ -n "$(git status --porcelain)" ]; then exit 1; fi


Manage Issues

name: Manage Issues

on:
  issues:
    types: [ labeled, unlabeled ]

jobs:
  labels:
    runs-on: ubuntu-22.04
    steps:
      - uses: FabricMC/fabric-action-scripts@v2
        with:
          context: ${{ github.event.action }}
          label: ${{ github.event.label.name }}


Release

name: Release
on: [workflow_dispatch] # Manual trigger

permissions:
  actions: read
  contents: write

jobs:
  build:
    runs-on: ubuntu-22.04
    container:
      image: eclipse-temurin:20-jdk
      options: --user root
    steps:
      - run: apt update && apt install git -y && git --version
      - run: git config --global --add safe.directory /__w/ForgifiedFabricAPI/ForgifiedFabricAPI
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: FabricMC/fabric-action-scripts@v2
        id: changelog
        with:
          context: changelog
          workflow_id: release.yml
      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2
        with:
          gradle-home-cache-excludes: |
            gradle.properties
      - name: Setup gradle.properties
        env:
          GRADLE_PROPERTIES: ${{ vars.GRADLE_PROPERTIES }}
        shell: bash
        run: |
          mkdir -p ~/.gradle/
          echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV
          echo "${GRADLE_PROPERTIES}" > ~/.gradle/gradle.properties
      - name: Create placeholder assets dir
        run: mkdir -p ${{ env.GRADLE_USER_HOME }}/caches/fabric-loom/assets
      - uses: gradle/wrapper-validation-action@v1
      - run: ./gradlew checkVersion build publish curseforge github modrinth --stacktrace
        env:
          MAVEN_URL: ${{ secrets.MAVEN_URL }}
          MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
          MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
          CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
          CHANGELOG: ${{ steps.changelog.outputs.changelog }}
          SIGNING_SERVER: ${{ secrets.SIGNING_SERVER }}
          SIGNING_PGP_KEY: ${{ secrets.SIGNING_PGP_KEY }}
          SIGNING_JAR_KEY: ${{ secrets.SIGNING_JAR_KEY }}


Issue management - run stale action

name: Issue management - run stale action

on:
  schedule:
    # hourly at minute 41
    - cron: "41 * * * *"

permissions:
  contents: read

jobs:
  stale:
    permissions:
      issues: write         # for actions/stale to close stale issues
      pull-requests: write  # for actions/stale to close stale PRs
    runs-on: ubuntu-latest
    steps:
      - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e # v9.0.0
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          days-before-stale: 21
          days-before-close: 14
          only-labels: "needs author feedback"
          stale-issue-label: stale
          stale-issue-message: >
            This has been automatically marked as stale because it has been marked
            as needing author feedback and has not had any activity for 21 days.
            It will be closed automatically if there is no response from the author
            within 14 additional days from this comment.
          stale-pr-label: stale
          stale-pr-message: >
            This has been automatically marked as stale because it has been marked
            as needing author feedback and has not had any activity for 21 days.
            It will be closed automatically if there is no response from the author
            within 14 additional days from this comment.


Build

name: Build

on:
  push:
    branches:
      - main
      - release/*
  workflow_dispatch:

jobs:
  build:
    name: "build"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up JDK for running Gradle
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17
      - name: touch local props
        run: touch demo-app/local.properties
      - name: run gradle check
        run: ./gradlew check
      - name: build demo app
        working-directory: ./demo-app
        run: ./gradlew check assemble
      - name: publish snapshot
        run: ./gradlew publishToSonatype
        env:
          SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
          SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
          GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
          GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}

  markdown-link-check:
    # release branches are excluded to avoid unnecessary maintenance
    if: ${{ !startsWith(github.ref_name, 'release/') }}
    uses: ./.github/workflows/reusable-markdown-link-check.yml

  workflow-notification:
    needs:
      - build
    if: failure() && github.run_attempt == 1
    uses: ./.github/workflows/reusable-workflow-notification.yml
    with:
      success: ${{ needs.build.result == 'success' }}

  required-status-check:
    needs:
      - build
    runs-on: ubuntu-latest
    if: always()
    steps:
      - if: |
          needs.build.result != 'success'
        run: exit 1


CodeQL (daily)

name: CodeQL (daily)

on:
  schedule:
    # Daily at 03:55 (UTC)
    - cron: '55 3 * * *'
  workflow_dispatch:

jobs:
  analyze:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Java 17
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17

      - name: touch local props
        run: touch demo-app/local.properties

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: java
          # using "latest" helps to keep up with the latest Kotlin support
          # see https://github.com/github/codeql-action/issues/1555#issuecomment-1452228433
          tools: latest

      - uses: gradle/gradle-build-action@v3
        with:
          # skipping build cache is needed so that all modules will be analyzed
          arguments: assemble --no-build-cache

      - name: Perform CodeQL analysis
        uses: github/codeql-action/analyze@v3

  open-issue-on-failure:
    # open an issue on failure because it can be easy to miss CI failure notifications
    needs:
      - analyze
    if: always()
    uses: ./.github/workflows/reusable-workflow-notification.yml
    with:
      success: ${{ needs.analyze.result == 'success' }}


Draft CHANGELOG entries for a release

name: Draft CHANGELOG entries for a release

on:
  workflow_dispatch:

jobs:
  create_draft:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Run changelog draft script
        run: ./.github/scripts/draft-change-log-entries.sh


Gradle wrapper validation

name: Gradle wrapper validation
on:
  pull_request:
    paths:
      - '**/gradle/wrapper/**'
  push:
    paths:
      - '**/gradle/wrapper/**'

jobs:
  validation:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: gradle/actions/wrapper-validation@v3.4.2


PR build

name: PR build

on: pull_request

jobs:
  pr-checks:
    name: "pr-checks"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up JDK for running Gradle
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17
      - name: touch local props
        run: touch demo-app/local.properties
      - name: run gradle
        run: ./gradlew check
      - name: build demo app
        working-directory: ./demo-app
        run: ./gradlew check assemble

  required-status-check:
    needs:
      - pr-checks
    runs-on: ubuntu-latest
    if: always()
    steps:
      - if: |
          needs.pr-checks.result != 'success'
        run: exit 1


Prepare release branch

name: Prepare release branch
on:
  workflow_dispatch:

jobs:
  prereqs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Verify prerequisites
        run: |
          if [[ $GITHUB_REF_NAME != main ]]; then
            echo this workflow should only be run against main
            exit 1
          fi

          if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
            echo the change log is missing an \"Unreleased\" section
            exit 1
          fi

  create-pull-request-against-release-branch:
    runs-on: ubuntu-latest
    needs:
      - prereqs
    steps:
      - uses: actions/checkout@v4

      - name: Create release branch
        run: |
          version=$(.github/scripts/get-version.sh)
          if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
            release_branch_name=$(echo $version | sed -E 's/([0-9]+)\.([0-9]+)\.0/release\/v\1.\2.x/')
          else
            echo "unexpected version: $version"
            exit 1
          fi

          git push origin HEAD:$release_branch_name

          echo "VERSION=$version" >> $GITHUB_ENV
          echo "RELEASE_BRANCH_NAME=$release_branch_name" >> $GITHUB_ENV

      - name: Update version
        run: .github/scripts/update-version.sh $VERSION

      - name: Update version in README
        run: sed -Ei "s/(\"io.opentelemetry.android:android-agent:).*\"/\1${VERSION}-alpha\"/" README.md

      - name: Update the change log with the approximate release date
        run: |
          date=$(date "+%Y-%m-%d")
          sed -Ei "s/^## Unreleased$/## Version $VERSION ($date)/" CHANGELOG.md

      - name: Use CLA approved github bot
        run: .github/scripts/use-cla-approved-github-bot.sh

      - name: Create pull request against the release branch
        env:
          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
          GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
        run: |
          message="Prepare release $VERSION"
          branch="opentelemetrybot/prepare-release-${VERSION}"

          git checkout -b $branch
          git commit -a -m "$message"
          git push --set-upstream origin $branch
          gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \
                       --body "$message." \
                       --base $RELEASE_BRANCH_NAME

  create-pull-request-against-main:
    runs-on: ubuntu-latest
    needs:
      - prereqs
    steps:
      - uses: actions/checkout@v4

      - name: Set environment variables
        run: |
          version=$(.github/scripts/get-version.sh)
          if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
            major="${BASH_REMATCH[1]}"
            minor="${BASH_REMATCH[2]}"
            next_version="$major.$((minor + 1)).0"
          else
            echo "unexpected version: $version"
            exit 1
          fi
          echo "NEXT_VERSION=${next_version}" >> $GITHUB_ENV
          echo "VERSION=$version" >> $GITHUB_ENV

      - name: Update version
        run: .github/scripts/update-version.sh $NEXT_VERSION

      - name: Update version in README
        run: sed -Ei "s/(\"io.opentelemetry.android:android-agent:).*\"/\1${VERSION}-alpha\"/" README.md

      - name: Update the change log on main
        run: |
          # the actual release date on main will be updated at the end of the release workflow
          date=$(date "+%Y-%m-%d")
          sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version $VERSION ($date)/" CHANGELOG.md

      - name: Use CLA approved github bot
        run: .github/scripts/use-cla-approved-github-bot.sh

      - name: Create pull request against main
        env:
          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
          GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
        run: |
          message="Update version to $NEXT_VERSION"
          body="Update version to \`$NEXT_VERSION\`."
          branch="opentelemetrybot/update-version-to-${NEXT_VERSION}"

          git checkout -b $branch
          git commit -a -m "$message"
          git push --set-upstream origin $branch
          gh pr create --title "$message" \
                       --body "$body" \
                       --base main


Release

---
name: Release

on:
  workflow_dispatch:

jobs:
  release:
    name: "release"
    runs-on: ubuntu-latest
    steps:
      - run: |
          if [[ $GITHUB_REF_NAME != release/* ]]; then
            echo This workflow can only be run against release branches
            exit 1
          fi
      - uses: actions/checkout@v4

      - name: Set environment variables
        run: |
          version=$(.github/scripts/get-version.sh)
          if [[ $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
            major="${BASH_REMATCH[1]}"
            minor="${BASH_REMATCH[2]}"
            patch="${BASH_REMATCH[3]}"
          else
            echo "unexpected version: $version"
            exit 1
          fi
          if [[ $patch == 0 ]]; then
            if [[ $minor == 0 ]]; then
              prior_major=$((major - 1))
              prior_minor=$(grep -Po "^## Version $prior_major.\K[0-9]+" CHANGELOG.md | head -1)
              prior_version="$prior_major.$prior_minor"
            else
              prior_version="$major.$((minor - 1)).0"
            fi
          else
            prior_version="$major.$minor.$((patch - 1))"
          fi
          inst_version=$(grep ^opentelemetry-alpha gradle/libs.versions.toml | sed -E "s/^.*\"(.*)\"/\1/")
          sdk_version=$(cat gradle/libs.versions.toml  | grep "^opentelemetry =" | sed -E "s/^.*\"(.*)\"/\1/")

          echo "VERSION=$version" >> $GITHUB_ENV
          echo "PRIOR_VERSION=$prior_version" >> $GITHUB_ENV
          echo "INST_VERSION=$inst_version" >> $GITHUB_ENV
          echo "OTEL_SDK_VERSION=$sdk_version" >> $GITHUB_ENV

        # check out main branch to verify there won't be problems with merging the change log
        # at the end of this workflow
      - uses: actions/checkout@v4
        with:
          ref: main

      - name: Check that change log update was merged to main
        run: |
          if [[ $VERSION == *.0 ]]; then
            # not making a patch release
            if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then
              echo the pull request generated by prepare-release-branch.yml needs to be merged first
              exit 1
            fi
          fi

      # back to the release branch
      - uses: actions/checkout@v4
        with:
          # tags are needed for the generate-release-contributors.sh script
          fetch-depth: 0

      - name: Set up JDK for running Gradle
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17

      - name: Build and publish artifacts
        run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Pfinal=true
        env:
          SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
          SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
          GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
          GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}

      - name: Generate release notes
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          .github/scripts/generate-release-notes.sh "$VERSION" "$PRIOR_VERSION" "$INST_VERSION" "$OTEL_SDK_VERSION"

      - id: create-github-release
        name: Create GitHub release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release create --target $GITHUB_REF_NAME \
                            --title "Version $VERSION" \
                            --notes-file /tmp/release-notes.txt \
                            v$VERSION

          echo "version=$VERSION" >> $GITHUB_OUTPUT

      - name: Create release tag for release builds
        env:
          GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
        if: "${{ inputs.release_type == 'final' }}"
        run: |
          VERSION_NUMBER=$(grep ^version= gradle.properties  | sed -e 's/^.*=//')
          VERSION="v${VERSION_NUMBER}"
          git tag ${VERSION}
          git push origin ${VERSION}


name: Issue management - remove labels as needed

on:
  issue_comment:
    types: [created]

jobs:
  issue_comment:
    if: >
      contains(github.event.issue.labels.*.name, 'needs author feedback') &&
      github.event.comment.user.login == github.event.issue.user.login
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - name: Remove labels
        env:
          ISSUE_NUMBER: ${{ github.event.issue.number }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh issue edit --remove-label "needs author feedback" $ISSUE_NUMBER
          gh issue edit --remove-label "stale" $ISSUE_NUMBER


Reusable - Markdown link check

name: Reusable - Markdown link check

on:
  workflow_call:

jobs:
  markdown-link-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install markdown-link-check
        # https://github.com/tcort/markdown-link-check/issues/297
        run: npm install -g markdown-link-check@3.11.2

      - name: Run markdown-link-check
        run: |
          find . -type f \
                 -name '*.md' \
                 -not -path './CHANGELOG.md' \
               | xargs .github/scripts/markdown-link-check-with-retry.sh


Reusable - Workflow notification

# this is useful because notifications for scheduled workflows are only sent to the user who
# initially created the given workflow
name: Reusable - Workflow notification

on:
  workflow_call:
    inputs:
      success:
        type: boolean
        required: true

jobs:
  workflow-notification:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Open issue or add comment if issue already open
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          number=$(gh issue list --search "Workflow failed: $GITHUB_WORKFLOW" --limit 1 --json number -q .[].number)

          echo $number
          echo ${{ inputs.success }}

          if [[ $number ]]; then
            if [[ "${{ inputs.success }}" == "true" ]]; then
              gh issue close $number
            else
              gh issue comment $number \
                               --body "See [$GITHUB_WORKFLOW #$GITHUB_RUN_NUMBER](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)."
            fi
          elif [[ "${{ inputs.success }}" == "false" ]]; then
            gh issue create --title "Workflow failed: $GITHUB_WORKFLOW (#$GITHUB_RUN_NUMBER)" \
                            --body "See [$GITHUB_WORKFLOW #$GITHUB_RUN_NUMBER](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)."
          fi


ci

name: ci

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ${{ matrix.os }}
    name: Java ${{ matrix.java }} ${{ matrix.os }}
    strategy:
      matrix:
        java: [8, 11, 17, 21]
        os: [macos-latest, ubuntu-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4
      - uses: gradle/wrapper-validation-action@v3

      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v4
        with:
          java-version: ${{ matrix.java }}
          distribution: 'corretto'

      - name: Clean, build and javadoc
        run: ./gradlew clean build javadoc -Plog-tests --stacktrace

      - name: Allow long file names in git for windows
        if: matrix.os == 'windows-latest'
        run: git config --system core.longpaths true

      - name: CLI integration tests
        if: matrix.java == 17
        run: ./gradlew :smithy-cli:integ -Plog-tests --stacktrace

      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: java-${{ matrix.java }}-${{ matrix.os }}-test-report
          path: '**/build/reports/tests'

  build-docs:
    runs-on: ubuntu-latest
    name: Documentation Build
    steps:
    - uses: actions/checkout@v4

    - name: Set up Python 3.x
      uses: actions/setup-python@v5
      with:
        python-version: '3.x'

    - name: Install doc dependencies
      run: cd docs && make install

    - name: Build docs
      run: cd docs && make html

    - uses: actions/upload-artifact@v4
      with:
        name: built-docs
        path: docs/build/html


Analyze with CodeGuru Reviewer

# Runs CodeGuru Reviewer on push events,
# and uploads recommendations to the GitHub Security tab.
# For information on the setup see:
# https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample

name: Analyze with CodeGuru Reviewer
on: [push]
permissions:
    id-token: write
    contents: read
    security-events: write

jobs:
  CodeGuruReviewerScan:
    runs-on: ubuntu-latest
    steps:
    - name: Assume IAM Role
      id: iam-role
      continue-on-error: true
      uses: aws-actions/configure-aws-credentials@v4
      with:
        role-to-assume: arn:aws:iam::048169001733:role/GuruGitHubCICDRole
        aws-region: us-west-2

    - uses: actions/checkout@v4
      if: steps.iam-role.outcome == 'success'
      with:
        fetch-depth: 0

    - name: Set up JDK 1.8
      if: steps.iam-role.outcome == 'success'
      uses: actions/setup-java@v4
      with:
        distribution: 'corretto'
        java-version: 8

    - name: Compile
      if: steps.iam-role.outcome == 'success'
      run: ./gradlew compileJava -x test
    - name: Copy build artifacts
      if: steps.iam-role.outcome == 'success'
      run: |
        mkdir -p class-files
        cp -r smithy-*/build/classes/java/main/* class-files

    - name: Run CodeGuru Reviewer
      id: guruscan
      if: steps.iam-role.outcome == 'success'
      continue-on-error: true
      uses: aws-actions/codeguru-reviewer@v1.1
      with:
        s3_bucket: codeguru-reviewer-github-profiler-demo-048169001733-uw2
        build_path: ./class-files

    - name: Upload review result
      if: steps.iam-role.outcome == 'success' &&steps.guruscan.outcome == 'success'
      uses: github/codeql-action/upload-sarif@v3
      with:
        sarif_file: codeguru-results.sarif.json


make-docs

name: make-docs
on:
  release:
    types: [released]
  workflow_dispatch: # on button click
    inputs:
      javadocs:
        type: boolean
        description: 'Build JavaDocs?'
        required: true
      release:
        type: boolean
        description: 'Release the docs?'
        required: true

env:
  ARTIFACTS_DIR: /tmp/artifacts

jobs:
  build-docs:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repo
      uses: actions/checkout@v4
    - name: Setup
      run: |
        mkdir -p $ARTIFACTS_DIR

    - name: Build JavaDocs
      # run if 'javadocs' is not set to false
      if: ${{ !contains(inputs.javadocs, 'false') }}
      run: |
        VERSION=$(cat VERSION)
        mkdir -p $ARTIFACTS_DIR/javadoc
        ./gradlew javadoc
        cp -R build/docs/javadoc/latest $ARTIFACTS_DIR/javadoc/$VERSION
        mkdir $ARTIFACTS_DIR/javadoc/latest
        cat << EOF > $ARTIFACTS_DIR/javadoc/latest/index.html
        <!DOCTYPE html>
        <meta charset="utf-8">
        <title>Redirecting to latest javadocs</title>
        <meta http-equiv="refresh" content="0; URL=../${VERSION}/">
        EOF

    - name: Build Smithy docs
      run: |
        cd docs
        pip3 install -r requirements.txt
        make clean
        make html
        cp -R build/html/* $ARTIFACTS_DIR
        rm $ARTIFACTS_DIR/.buildinfo || true
        rm $ARTIFACTS_DIR/objects.inv || true

    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: smithy-docs
        path: ${{ env.ARTIFACTS_DIR }}
        retention-days: 7

  publish-docs:
    runs-on: ubuntu-latest
    # run if 'release' is not set to false
    if: ${{ !contains(inputs.release, 'false') }}
    needs: build-docs
    steps:
    - name: Checkout GitHub pages branch
      uses: actions/checkout@v4
      with:
        ref: 'gh-pages'
    - name: Download artifacts
      id: download
      uses: actions/download-artifact@v4
      with:
        name: smithy-docs
        path: /tmp/smithy-docs
    - name: Copy artifacts
      run: |
        git pull
        cp -R /tmp/smithy-docs/* .
        git config --global user.name "smithy-automation"
        git config --global user.email "github-smithy-automation@amazon.com"
        git add -A
        git commit -m "Update documentation"
        git push


post-release

# Runs certain jobs after a release is published or on an as-needed basis (manually),
# e.g. triggering an update to the homebrew-tap when a new version of the CLI is available

name: post-release
on:
  release:
    types: [released]
  workflow_dispatch: # on button click
    inputs:
      version:
        description: 'The version that was released (e.g. 1.47.0)'
        required: true
        type: string

env:
  version: ${{ github.event.inputs.version || github.ref_name }}

jobs:
  homebrew-tap:
    runs-on: ubuntu-latest
    steps:
    - name: Trigger homebrew-tap update
      uses: benc-uk/workflow-dispatch@v1
      with:
        workflow: autoupdate
        repo: smithy-lang/homebrew-tap
        ref: 'main'
        inputs: '{ "version": "${{ env.version }}" }'
        # Required when using the `repo` option
        token: "${{ secrets.PR_TOKEN }}"


sdk-codegen-ci

name: sdk-codegen-ci

on:
  workflow_dispatch:

jobs:
  build-aws-sdk-js-v3:
    runs-on: ubuntu-latest
    steps:
      - name: Use Node.js 14.x
        uses: actions/setup-node@v4
        with:
          node-version: 14.x

      - name: Increase Node Heap space
        run: echo "NODE_OPTIONS=--max-old-space-size=16384" >> $GITHUB_ENV

      - uses: actions/checkout@v4
      - id: smithy-version
        uses: ./.github/workflows/checkout-and-build-smithy

      - name: Add smithyVersion env variable
        run: echo "smithyVersion=${{ steps.smithy-version.outputs.smithy-version }}" >> $GITHUB_ENV

      - name: Checkout smithy-typescript
        uses: actions/checkout@v4
        with:
          repository: awslabs/smithy-typescript
          path: smithy-typescript

      - name: Build smithy-typescript
        run: cd smithy-typescript && ./gradlew -PsmithyVersion=$smithyVersion clean build publishToMavenLocal

      - name: Checkout aws-sdk-js-v3
        uses: actions/checkout@v4
        with:
          repository: aws/aws-sdk-js-v3
          path: aws-sdk-js-v3

      - name: Build aws-sdk-js-v3
        run: cd aws-sdk-js-v3/codegen && ./gradlew -PsmithyVersion=$smithyVersion clean build

      - name: Test aws-sdk-js-v3
        run: cd aws-sdk-js-v3 && yarn && yarn test:all

  build-aws-sdk-go-v2:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-java@v4
        with:
          java-version: 17
          distribution: 'corretto'

      - name: Set up Go 1.19
        uses: actions/setup-go@v5
        with:
          go-version: 1.19

      - uses: actions/checkout@v4
      - id: smithy-version
        uses: ./.github/workflows/checkout-and-build-smithy

      - name: Add smithyVersion env variable
        run: echo "smithyVersion=${{ steps.smithy-version.outputs.smithy-version }}" >> $GITHUB_ENV

      - name: Checkout smithy-go
        uses: actions/checkout@v4
        with:
          repository: aws/smithy-go
          path: smithy-go

      - name: Build smithy-go
        run: cd smithy-go/codegen && ./gradlew -PsmithyVersion=$smithyVersion clean build publishToMavenLocal

      - name: Checkout aws-sdk-go-v2
        uses: actions/checkout@v4
        with:
          repository: aws/aws-sdk-go-v2
          path: aws-sdk-go-v2

      - name: Build aws-sdk-go-v2
        run: |
          cd aws-sdk-go-v2/codegen
          ./gradlew -PsmithyVersion=$smithyVersion clean build -Plog-tests
          ./gradlew clean

      - name: Run aws-sdk-go-v2 protocol tests
        # This is essentially the `ci-test` command in the Makefile
        run: |
          cd aws-sdk-go-v2 && make update-requires gen-repo-mod-replace \
          update-module-metadata smithy-annotate-stable gen-config-asserts gen-internal-codegen \
          copy-attributevalue-feature gen-mod-dropreplace-smithy-. min-go-version-. tidy-modules-. \
          add-module-license-files gen-aws-ptrs format unit-race ci-test-generate-validate

  build-aws-sdk-kotlin:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - id: smithy-version
        uses: ./.github/workflows/checkout-and-build-smithy

      - name: Add smithyVersion env variable
        run: echo "smithyVersion=${{ steps.smithy-version.outputs.smithy-version }}" >> $GITHUB_ENV

      - name: Checkout smithy-kotlin
        uses: actions/checkout@v4
        with:
          repository: awslabs/smithy-kotlin
          path: smithy-kotlin

      - name: Build smithy-kotlin
        run: cd smithy-kotlin && ./gradlew -PsmithyVersion=$smithyVersion clean build publishToMavenLocal

      - name: Checkout aws-sdk-kotlin
        uses: actions/checkout@v4
        with:
          repository: awslabs/aws-sdk-kotlin
          path: aws-sdk-kotlin

      - name: Build aws-sdk-kotlin
        run: cd aws-sdk-kotlin && ./gradlew -PsmithyVersion=$smithyVersion clean build

      - name: Build aws-sdk-kotlin
        run: cd aws-sdk-kotlin && ./gradlew -PsmithyVersion=$smithyVersion clean build publishToMavenLocal

      - name: Run aws-sdk-kotlin protocol tests
        run: cd aws-sdk-kotlin && ./gradlew -PsmithyVersion=$smithyVersion -p codegen/protocol-tests testAllProtocols

  build-aws-sdk-swift:
    runs-on: ubuntu-latest
    steps:
      - uses: swift-actions/setup-swift@v2
      - uses: actions/setup-java@v4
        with:
          java-version: 11
          distribution: 'corretto'

      - uses: actions/checkout@v4
      - id: smithy-version
        uses: ./.github/workflows/checkout-and-build-smithy

      - name: Add smithyVersion env variable
        run: echo "smithyVersion=${{ steps.smithy-version.outputs.smithy-version }}" >> $GITHUB_ENV

      - name: Checkout aws-crt-swift
        uses: actions/checkout@v4
        with:
          repository: awslabs/aws-crt-swift
          path: Sources/SmithySwift/aws-crt-swift

      - name: Checkout smithy-swift
        uses: actions/checkout@v4
        with:
          repository: awslabs/smithy-swift
          path: Sources/SmithySwift/smithy-swift

      - name: Build smithy-swift
        run: |
          echo $smithyVersion && cd Sources/SmithySwift/smithy-swift
          ./gradlew -PsmithyVersion=$smithyVersion clean build publishToMavenLocal

      - name: Checkout aws-sdk-swift
        uses: actions/checkout@v4
        with:
          repository: awslabs/aws-sdk-swift
          path: Sources/SmithySwift/aws-sdk-swift

      - name: Set SMITHY_SWIFT_CI_DIR env variable
        run: echo "SMITHY_SWIFT_CI_DIR=$GITHUB_WORKSPACE/Sources/SmithySwift/smithy-swift" >> $GITHUB_ENV

      - name: Set AWS_SDK_SWIFT_CI_DIR env variable
        run: echo "AWS_SDK_SWIFT_CI_DIR=$GITHUB_WORKSPACE/Sources/SmithySwift/aws-sdk-swift" >> $GITHUB_ENV

      - name: Build aws-sdk-swift
        run: cd Sources/SmithySwift/aws-sdk-swift && ./gradlew -PsmithyVersion=$smithyVersion clean build

      - name: Generate Swift SDKs
        run: cd Sources/SmithySwift/aws-sdk-swift && ./gradlew -PsmithyVersion=$smithyVersion -p codegen/sdk-codegen build

      - name: Build codegen/protocol-test-codegen-local
        run: cd Sources/SmithySwift/aws-sdk-swift && ./gradlew -PsmithyVersion=$smithyVersion -p codegen/protocol-test-codegen-local build

      - name: Run local protocol tests
        run: cd Sources/SmithySwift/aws-sdk-swift/codegen/protocol-test-codegen-local/build && swift test

  build-smithy-rs:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: 1.62.1

      - uses: actions/setup-java@v4
        with:
          java-version: 11
          distribution: 'corretto'

      - uses: actions/checkout@v4
      - id: smithy-version
        uses: ./.github/workflows/checkout-and-build-smithy

      - name: Add smithyVersion env variable
        run: echo "smithyVersion=${{ steps.smithy-version.outputs.smithy-version }}" >> $GITHUB_ENV

      - name: Check out smithy-rs
        uses: actions/checkout@v4
        with:
          repository: awslabs/smithy-rs
          ref: main
          path: smithy-rs

      - name: Check out aws-sdk-rust
        uses: actions/checkout@v4
        with:
          repository: awslabs/aws-sdk-rust
          ref: main
          path: aws-sdk-rust

      - name: Install rustfmt
        run: rustup component add rustfmt

      - name: Build smithy-rs
        run: |
          cd smithy-rs
          ./gradlew :aws:sdk:assemble -PsmithyVersion=$smithyVersion

      - name: Test smithy-rs
        run: |
          cd smithy-rs
          ./gradlew :aws:sdk:cargoTest -PsmithyVersion=$smithyVersion


Close stale issues

name: "Close stale issues"

# Controls when the action will run.
on:
  schedule:
    - cron: "0 0 * * *"

jobs:
  cleanup:
    runs-on: ubuntu-latest
    name: Stale issue job
    steps:
      - uses: aws-actions/stale-issue-cleanup@v6
        with:
          # Targeted types
          issue-types: issues

          # Issue timing
          days-before-stale: 60
          days-before-close: 14
          days-before-ancient: 365

          # Labels
          stale-issue-label: closing-soon
          exempt-issue-labels: bug,documentation,feature-request,investigating,protocol-test
          response-requested-label: response-requested

          # Messages
          stale-issue-message: This issue has not received a response in a while. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.
          ancient-issue-message: We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

          # If you don't want to mark a issue as being ancient based on a
          # threshold of "upvotes", you can set this here. An "upvote" is
          # the total number of +1, heart, hooray, and rocket reactions
          # on an issue.
          minimum-upvotes-to-exempt: 5

          # Don't set closed-for-staleness label to skip closing very old issues
          # regardless of label
          closed-for-staleness-label: closed-for-staleness

          repo-token: ${{ secrets.GITHUB_TOKEN }}
          loglevel: DEBUG


Get latest smithy gradle plugin version

name: Get latest smithy gradle plugin version
on:
  workflow_dispatch: # on button click
  # Uncomment once permissions to create PRs has been added.
  schedule:
    # Runs every wednesday at 11
    - cron:  '0 11 * * WED'

jobs:
  get-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Fetch latest smithy-gradle-plugin version
        id: fetch-latest
        run: |
          echo "latestSmithyGradle=$( \
           curl -sL https://api.github.com/repos/smithy-lang/smithy-gradle-plugin/tags | \
           jq -r '.[0].name')" >> $GITHUB_OUTPUT
      - name: Get current version
        id: get-current
        run: |
          cat gradle.properties >> $GITHUB_OUTPUT
      - name: Check if the current version of smithy-gradle-plugin should be updated
        id: update-check
        run: |
          echo update-required=$( \
          [ "${{ steps.get-current.outputs.smithyGradleVersion }}" = "${{ steps.fetch-latest.outputs.latestSmithyGradle }}" ] \
          && echo "false" || echo "true") >> $GITHUB_OUTPUT
      - name: Set up new git branch for version bump
        id: git-setup
        if: steps.update-check.outputs.update-required == 'true'
        run: |
          git checkout -b "automation/bump-smithy-gradle-version/${{ steps.fetch-latest.outputs.latestSmithyGradle }}"
          git config --global user.email "github-aws-smithy-automation@amazon.com"
          git config --global user.name "Smithy Automation"
      - name: Find and replace gradle version in properties files
        id: replace-current-version-properties
        if: steps.update-check.outputs.update-required == 'true'
        run: |
          find . -type f -name 'gradle.properties' \
          -exec sed -i "s|smithyGradleVersion=${{ steps.get-current.outputs.smithyGradleVersion }}|smithyGradleVersion=${{ steps.fetch-latest.outputs.latestSmithyGradle }}|g" {} \;
      - name: Create PR
        if: steps.update-check.outputs.update-required == 'true'
        run: |
          git add .
          git commit -m 'Update smithy-gradle-plugin Version'
          git push --set-upstream origin "automation/bump-smithy-gradle-version/${{ steps.fetch-latest.outputs.latestSmithyGradle }}"
          gh pr create \
            --title "[Automation] smithy-gradle-plugin Version Bump - \`${{ steps.fetch-latest.outputs.latestSmithyGradle }}\`" \
            --body "Automated pull request to bump smithy gradle plugin version from ${{ steps.get-current.outputs.smithyGradleVersion }} to ${{ steps.fetch-latest.outputs.latestSmithyGradle }}" \
            --base main
          echo "PR Created for version bump to ${{ steps.fetch-latest.outputs.latestSmithyGradle }}"
        env:
          GITHUB_TOKEN: ${{ secrets.PR_TOKEN }}


Core/hadoop2 CI with Maven

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Core/hadoop2 CI with Maven

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  push:
    branches:
      - "master"
      - "0.**"

  pull_request:
    branches:
      - "master"
      - "0.**"
    paths:
      - "ams/**"
      - "core/**"
      - "mixed-format/flink/**"
      - "mixed-format/hive/**"
      - "mixed-format/spark/**"
      - "pom.xml"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: maven

      - name: Validate checkstyle first
        run: mvn validate

      - name: Build all module with Maven
        run: mvn clean install -pl '!mixed-format/trino' -Djacoco.flink.skip=true -B -ntp -Dhadoop=v2

      - name: Code coverage
        uses: codecov/codecov-action@v3
        with:
          verbose: true
          flags: core


Core/hadoop3 CI with Maven

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Core/hadoop3 CI with Maven

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  push:
    branches:
      - "master"
      - "0.**"

  pull_request:
    branches:
      - "master"
      - "0.**"
    paths:
      - "ams/**"
      - "core/**"
      - "mixed-format/flink/**"
      - "mixed-format/hive/**"
      - "mixed-format/spark/**"
      - "pom.xml"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: maven

      - name: Validate checkstyle first
        run: mvn validate

      - name: Build all module with Maven
        run: mvn clean install -pl '!mixed-format/trino' -Djacoco.flink.skip=true -B -ntp

      - name: Code coverage
        uses: codecov/codecov-action@v3
        with:
          verbose: true
          flags: core


Publish Docker Image

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This workflow will build docker images when commit merged or pushed to master.
# or tags pushed.

name: Publish Docker Image

on:
  push:
    branches:
      - "master"
    tags:
      - "v*"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  docker-amoro:
    name: Push Amoro Docker Image to Docker Hub
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.repository, 'NetEase/') }}
    strategy:
      matrix:
        hadoop: [ "v3" ]
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: maven
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Set up Docker tags
        uses: docker/metadata-action@v5
        id: meta
        with:
          flavor: |
            latest=auto
          images: |
            name=arctic163/amoro
          tags: |
            type=ref,event=branch,enable=${{ matrix.hadoop == 'v3' }},suffix=-snapshot
            type=ref,event=branch,enable=${{ matrix.hadoop == 'v3' }},suffix=-snapshot-hadoop3
            type=ref,event=branch,enable=${{ matrix.hadoop == 'v2' }},suffix=-snapshot-hadoop2
            type=semver,event=tag,enable=${{ matrix.hadoop == 'v3' }},pattern={{version}}
            type=semver,event=tag,enable=${{ matrix.hadoop == 'v2' }},pattern={{version}}-hadoop2

      - name: Print tags
        run: echo '${{ steps.meta.outputs.tags }}'

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Set Maven Build Properties
        if: ${{ matrix.hadoop != 'v3' }}
        run: |
          echo "MVN_HADOOP=-Dhadoop=${{ matrix.hadoop }}" >> $GITHUB_ENV

      - name: Build dist module with Maven
        run: mvn clean install -pl 'ams/dist' -am -e ${MVN_HADOOP} -DskipTests -B -ntp

      - name: Build and Push Amoro Docker Image
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          file: docker/amoro/Dockerfile
          platforms: linux/amd64,linux/arm64
          tags: ${{ steps.meta.outputs.tags }}

  docker-optimizer-flink:
    name: Push Amoro Optimizer-Flink Docker Image to Docker Hub
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.repository, 'NetEase/') }}
    strategy:
      matrix:
        flink: [ "1.14.6", "1.18.1" ]
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: maven
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Set up Docker tags
        uses: docker/metadata-action@v5
        id: meta
        with:
          flavor: |
            latest=auto
          images: |
            name=arctic163/optimizer-flink
          tags: |
            type=ref,event=branch,enable=${{ matrix.flink == '1.14.6' }},suffix=-snapshot
            type=ref,event=branch,enable=${{ matrix.flink == '1.14.6' }},suffix=-snapshot-flink1.14
            type=ref,event=branch,enable=${{ matrix.flink == '1.18.1' }},suffix=-snapshot-flink1.18
            type=semver,enable=${{ matrix.flink == '1.14.6' }},pattern={{version}}
            type=semver,enable=${{ matrix.flink == '1.14.6' }},pattern={{version}}-flink1.14
            type=semver,enable=${{ matrix.flink == '1.18.1' }},pattern={{version}}-flink1.18

      - name: Print tags
        run: echo '${{ steps.meta.outputs.tags }}'

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Set optimizer flink version
        run: |
          OPTIMIZER_FLINK=${{ matrix.flink }} && \
          echo "OPTIMIZER_FLINK=-Dflink-optimizer.flink-version${OPTIMIZER_FLINK}" >> $GITHUB_ENV
          if [[ "$OPTIMIZER_FLINK" < "1.15" ]]; then
            echo "Adding -Pflink-pre-1.15 for Flink version less than 1.15"
            echo "OPTIMIZER_FLINK=-Pflink-pre-1.15 -Dflink-optimizer.flink-version=${OPTIMIZER_FLINK}" >> $GITHUB_ENV
          fi

      - name: Set ENV Amoro version
        id: version
        run: |
          AMORO_VERSION=`cat pom.xml | grep 'amoro-parent' -C 3 | grep -Eo '<version>.*</version>' | awk -F'[><]' '{print $3}'` \
          && echo "$AMORO_VERSION" \
          && echo "AMORO_VERSION=${AMORO_VERSION}" >> $GITHUB_ENV \
          && echo "AMORO_VERSION=${AMORO_VERSION}" >> $GITHUB_OUTPUT

      - name: Build optimizer module with Maven
        run: mvn clean package -pl 'ams/optimizer/flink-optimizer' -am -e ${OPTIMIZER_FLINK} -DskipTests -B -ntp

      - name: Build and Push Flink Optimizer Docker Image
        uses: docker/build-push-action@v4
        env:
          AMORO_VERSION: ${{ steps.version.outputs.AMORO_VERSION }}
        with:
          context: .
          push: true
          file: docker/optimizer-flink/Dockerfile
          platforms: linux/amd64,linux/arm64
          tags: ${{ steps.meta.outputs.tags }}
          build-args: |
            FLINK_VERSION=${{ matrix.flink }}
            OPTIMIZER_JOB=ams/optimizer/flink-optimizer/target/flink-optimizer-${{ env.AMORO_VERSION }}-jar-with-dependencies.jar

  docker-optimizer-spark:
    name: Push Amoro Optimizer-Spark Docker Image to Docker Hub
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.repository, 'NetEase/') }}
    strategy:
      matrix:
        spark: [ "3.3.3" ]
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: maven
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Set up Docker tags
        uses: docker/metadata-action@v5
        id: meta
        with:
          flavor: |
            latest=auto
          images: |
            name=arctic163/optimizer-spark
          tags: |
            type=ref,event=branch,enable=${{ matrix.spark == '3.3.3' }},suffix=-snapshot-spark3.3
            type=semver,enable=${{ matrix.spark == '3.3.3' }},pattern={{version}}-spark3.3

      - name: Print tags
        run: echo '${{ steps.meta.outputs.tags }}'

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Set optimizer spark version
        run: |
          OPTIMIZER_SPARK=${{ matrix.spark }} && \
          echo "OPTIMIZER_SPARK=-Dspark-optimizer.spark-version${OPTIMIZER_SPARK}" >> $GITHUB_ENV

      - name: Set ENV Amoro version
        id: version
        run: |
          AMORO_VERSION=`cat pom.xml | grep 'amoro-parent' -C 3 | grep -Eo '<version>.*</version>' | awk -F'[><]' '{print $3}'` \
          && echo "$AMORO_VERSION" \
          && echo "AMORO_VERSION=${AMORO_VERSION}" >> $GITHUB_ENV \
          && echo "AMORO_VERSION=${AMORO_VERSION}" >> $GITHUB_OUTPUT

      - name: Build optimizer module with Maven
        run: mvn clean package -pl 'ams/optimizer/spark-optimizer' -am -e ${OPTIMIZER_SPARK} -DskipTests -B -ntp

      - name: Build and Push Spark Optimizer Docker Image
        uses: docker/build-push-action@v4
        env:
          AMORO_VERSION: ${{ steps.version.outputs.AMORO_VERSION }}
        with:
          context: .
          push: true
          file: docker/optimizer-spark/Dockerfile
          platforms: linux/amd64,linux/arm64
          tags: ${{ steps.meta.outputs.tags }}
          build-args: |
            SPARK_VERSION=${{ matrix.spark }}
            OPTIMIZER_JOB=ams/optimizer/spark-optimizer/target/spark-optimizer-${{ env.AMORO_VERSION }}-jar-with-dependencies.jar

  docker-quickdemo:
    name: Push Amoro Quick-Demo Docker Image to Docker Hub
    runs-on: ubuntu-latest
    needs: docker-amoro
    if: ${{ startsWith(github.repository, 'NetEase/') && startsWith(github.ref, 'refs/tags/' )}}
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: maven
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Set up Docker tags
        uses: docker/metadata-action@v5
        id: meta
        with:
          flavor: |
            latest=auto
          images: |
            name=arctic163/quickdemo
          tags: |
            type=ref,event=branch,suffix=-snapshot
            type=semver,pattern={{version}}

      - name: Print tags
        run: echo '${{ steps.meta.outputs.tags }}'

      - name: Set Amoro Tag
        id: tag
        run: |
          AMORO_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1) && echo "AMORO_TAG=${AMORO_TAG#*:}" >> $GITHUB_OUTPUT

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build optimizer module with Maven
        run: mvn clean package -pl 'mixed/flink/v1.17/flink-runtime' -am -e -DskipTests -B -ntp

      - name: Build and Push Flink Optimizer Docker Image
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          file: docker/quickdemo/Dockerfile
          platforms: linux/amd64,linux/arm64
          tags: ${{ steps.meta.outputs.tags }}
          build-args: |
            AMORO_TAG=${{ steps.tag.outputs.AMORO_TAG }}
            FLINK_VERSION=1.18.1
            ICEBERG_VERSION=1.3.1


Pull Request Labeler

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: "Pull Request Labeler"
on: pull_request_target

permissions:
  contents: read
  pull-requests: write

jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/labeler@v4
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          sync-labels: true


Trino CI with Maven

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Trino CI with Maven

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  push:
    branches:
      - "master"
      - "0.**"

  pull_request:
    branches:
      - "master"
      - "0.**"
    paths:
      - "ams/**"
      - "core/**"
      - "mixed-format/hive/**"
      - "mixed-format/trino/**"
      - "pom.xml"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: maven

      - name: Validate checkstyle first
        run: mvn validate -P trino-spotless

      - name: Install dependency with Maven
        run: mvn clean install -DskipTests -pl 'ams/api,core,mixed-format/hive' -Dhadoop=v2 -am -B -P trino-spotless

      - name: Build with Maven
        run: mvn clean test -pl 'mixed-format/trino' -B -ntp -Dhadoop=v2 -P trino-spotless

      - name: Code coverage
        uses: codecov/codecov-action@v3
        with:
          verbose: true
          flags: trino


CI

name: CI

on:
  push:
    branches:
      - master

  pull_request:

jobs:
  ci:
    runs-on: ubuntu-20.04

    strategy:
      fail-fast: false

      matrix:
        java: [8, 11]

    steps:
      - name: checkout
        uses: actions/checkout@v2

      - name: Set up java
        uses: actions/setup-java@v3
        with:
          distribution: zulu
          java-version: ${{ matrix.java }}
          cache: maven

      - name: Install dependencies
        run: ./mvnw install -B -Dmaven.test.skip -Dinvoker.skip

      - name: Run tests
        run: ./mvnw verify -B -Pintegration-test


Pull Request pipeline

# This workflow is called for every pull request regardless which branch its targets
#
# 'coral-workflow' runs the jobs for coral when
# - a PR is opened, synchronize, or reopened
# - & there are changes inside `coral` directory
# -> it does _not_ differentiate between a PR that is ready for review or a draft
#
# 'coral-workflow' runs the jobs for coral when
# - a PR is opened, synchronize, or reopened
# - & there are changes detected in the directories cluster-api and core
#     the file pom.xml
# - & the PR is not in DRAFT status
# - OR the PR is in draft status, but was marked as "Ready for review"
name: Pull Request pipeline

on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
  workflow_dispatch:

jobs:
  check-changes:
    runs-on: ubuntu-latest
    outputs:
      changes-maven: ${{ steps.check-changed-dirs.outputs.changes-maven }}
      changes-coral: ${{ steps.check-changed-dirs.outputs.changes-coral }}
    steps:
      - name: Checkout code
        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332  #v4.1.7
        with:
          ref: ${{ github.ref }}
          fetch-depth: 0

      - id: check-changed-dirs
        name: Check directories of changes
        run: |
          if git diff --name-only HEAD^ HEAD | grep -q '^coral/'; then
            echo "Changes detected in coral directory 🪸"
            echo "changes-coral=true" >> $GITHUB_OUTPUT
          fi
          if git diff --name-only HEAD^ HEAD | grep -qE '^cluster-api/|^core/|^pom.xml$'; then
            echo "Changes detected for cluster-api/core or pom.xml"
            echo "changes-maven=true" >> $GITHUB_OUTPUT
          fi

  run-maven-jobs:
    needs: check-changes
    # the condition makes sure that changes on a draft PR do not trigger the job, except it's a "ready_for_review" event
    # in that case, the job will only run if there are actual changes relevant to maven
    if: (github.event.pull_request.draft == false || github.event.action == 'ready_for_review') && needs.check-changes.outputs.changes-maven == 'true'
    uses: ./.github/workflows/jobs-maven.yaml

  run-coral-jobs:
    needs: check-changes
    # since we're triggering the workflow for the "ready_for_review" event to avoid
    # the maven jobs to run on a draft, this condition makes sure that the coral jobs
    # are not triggered for "ready_for_review" as they are already running on drafts
    # so the "ready_for_review" event is not relevant here.
    # it also makes sure to only run the jobs when there are changes on the branch
    # that relate to coral
    if: needs.check-changes.outputs.changes-coral == 'true' && github.event.action != 'ready_for_review'
    uses: ./.github/workflows/jobs-coral.yaml


Checks enabling merge to main

# This workflow is called when a pull request  is approved
# that targets the protected branch `main`.
# The job `merge-to-main` ("Status check for enabling merging to main")
# is a required status check.
# (https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28)
# We can only merge to main when this job has run and is green.
# The workflow can be triggered manually, too.
name: Checks enabling merge to main

on:
  pull_request_review:
    types:
      - submitted
    branches:
      - main
  pull_request:
    types:
      - synchronize
    branches:
      - main
  workflow_dispatch:

jobs:
  checkout-code:
    if: (github.event_name == 'pull_request' && github.event.action == 'synchronize') || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332  #v4.1.7
        with:
          ref: ${{ github.ref }}
          fetch-depth: 0

  run-coral-jobs:
    if: (github.event_name == 'pull_request' && github.event.action == 'synchronize') || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
    name: Run coral workflow before enabling merge to main
    needs: checkout-code
    uses: ./.github/workflows/jobs-coral.yaml

  run-maven-jobs:
    if: (github.event_name == 'pull_request' && github.event.action == 'synchronize') || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
    name: Run maven workflow before enabling merge to main
    needs: checkout-code
    uses: ./.github/workflows/jobs-maven.yaml

  run-e2e-tests:
    if: (github.event_name == 'pull_request' && github.event.action == 'synchronize') || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
    name: Run Playwright e2e test before enabling merge to main
    needs: checkout-code
    permissions:
      actions: write
    uses: ./.github/workflows/end-to-end-tests.yaml

  merge-to-main:
    name: Status check for enabling merging to main
    if: (github.event_name == 'pull_request' && github.event.action == 'synchronize') || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved')
    runs-on: ubuntu-latest
    needs: [ run-maven-jobs, run-coral-jobs, run-e2e-tests ]

    steps:
      - name: Confirm check
        run: echo "🎉 this was successful"


Typescript checks

# ℹ
# This workflow runs for pull_requests that are based on main
# if there is a change in coral, including file `coral/types/api.d.ts`
#    - 1. it runs the coral setup
#    - 2. it runs the typescript compiler
#       - if ok: ends the workflow ✅
#       - if tsc has errors: fails the workflow ⛔

# This workflow ensures that our type definition for APIs are always in
# sync and that API changes don't break things in coral.

name: Typescript checks

on:
  pull_request:
    paths:
      - 'coral/**'

jobs:
  typecheck:
    name: Type check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
        with:
          persist-credentials: false

      - name: Setup coral
        uses: ./.github/actions/setup-coral

      - name: Run tsc
        working-directory: ./coral
        run: pnpm tsc


Coral related jobs

# This workflow is not automatically triggered, but needs to be
# called from e.g. another workflow file. It enables us to
# reuse the jobs run here in different workflows.
# Please note that in order to run this jobs, the
# code needs to be checked already out when using the job
name: Coral related jobs

on:
  workflow_call

permissions:
  contents: read

jobs:
  type-check:
    name: TypeScript compiler
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332  #v4.1.7
        with:
          persist-credentials: false

      - name: Setup coral
        uses: ./.github/actions/setup-coral

      - name: Run tsc
        working-directory: ./coral
        run: pnpm run tsc

  static_code_analysis:
    name: Static code analysis
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332  #v4.1.7
        with:
          persist-credentials: false

      - name: Setup coral
        uses: ./.github/actions/setup-coral

      - name: Run static checks
        working-directory: ./coral
        run: pnpm run lint

  tests:
    name: Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332  #v4.1.7
        with:
          persist-credentials: false

      - name: Setup coral
        uses: ./.github/actions/setup-coral

      - name: Get number of CPU cores
        id: cpu-cores
        uses: SimenB/github-actions-cpu-cores@v2
      - name: run tests
        working-directory: ./coral
        run: pnpm run test-ci --max-workers ${{ steps.cpu-cores.outputs.count }}


Java CI with Maven

# This workflow is not automatically triggered, but needs to be
# called from e.g. another workflow file. It enables us to
# reuse the jobs run here in different workflows.
# Please note that in order to run this jobs, the
# code needs to be checked already out when using the job

# This workflow will build a Java project with Maven, and cache/restore any
# dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven

env:
  NODE_VERSION: 18

on:
  workflow_call

permissions:
  contents: read

jobs:
  build:
    strategy:
      matrix:
        java-version: [17, 21]
        runs-on: [ubuntu-latest]
    name: Jdk ${{ matrix.java-version }}, os ${{ matrix.runs-on }}
    runs-on: ${{ matrix.runs-on }}
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332  #v4.1.7
        with:
          persist-credentials: false
      - name: Setup node.js
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: ${{ env.NODE_VERSION }}
      - name: Install node.js uglify packages
        run: npm install uglify-js -g && npm install uglifycss -g
      - name: Set up JDK ${{ matrix.java-version }}
        uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java-version }}
          cache: maven
      - name: Build and run tests with Maven
        run: mvn --batch-mode --update-snapshots verify