From f87cabf6450faba63a94cc0fd7bc57c4ff35d7f2 Mon Sep 17 00:00:00 2001 From: Konstantin Aksenov Date: Thu, 4 Apr 2024 19:51:17 +1000 Subject: [PATCH] fix(core): exit codes in case of connectivity issues --- .github/workflows/deploy.yaml | 79 ++++++++++++++----- Dockerfile | 12 ++- .../vacxe/googleplaycli/PlayStoreCli.kt | 2 +- .../vacxe/googleplaycli/core/BaseCommand.kt | 12 ++- 4 files changed, 76 insertions(+), 29 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 6b855aa..3b5c44e 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,26 +1,65 @@ -name: deploy-sonatype-snapshot +name: Deploy Release on: - push: - branches: - - master + release: + types: [ created ] + jobs: - deploy: + release-tar: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Set up JDK 12 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 with: - java-version: 12 - - name: assembleDist - run: ./gradlew distZip distTar - - name: google-play-cli.tar - uses: actions/upload-artifact@master + distribution: "temurin" + java-version: 11 + - name: Build release tar + run: ./gradlew distTar + - name: Tar Checksum + run: shasum -a 256 build/distributions/google-play-cli.tar + - name: Get release information + id: get_release + uses: bruceadams/get-release@v1.3.2 + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Upload artifacts to release + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ github.token }} with: - name: google-play-cli.tar - path: build/distributions/google-play-cli.tar - - name: google-play-cli.zip - uses: actions/upload-artifact@master - with: - name: google-play-cli.zip - path: build/distributions/google-play-cli.zip + upload_url: ${{ steps.get_release.outputs.upload_url }} + asset_path: ./build/distributions/google-play-cli.tar + asset_name: google-play-cli.tar + asset_content_type: application/x-tar + + docker-build-push: + name: Build and Push Docker image + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + needs: [ release-tar ] + steps: + - uses: actions/checkout@v4 + + - name: Get release information + id: get_release + uses: bruceadams/get-release@v1.3.2 + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Docker Login + run: echo $PACKAGES_WRITE_TOKEN | docker login ghcr.io -u $USERNAME --password-stdin + env: + PACKAGES_WRITE_TOKEN: ${{ secrets.GITHUB_TOKEN }} + USERNAME: ${{ github.actor }} + + - name: Docker Build + run: docker build -t ghcr.io/vacxe/google-play-cli:$VERSION --build-arg="PLAY_CLI_VERSION=$VERSION" . + env: + VERSION: ${{ steps.get_release.outputs.tag_name }} + + - name: Deploy + run: docker push ghcr.io/vacxe/google-play-cli:$VERSION + env: + VERSION: ${{ steps.get_release.outputs.tag_name }} diff --git a/Dockerfile b/Dockerfile index 2709c78..25f8c1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,14 @@ FROM adoptopenjdk/openjdk11:jdk-11.0.11_9-alpine-slim -ARG VERSION +ARG PLAY_CLI_VERSION RUN apk update && \ apk add --no-cache jq wget unzip -RUN wget -q "https://github.com/Vacxe/google-play-cli-kt/releases/download/$VERSION/google-play-cli-$VERSION.zip" -O "google-play-cli.zip" && \ - unzip "google-play-cli.zip" && \ - rm "google-play-cli.zip" && \ - mv google-play-cli /usr/local/ - -RUN chmod +x /usr/local/google-play-cli +# Install released Version from artefacts +RUN wget -q "https://github.com/Vacxe/google-play-cli-kt/releases/download/$PLAY_CLI_VERSION/google-play-cli.tar" && \ + tar -xvf "google-play-cli.tar" -C /usr/local && \ + rm "google-play-cli.tar" ENV PATH="${PATH}:/usr/local/google-play-cli/bin/" diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt index 9a0b293..2c7bf61 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreCli.kt @@ -82,7 +82,7 @@ fun main(args: Array) { addCmd { object : CliktCommand(name = "version", help = "Library version code") { override fun run() { - println("0.3.8") + println("0.3.9") } } } diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt index 97ff71f..56230e0 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt @@ -81,9 +81,19 @@ abstract class BaseCommand(name: String, actionDescription: String = "") : } else { println(e.content) } - exitProcess(1) + exitProcess(ExitCode.PLAY_CONSOLE_ERROR) + } catch (e: Exception) { + println(e) + exitProcess(ExitCode.DEFAULT) } } abstract fun run(api: PlayStoreApi): Any? + + private companion object { + object ExitCode { + const val DEFAULT = 1 + const val PLAY_CONSOLE_ERROR = 2 + } + } } \ No newline at end of file