cuelang.org/go@v0.13.0/.github/workflows/evict_caches.yaml (about)

     1  # Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
     2  
     3  name: Evict caches
     4  "on":
     5    schedule:
     6      - cron: 0 2 * * *
     7  jobs:
     8    test:
     9      defaults:
    10        run:
    11          shell: bash --noprofile --norc -euo pipefail {0}
    12      if: ${{github.repository == 'cue-lang/cue'}}
    13      runs-on: ubuntu-24.04
    14      steps:
    15        - name: Checkout code
    16          uses: actions/checkout@v4
    17          with:
    18            ref: ${{ github.event.pull_request.head.sha }}
    19            fetch-depth: 0
    20        - name: Reset git directory modification times
    21          run: touch -t 202211302355 $(find * -type d)
    22        - name: Restore git file modification times
    23          uses: chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe
    24        - id: DispatchTrailer
    25          name: Try to extract Dispatch-Trailer
    26          run: |-
    27            x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')"
    28            if [[ "$x" == "" ]]
    29            then
    30               # Some steps rely on the presence or otherwise of the Dispatch-Trailer.
    31               # We know that we don't have a Dispatch-Trailer in this situation,
    32               # hence we use the JSON value null in order to represent that state.
    33               # This means that GitHub expressions can determine whether a Dispatch-Trailer
    34               # is present or not by checking whether the fromJSON() result of the
    35               # output from this step is the JSON value null or not.
    36               x=null
    37            fi
    38            echo "value<<EOD" >> $GITHUB_OUTPUT
    39            echo "$x" >> $GITHUB_OUTPUT
    40            echo "EOD" >> $GITHUB_OUTPUT
    41        - if: |-
    42            ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
    43            Dispatch-Trailer: {"type":"')))) && (contains(github.event.head_commit.message, '
    44            Dispatch-Trailer: {"type":"'))
    45          name: Check we don't have Dispatch-Trailer on a protected branch
    46          run: |-
    47            echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch"
    48            false
    49        - name: Delete caches
    50          run: |-
    51            echo ${{ secrets.CUECKOO_GITHUB_PAT }} | gh auth login --with-token
    52            for i in https://github.com/cue-lang/cue https://github.com/cue-lang/cue-trybot
    53            do
    54            	echo "Evicting caches for $i"
    55            	gh cache delete --repo $i --all --succeed-on-no-caches
    56            done
    57        - name: Trigger workflow runs to repopulate caches
    58          run: |-
    59            # Prepare git for pushes to trybot repo. Note
    60            # because we have already checked out code we don't
    61            # need origin. Fetch origin default branch for later use
    62            git config user.name cueckoo
    63            git config user.email cueckoo@gmail.com
    64            git config http.https://github.com/.extraheader "AUTHORIZATION: basic $(echo -n cueckoo:${{ secrets.CUECKOO_GITHUB_PAT }} | base64)"
    65            git remote add trybot https://github.com/cue-lang/cue-trybot
    66  
    67            # Now trigger the most recent workflow run on each of the default branches.
    68            # We do this by listing all the branches on the main repo and finding those
    69            # which match the protected branch patterns (globs).
    70            for j in $(curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" -f https://api.github.com/repos/cue-lang/cue/branches | jq -r '.[] | .name')
    71            do
    72            	for i in master release-branch.*
    73            	do
    74            		if [[ "$j" != $i ]]; then
    75            			continue
    76            		fi
    77  
    78            		echo Branch: $j
    79            		sha=$(curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/cue-lang/cue/commits/$j" | jq -r '.sha')
    80            		echo Latest commit: $sha
    81  
    82            		echo "Trigger workflow on cue-lang/cue"
    83            		curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue/actions/workflows/trybot.yaml/dispatches -d "{\"ref\":\"$j\"}"
    84  
    85            		# Ensure that the trybot repo has the latest commit for
    86            		# this branch.  If the force-push results in a commit
    87            		# being pushed, that will trigger the trybot workflows
    88            		# so we don't need to do anything, otherwise we need to
    89            		# trigger the most recent commit on that branch
    90            		git remote -v
    91            		git fetch origin refs/heads/$j
    92            		git log -1 FETCH_HEAD
    93  
    94            		success=false
    95            		for try in {1..20}; do
    96            			echo "Push to trybot try $try"
    97            			exitCode=0; push="$(git push -f trybot FETCH_HEAD:$j 2>&1)" || exitCode=$?
    98            			echo "$push"
    99            			if [[ $exitCode -eq 0 ]]; then
   100            				success=true
   101            				break
   102            			fi
   103            			sleep 1
   104            		done
   105            		if ! $success; then
   106            			echo "Giving up"
   107            			exit 1
   108            		fi
   109  
   110            		if echo "$push" | grep up-to-date
   111            		then
   112            			# We are up-to-date, i.e. the push did nothing, hence we need to trigger a workflow_dispatch
   113            			# in the trybot repo.
   114            			echo "Trigger workflow on cue-lang/cue-trybot"
   115            			curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue-trybot/actions/workflows/trybot.yaml/dispatches -d "{\"ref\":\"$j\"}"
   116            		else
   117            			echo "Force-push to cue-lang/cue-trybot did work; nothing to do"
   118            		fi
   119            	done
   120            done