name: Cache on: push: branches: - 'develop' jobs: Caching_CVAT: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Getting SHA with cache from the default branch id: get-sha run: | DEFAULT_BRANCH=$(gh api /repos/$REPO | jq -r '.default_branch') for sha in $(gh api "/repos/$REPO/commits?per_page=100&sha=${DEFAULT_BRANCH}" | jq -r '.[].sha'); do RUN_status=$(gh api /repos/${REPO}/actions/workflows/cache.yml/runs | \ jq -r ".workflow_runs[]? | select((.head_sha == \"${sha}\") and (.conclusion == \"success\")) | .status") if [[ ${RUN_status} == "completed" ]]; then SHA=$sha break fi done echo Default branch is ${DEFAULT_BRANCH} echo Workflow will try to get cache from commit: ${SHA} echo ::set-output name=default_branch::${DEFAULT_BRANCH} echo ::set-output name=sha::${SHA} - uses: actions/cache@v3 id: server-cache-action with: path: /tmp/cvat_cache_server key: ${{ runner.os }}-build-server-${{ github.sha }} restore-keys: | ${{ runner.os }}-build-server-${{ steps.get-sha.outputs.sha }} ${{ runner.os }}-build-server- - uses: actions/cache@v3 id: ui-cache-action with: path: /tmp/cvat_cache_ui key: ${{ runner.os }}-build-ui-${{ github.sha }} restore-keys: | ${{ runner.os }}-build-ui-${{ steps.get-sha.outputs.sha }} ${{ runner.os }}-build-ui- - name: Check cache hit if: steps.server-cache-action.outputs.cache-hit != 'false' || steps.ui-cache-action.outputs.cache-hit != 'false' uses: actions/github-script@v3 with: script: | core.setFailed('Caching failed due to a cache hit occurred') - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Caching CVAT server uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile cache-from: type=local,src=/tmp/cvat_cache_server cache-to: type=local,dest=/tmp/cvat_cache_server-new - name: Caching CVAT UI uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile.ui cache-from: type=local,src=/tmp/cvat_cache_ui cache-to: type=local,dest=/tmp/cvat_cache_ui-new - name: Moving cache run: | rm -rf /tmp/cvat_cache_server mv /tmp/cvat_cache_server-new /tmp/cvat_cache_server rm -rf /tmp/cvat_cache_ui mv /tmp/cvat_cache_ui-new /tmp/cvat_cache_ui