From d9a1ebb8412f8abb434dbb3fefcfde8912ab8912 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 20 Feb 2023 15:06:24 -0500 Subject: [PATCH] docker: add no-cache-filters --- .github/workflows/ci-docker.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 3858ae10..1082c941 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -205,9 +205,20 @@ jobs: # get branch name BRANCH=${GITHUB_HEAD_REF} + RELEASE=false + if [ -z "$BRANCH" ]; then echo "This is a PUSH event" BRANCH=${{ github.ref_name }} + COMMIT=${{ github.sha }} + CLONE_URL=${{ github.event.repository.clone_url }} + if [[ $BRANCH == "master" ]]; then + RELEASE=true + fi + else + echo "This is a PULL REQUEST event" + COMMIT=${{ github.event.pull_request.head.sha }} + CLONE_URL=${{ github.event.pull_request.head.repo.clone_url }} fi # determine to push image to dockerhub and ghcr or not @@ -220,7 +231,6 @@ jobs: # setup the tags REPOSITORY=${{ github.repository }} BASE_TAG=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]') - COMMIT=${{ github.sha }} TAGS="${BASE_TAG}:${COMMIT:0:7}${{ matrix.tag }},ghcr.io/${BASE_TAG}:${COMMIT:0:7}${{ matrix.tag }}" @@ -259,7 +269,10 @@ jobs: elif [[ $line == "# artifacts: "* && $ARTIFACTS == "" ]]; then # echo the line and use `sed` to remove the custom directive ARTIFACTS=$(echo -e "$line" | sed 's/# artifacts: //') - elif [[ $PLATFORMS != "" && $ARTIFACTS != "" ]]; then + elif [[ $line == "# no-cache-filters: "* && $NO_CACHE_FILTERS == "" ]]; then + # echo the line and use `sed` to remove the custom directive + NO_CACHE_FILTERS=$(echo -e "$line" | sed 's/# no-cache-filters: //') + elif [[ $PLATFORMS != "" && $ARTIFACTS != "" && $NO_CACHE_FILTERS != "" ]]; then # break while loop once all custom directives are found break fi @@ -277,7 +290,10 @@ jobs: echo "branch=${BRANCH}" >> $GITHUB_OUTPUT echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT echo "commit=${COMMIT}" >> $GITHUB_OUTPUT + echo "clone_url=${CLONE_URL}" >> $GITHUB_OUTPUT + echo "release=${RELEASE}" >> $GITHUB_OUTPUT echo "artifacts=${ARTIFACTS}" >> $GITHUB_OUTPUT + echo "no_cache_filters=${NO_CACHE_FILTERS}" >> $GITHUB_OUTPUT echo "platforms=${PLATFORMS}" >> $GITHUB_OUTPUT echo "push=${PUSH}" >> $GITHUB_OUTPUT echo "tags=${TAGS}" >> $GITHUB_OUTPUT @@ -328,9 +344,12 @@ jobs: BUILD_DATE=${{ steps.prepare.outputs.build_date }} BUILD_VERSION=${{ needs.check_changelog.outputs.next_version }} COMMIT=${{ steps.prepare.outputs.commit }} + CLONE_URL=${{ steps.prepare.outputs.clone_url }} + RELEASE=${{ steps.prepare.outputs.release }} tags: ${{ steps.prepare.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache + no-cache-filters: ${{ steps.prepare.outputs.no_cache_filters }} - name: Build and push id: build @@ -345,9 +364,12 @@ jobs: BUILD_DATE=${{ steps.prepare.outputs.build_date }} BUILD_VERSION=${{ needs.check_changelog.outputs.next_version }} COMMIT=${{ steps.prepare.outputs.commit }} + CLONE_URL=${{ steps.prepare.outputs.clone_url }} + RELEASE=${{ steps.prepare.outputs.release }} tags: ${{ steps.prepare.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache + no-cache-filters: ${{ steps.prepare.outputs.no_cache_filters }} - name: Arrange Artifacts if: ${{ steps.prepare.outputs.artifacts == 'true' }} @@ -358,6 +380,9 @@ jobs: # https://unix.stackexchange.com/a/52816 find ./ -type f -exec mv -t ./ -n '{}' + + # remove provenance file + rm -f ./provenance.json + - name: Upload Artifacts if: ${{ steps.prepare.outputs.artifacts == 'true' }} uses: actions/upload-artifact@v3