name: 构建lite镜像
on:
  push:
    tags:
      - v*.*.*
      - v*.*-Beta*
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    if: "!contains(github.ref, 'ExeBeta')"
    name: 构建lite镜像
    steps:
      - name: Checkout
        uses: actions/checkout@master

      - name: Prepare
        id: prepare
        run: |
          echo "::set-output name=version::${GITHUB_REF:10}"
          echo "version=${GITHUB_REF:10}"

      - name: Set Up QEMU
        uses: docker/setup-qemu-action@v2

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

      - name: Login DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Go Cross Build
        working-directory: docker
        run: |
          docker run --rm \
            -e VERSION=${{ steps.prepare.outputs.version }} \
            -e BASEKEY=${{ secrets.BASEKEY }} \
            -e AESKEY16=${{ secrets.AESKEY16 }} \
            -e AESIV16=${{ secrets.AESIV16 }} \
            -v $(pwd)/go:/root/go \
            -v $(pwd)/lite-make.sh:/init.sh \
            --entrypoint "/init.sh" \
            nevinee/csf-cross-builder

      - name: Docker Buildx Latest Image
        if: "!contains(steps.prepare.outputs.version, 'Beta')"
        uses: docker/build-push-action@v3
        with:
          context: docker
          file: docker/lite-release.Dockerfile
          platforms: |
            linux/386
            linux/amd64
            linux/arm64
            linux/arm/v7
          push: true
          build-args: |
            VERSION=${{ steps.prepare.outputs.version }}
          tags: |
            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:${{ steps.prepare.outputs.version }}-lite
            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:${{ steps.prepare.outputs.version }}
            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:latest-lite
            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:latest

      - name: Docker Buildx Beta Image
        if: contains(steps.prepare.outputs.version, 'Beta')
        uses: docker/build-push-action@v3
        with:
          context: docker
          file: docker/lite-release.Dockerfile
          platforms: |
            linux/386
            linux/amd64
            linux/arm64
            linux/arm/v7
          push: true
          build-args: |
            VERSION=${{ steps.prepare.outputs.version }}
          tags: |
            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:${{ steps.prepare.outputs.version }}-lite
            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:${{ steps.prepare.outputs.version }}
