diff --git a/.github/actions/replace-text/action.yml b/.github/actions/replace-text/action.yml new file mode 100644 index 0000000..72f41da --- /dev/null +++ b/.github/actions/replace-text/action.yml @@ -0,0 +1,22 @@ +name: Replace text in file + +inputs: + old-string: + description: String to replace + required: true + type: string + new-string: + description: String to replace with + required: true + type: string + file: + description: Path to file + required: true + type: string + +runs: + using: composite + steps: + - name: Replace substring + shell: bash + run: sed -i 's/${{ inputs.old-string }}/${{ inputs.new-string }}/g' ${{ inputs.file }} diff --git a/.github/actions/replace-version/action.yml b/.github/actions/replace-version/action.yml new file mode 100644 index 0000000..a54631e --- /dev/null +++ b/.github/actions/replace-version/action.yml @@ -0,0 +1,24 @@ +name: Replace version + +inputs: + version: + description: Version to replace with + required: true + type: string + +runs: + using: composite + steps: + - name: Replace string in src/main.cpp + uses: ./.github/actions/replace-text + with: + file: src/main.cpp + old-string: + new-string: ${{ inputs.version }} + + - name: Replace string in bin/lottie_common.sh + uses: ./.github/actions/replace-text + with: + file: bin/lottie_common.sh + old-string: + new-string: ${{ inputs.version }} diff --git a/.github/workflows/build-darwin.yml b/.github/workflows/build-darwin.yml index b352958..9191a7d 100644 --- a/.github/workflows/build-darwin.yml +++ b/.github/workflows/build-darwin.yml @@ -7,6 +7,10 @@ on: description: Name of artifact as which Darwin executable to be uploaded required: true type: string + version: + description: Version to replace with + required: false + type: string jobs: build-darwin: @@ -18,6 +22,12 @@ jobs: - uses: actions/checkout@v3 + - name: Replace version + if: ${{ inputs.version != '' }} + uses: ./.github/actions/replace-version + with: + version: ${{ inputs.version }} + - name: Detect conan profile run: conan profile detect diff --git a/.github/workflows/build-linux-and-docker.yml b/.github/workflows/build-linux-and-docker.yml index 64633f7..c8afd3f 100644 --- a/.github/workflows/build-linux-and-docker.yml +++ b/.github/workflows/build-linux-and-docker.yml @@ -11,6 +11,10 @@ on: description: "amd64 or arm64" required: true type: string + version: + description: Version to replace with + required: false + type: string jobs: build-docker: @@ -27,6 +31,12 @@ jobs: - name: Setup Docker buildx uses: docker/setup-buildx-action@v2 + - name: Replace version + if: ${{ inputs.version != '' }} + uses: ./.github/actions/replace-version + with: + version: ${{ inputs.version }} + - name: Build lottie-to-apng uses: docker/build-push-action@v4 with: @@ -37,7 +47,7 @@ jobs: load: true cache-from: type=gha cache-to: type=gha,mode=max - + - name: Upload lottie-to-apng as artifact uses: ishworkh/container-image-artifact-upload@v1.0.0 with: diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 7eb1409..2d2b586 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -7,7 +7,10 @@ on: description: Name of artifact as which Windows executable to be uploaded required: true type: string - + version: + description: Version to replace with + required: false + type: string jobs: build-windows: name: Build Windows executable @@ -18,6 +21,12 @@ jobs: - uses: actions/checkout@v3 + - name: Replace version + if: ${{ inputs.version != '' }} + uses: ./.github/actions/replace-version + with: + version: ${{ inputs.version }} + - name: Detect conan profile run: conan profile detect diff --git a/.github/workflows/cd-release.yml b/.github/workflows/cd-release.yml index 2c216f7..0464475 100644 --- a/.github/workflows/cd-release.yml +++ b/.github/workflows/cd-release.yml @@ -17,18 +17,21 @@ jobs: with: output-artifact-name: lottie-to-png.linux.${{ matrix.arch }} arch: ${{ matrix.arch }} + version: ${{ github.ref_name }} build-darwin: name: Build Darwin executable uses: ./.github/workflows/build-darwin.yml with: output-artifact-name: lottie-to-png.darwin.amd64 + version: ${{ github.ref_name }} build-windows: name: Build Windows executable uses: ./.github/workflows/build-windows.yml with: output-artifact-name: lottie-to-png.windows.amd64.exe + version: ${{ github.ref_name }} push-docker-image: name: Push images to DockerHub @@ -80,12 +83,18 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Create manifest + - name: Create manifest of latest tag run: docker manifest create ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:latest --amend ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:amd64 --amend ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:arm64 - - name: Push manifest + - name: Push manifest of latest tag run: docker manifest push ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:latest + - name: Create manifest of version tag + run: docker manifest create ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:${{ github.ref_name }} --amend ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:amd64 --amend ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:arm64 + + - name: Push manifest of version tag + run: docker manifest push ${{ secrets.DOCKERHUB_USERNAME }}/lottie-to-${{ matrix.format }}:${{ github.ref_name }} + - name: Make format uppercase id: format uses: ASzc/change-string-case-action@v5 @@ -93,20 +102,20 @@ jobs: string: ${{ matrix.format }} - uses: actions/checkout@v4 - - - name: Find and replace FORMAT - uses: jacobtomlinson/gha-find-replace@v3 + + - name: Find and replace FORMAT in readme for DockerHub + uses: ./.github/actions/replace-text with: - find: FORMAT - replace: ${{ steps.format.outputs.uppercase }} - regex: false + file: README.dockerhub.md + old-string: FORMAT + new-string: ${{ steps.format.outputs.uppercase }} - - name: Find and replace format - uses: jacobtomlinson/gha-find-replace@v3 + - name: Find and replace format in readme for DockerHub + uses: ./.github/actions/replace-text with: - find: format - replace: ${{ matrix.format }} - regex: false + file: README.dockerhub.md + old-string: format + new-string: ${{ matrix.format }} - name: Update description at DockerHub uses: peter-evans/dockerhub-description@v3 @@ -136,6 +145,11 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Replace version + uses: ./.github/actions/replace-version + with: + version: ${{ github.ref_name }} + - name: Download artifact uses: actions/download-artifact@v3 with: diff --git a/bin/lottie_common.sh b/bin/lottie_common.sh index 5e1141a..0137c37 100644 --- a/bin/lottie_common.sh +++ b/bin/lottie_common.sh @@ -19,13 +19,21 @@ function print_help() { echo " path Path to .json or .tgs file to convert" echo echo "Optional arguments:" - echo " -h, --help show this help message and exit" + echo " -h, --help shows this help message and exits" + echo " -v, --version prints version information and exits" echo " --output OUTPUT Output file path" echo " --height HEIGHT Output image height. Default: $HEIGHT" echo " --width WIDTH Output image width. Default: $WIDTH" echo " --fps FPS Output frame rate. Default: $FPS" echo " --threads THREADS Number of threads to use. Default: number of CPUs" echo " --quality QUALITY Output quality. Default: $QUALITY" + echo + echo "It's open-source project: https://github.com/ed-asriyan/lottie-converter" + echo "Author: Ed Asriyan " +} + +function print_version() { + echo "" } while [[ $# -gt 0 ]]; do @@ -60,10 +68,14 @@ while [[ $# -gt 0 ]]; do shift shift ;; - --help) + -h|--help) print_help exit 1 ;; + -v|--version) + print_version + exit 1 + ;; *) POSITIONAL_ARG=$1 shift diff --git a/src/main.cpp b/src/main.cpp index c3cdeab..f64ab19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,17 @@ void convert( } int main(int argc, const char** argv) { - argparse::ArgumentParser program("lottie_to_png"); + argparse::ArgumentParser program("lottie_to_png", ""); + + program.add_description( + "Lottie animations (.json) to frames as .png files converter.\n" + "This executable is one of components of lottie-converter project and isn't supposed to be used directly." + ); + + program.add_epilog( + "It's open-source project: https://github.com/ed-asriyan/lottie-converter\n" + "Author: Ed Asriyan " + ); program.add_argument("path") .required()