name: Build Docker Image for Actions on: [push] if: github.ref == 'refs/heads/main' jobs: Check-If-Rebuild: runs-on: ubuntu-22.04 env: DEBIAN_FRONTEND: noninteractive outputs: last-time: ${{ steps.last-time.outputs.last-time }} dockerfile-changed: ${{ steps.dockerfile-changed.outputs.dockerfile-changed }} steps: - name: Install jq run: | apt-get update -y apt-get install -y jq - name: Check last repository build time id: last-time run: curl -s https://hub.docker.com/v2/repositories/drunkendog/standard-build-actions/tags/latest | jq '.last_updated' | xargs -i date --date {} +%s | xargs -i expr $(date +%s) - {} | xargs -i echo last-time={} >> $GITHUB_OUTPUT - name: Check if Dockerfile changed id: dockerfile-changed run: | if ${{ github.event_name == 'pull_request' }}; then echo dockerfile-changed=$(git diff --name-only -r HEAD^1 HEAD | grep -x actions/Dockerfile | wc -l) >> $GITHUB_OUTPUT else echo dockerfile-changed=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -x actions/Dockerfile | wc -l) >> $GITHUB_OUTPUT fi Build-Image: needs: [Check-If-Rebuild] if: needs.Check-If-Rebuild.outputs.last-time > 86400 || needs.Check-If-Rebuild.outputs.dockerfile-changed == 1 runs-on: ubuntu-22.04 steps: - name: Check out repository code uses: actions/checkout@v3 - name: Get Docker run: curl -sL get.docker.io | bash - name: Build and upload image run: sh actions/build-docker-image.sh ${{ secrets.DOCKER_USERNAME }} ${{ secrets.DOCKER_TOKEN }}