name: update-bot on: push: branches: - master schedule: - cron: '30 23 * * *' jobs: check: runs-on: ubuntu-latest outputs: img_ver: ${{ steps.check_ver.outputs.img_ver }} qbt_ver: ${{ steps.check_ver.outputs.qbt_ver }} lib_ver: ${{ steps.check_ver.outputs.lib_ver }} is_new: ${{ steps.check_ver.outputs.is_new }} latest: ${{ steps.check_ver.outputs.latest }} steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Check version id: check_ver run: | OLD_VER=$(curl -s "${GHCR_URL}" | grep -Po "(\d+\.)+\d+(|beta\d+|rc\d+)-r\d+" | head -1) NEW_TAG=$(curl -s "${REPO_TAGS}" | grep -Po "(\d+\.)+\d+(|beta\d+|rc\d+)\.zip" | head -1) LIB_VER=$(jq -r '.libtorrent' ./latest.json) QBT_VER=$(jq -r '.qbittorrent' ./latest.json) PKG_REL=$(jq -r '.pkgrel' ./latest.json) if echo "${NEW_TAG%.zip}" | grep -Pq "^(\d+\.){2}\d+$"; then echo "::set-output name=latest::type=raw,latest" elif [ ${{ github.event_name }} == 'push' ]; then IMG_VER="${QBT_VER}-r${PKG_REL}" else QBT_VER="${NEW_TAG%.zip}" IMG_VER="${QBT_VER}-r0" fi IS_NEW=$([[ "${IMG_VER}" != "${OLD_VER}" ]] && echo "yes" || echo "no") echo "::set-output name=img_ver::${IMG_VER}" echo "::set-output name=qbt_ver::${QBT_VER}" echo "::set-output name=lib_ver::${LIB_VER}" echo "::set-output name=is_new::${IS_NEW}" env: GHCR_URL: https://github.com/mogeko/docker-qbittorrent/pkgs/container/qbittorrent REPO_TAGS: https://github.com/qbittorrent/qBittorrent/tags build: runs-on: ubuntu-latest needs: check if: ${{ needs.check.outputs.is_new == 'yes' }} steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Log in to Docker Hub uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to the Container registry uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@e5622373a38e60fb6d795a4421e56882f2d7a681 with: images: | ${{ github.repository_owner }}/qbittorrent ghcr.io/${{ github.repository_owner }}/qbittorrent tags: | type=edge type=schedule,pattern={{date 'YYYYMMDD'}} type=raw,${{ needs.check.outputs.img_ver }} ${{ needs.check.outputs.latest }} - name: Build and push Docker image id: build uses: docker/build-push-action@a66e35b9cbcf4ad0ea91ffcaf7bbad63ad9e0229 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | QBITTORRENT_VERSION=${{ needs.check.outputs.qbt_ver }} LIBTORRENT_VERSION=${{ needs.check.outputs.lib_ver }} - name: Save metadata run: echo ${{ toJSON(steps.build.outputs.metadata) }} > ${{ github.workspace }}/meta.json - name: Update metadata uses: actions/upload-artifact@v2 with: name: metadata path: ${{ github.workspace }}/meta.json