diff --git a/.github/workflows/build-and-run-tests.yml b/.github/workflows/build-and-run-tests.yml index 30af5f45ad..086842b618 100644 --- a/.github/workflows/build-and-run-tests.yml +++ b/.github/workflows/build-and-run-tests.yml @@ -5,6 +5,11 @@ on: branches: [main] pull_request: branches: [main] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: utbot_java_cli + DOCKERFILE_PATH: docker/Dockerfile_java_cli jobs: build_and_run_tests: @@ -16,14 +21,30 @@ jobs: java-version: '8' distribution: 'zulu' java-package: jdk+fx + - uses: gradle/gradle-build-action@v2 with: gradle-version: 6.8 + + - name: Set project version + run: echo "VERSION="$(date +%Y).$(date +%-m)"" >> $GITHUB_ENV - name: Build and run tests in UTBot Java run: | export KOTLIN_HOME="/usr" - gradle clean build --no-daemon + gradle clean build --no-daemon -PsemVer=${{ env.VERSION }} + + - name: Publish test results + uses: EnricoMi/publish-unit-test-result-action@v1 + if: always() + with: + files: "**/build/test-results/**/*.xml" + + - name: Cache utbot-cli-${{ env.VERSION }}.jar + uses: actions/cache@v3 + with: + path: utbot-cli/build/libs/utbot-cli-${{ env.VERSION }}.jar + key: utbot-cli - name: Upload utbot-framework logs if: ${{ always() }} @@ -39,9 +60,73 @@ jobs: name: utbot_framework_tests_report path: utbot-framework/build/reports/tests/test/* - - name: Upload utbot-intellij tests report artifacts if tests have failed - if: ${{ failure() }} - uses: actions/upload-artifact@v2 + + publish_cli_image: + needs: build_and_run_tests + if: ${{ github.event_name != 'pull_request' }} + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Set timezone + uses: szenius/set-timezone@v1.0 + with: + timezoneLinux: "Europe/Moscow" + + - name: Set environment variables + run: | + echo "COMMIT_SHORT_SHA="$(git rev-parse --short HEAD)"" >> $GITHUB_ENV + echo "VERSION="$(date +%Y).$(date +%-m)"" >> $GITHUB_ENV + + - uses: actions/cache@v3 with: - name: utbot_intellij_tests_report - path: utbot-intellij/build/reports/tests/test/* + path: utbot-cli/build/libs/utbot-cli-${{ env.VERSION }}.jar + key: utbot-cli + + - name: Set docker tag + run: + echo "DOCKER_TAG="$(date +%Y).$(date +%-m).$(date +%-d)-${{ env.COMMIT_SHORT_SHA }}"" >> $GITHUB_ENV + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ env.DOCKER_TAG }} + + - name: Docker Buildx (build and push) + run: | + docker buildx build \ + -f ${{ env.DOCKERFILE_PATH }} \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache-new" \ + --tag ${{ steps.meta.outputs.tags }} \ + --build-arg UTBOT_JAVA_CLI=utbot-cli/build/libs/utbot-cli-${{ env.VERSION }}.jar \ + --push . + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.github/workflows/publish-cli-image.yml b/.github/workflows/publish-cli-image.yml deleted file mode 100644 index fbc98c35a9..0000000000 --- a/.github/workflows/publish-cli-image.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: "CLI: publish image" -on: - push: - branches: [main] - -env: - REGISTRY: ghcr.io - IMAGE_NAME: utbot_java_cli - DOCKERFILE_PATH: docker/Dockerfile_java_cli - -jobs: - build-and-publish-docker: - runs-on: ubuntu-20.04 - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set timezone - uses: szenius/set-timezone@v1.0 - with: - timezoneLinux: "Europe/Moscow" - - - name: Set environment variables - run: - echo "COMMIT_SHORT_SHA="$(git rev-parse --short HEAD)"" >> $GITHUB_ENV - - - name: Set docker tag - run: - echo "DOCKER_TAG="$(date +%Y).$(date +%-m).$(date +%-d)-${{ env.COMMIT_SHORT_SHA }}"" >> $GITHUB_ENV - - - name: Log in to the Container registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }} - tags: | - type=raw,value=${{ env.DOCKER_TAG }} - - - name: Docker Buildx (build and push) - run: | - docker buildx build \ - -f ${{ env.DOCKERFILE_PATH }} \ - --cache-from "type=local,src=/tmp/.buildx-cache" \ - --cache-to "type=local,dest=/tmp/.buildx-cache-new" \ - --tag ${{ steps.meta.outputs.tags }} \ - --build-arg ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }} \ - --push . - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/docker/Dockerfile_java_cli b/docker/Dockerfile_java_cli index a084fcf0f9..41ddf8d3d0 100644 --- a/docker/Dockerfile_java_cli +++ b/docker/Dockerfile_java_cli @@ -1,25 +1,12 @@ FROM openjdk:8 -ARG ACCESS_TOKEN +ARG UTBOT_JAVA_CLI WORKDIR /usr/src/ -RUN apt-get update \ - && apt-get install -y curl \ - unzip \ - python3 \ - python3-requests \ - && apt-get clean - # Install UTBot Java CLI -COPY docker/get_java_cli_download_url.py . -ENV JAVA_CLI_ZIP_NAME "utbot_java_cli.zip" +COPY ${UTBOT_JAVA_CLI} . -RUN curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \ - -L "$(python3 get_java_cli_download_url.py)" \ - -o "${JAVA_CLI_ZIP_NAME}" \ - && unzip "${JAVA_CLI_ZIP_NAME}" \ - && rm "${JAVA_CLI_ZIP_NAME}" \ - && JAVA_CLI_PATH="$(find /usr/src -type f -name 'utbot-cli*')" \ - && ln -s "${JAVA_CLI_PATH}" /usr/src/utbot-cli.jar +RUN UTBOT_JAVA_CLI_PATH="$(find /usr/src -type f -name 'utbot-cli*')" \ + && ln -s "${UTBOT_JAVA_CLI_PATH}" /usr/src/utbot-cli.jar diff --git a/docker/get_java_cli_download_url.py b/docker/get_java_cli_download_url.py deleted file mode 100644 index ad2f6b03a5..0000000000 --- a/docker/get_java_cli_download_url.py +++ /dev/null @@ -1,14 +0,0 @@ -import json -import requests - -JAVA_ARTIFACTS_URL="https://api.github.com/repos/UnitTestBot/UTBotJava/actions/artifacts" - -request = requests.get(url = JAVA_ARTIFACTS_URL) -data = request.json() -artifacts = data['artifacts'] - -for artifact in artifacts: - if "utbot-cli" in artifact['name']: - print(artifact['archive_download_url']) - break -