---

name: Build Images Cron

# Rebuild images from master branch every Sunday

on:
  schedule:
    - cron: "0 0 * * 0"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: master

      - name: Get build tag
        id: get_build_tag
        # You must push tags first before pushing refs, otherwise you'll never build an image
        # tagged with a git tag.
        run: |
          if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
            TAG="$(echo ${GITHUB_REF#refs/tags/} | sed 's/^v//g')"
          else
            TAG="$(echo ${GITHUB_REF#refs/heads/} | tr '/-' '_')-${GITHUB_SHA:0:7}-$(date -u +'%Y%m%d%H%M')"
          fi
          echo "TAG: ${TAG}"
          echo "::set-output name=tag::${TAG}"

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-

      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.PANUBUILD_DOCKERHUB_USERNAME }}
          password: ${{ secrets.PANUBUILD_DOCKERHUB_TOKEN }}

      - name: Build and Push
        uses: docker/build-push-action@v2
        with:
          builder: ${{ steps.buildx.outputs.name }}
          context: .
          file: Dockerfile
          push: true
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
          tags: |
            panubo/sshd:latest
            panubo/sshd:${{ steps.get_build_tag.outputs.tag }}

Add workflow to rebuild master on cron
Add workflow to rebuild master on cron
