name: Reusable workflow. Using to build, test and push single module API on: workflow_call: inputs: ECR_REPOSITORY: description: "Using for deploy docker image to ECR" required: true type: string BOOT_JAR_NAME: description: "Using for start docker container." required: true type: string IS_TEST_ENABLED: description: "Using for start test before pushing to ECR if value is true." required: true type: boolean IS_ECR_PUSH_ENABLED: description: "Using for disable pushing to ECR if value is true." required: true type: boolean IS_COPY_DOCKERFILE: description: "Using for copy default dockerfile from https://github.com/ArbinaHQ/arbina-github-runner/tree/master/docker/api." required: true type: boolean IS_COPY_DOCKER_DIRECTORY: description: "Using for copy default docker directory (entrypoint, cron, healthcheck) from https://github.com/ArbinaHQ/arbina-github-runner/tree/master/docker/api." required: true type: boolean jobs: api-single-module-workflow: runs-on: custom steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v1 with: java-version: 17 - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build and analyze (exclude test) if: ${{ !inputs.IS_TEST_ENABLED }} env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN_CAN_READ_PACKAGES || secrets.GH_DEPBOT_TOKEN_CAN_READ_PACKAGES }} GITHUB_USERNAME: ${{ secrets.GH_USER_CAN_READ_PACKAGES || secrets.GH_DEPBOT_USER_CAN_READ_PACKAGES }} SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST_URL }} run: ./gradlew build bootJar sonar --info -x test - name: Build and analyze (include test) if: ${{ inputs.IS_TEST_ENABLED }} env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN_CAN_READ_PACKAGES || secrets.GH_DEPBOT_TOKEN_CAN_READ_PACKAGES }} GITHUB_USERNAME: ${{ secrets.GH_USER_CAN_READ_PACKAGES || secrets.GH_DEPBOT_USER_CAN_READ_PACKAGES }} SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST_URL }} run: ./gradlew build bootJar test sonar --info - name: Copy docker directory if: ${{ inputs.IS_COPY_DOCKER_DIRECTORY }} run: cp -r /docker/api/docker ./ - name: Copy dockerfile if: ${{ inputs.IS_COPY_DOCKERFILE }} run: cp /docker/api/Dockerfile ./ - name: Login to ECR if: ${{ inputs.IS_ECR_PUSH_ENABLED }} id: login-ecr uses: docker/login-action@v2 with: registry: ${{ secrets.ARBINA_ECR_REGISTRY }} username: ${{ secrets.ARBINA_ECR_USERNAME }} password: ${{ secrets.ARBINA_ECR_PASSWORD }} - name: Build, tag, and push image to ECR if: ${{ inputs.IS_ECR_PUSH_ENABLED }} env: ECR_REGISTRY: ${{ secrets.ARBINA_ECR_REGISTRY }} ECR_REPOSITORY: ${{ inputs.ECR_REPOSITORY }} IMAGE_TAG: ${{ github.sha }} BOOT_JAR_NAME: ${{ inputs.BOOT_JAR_NAME }} run: | docker build --build-arg=IMAGE_TAG=$IMAGE_TAG --build-arg=BOOT_JAR_NAME=$BOOT_JAR_NAME -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker build --build-arg=IMAGE_TAG=$IMAGE_TAG --build-arg=BOOT_JAR_NAME=$BOOT_JAR_NAME -t $ECR_REGISTRY/$ECR_REPOSITORY:latest . docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest