Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-20 08:43:05

0001 #!/usr/bin/env bash
0002 # Pin eic-spack.sh to the head of the eic-spack develop branch, and keep a
0003 # single pull request (branch ${BRANCH}) up to date with that bump.
0004 #
0005 # Intended to run from .github/workflows/update-eic-spack.yml, with GH_TOKEN
0006 # set and the base branch checked out. Requires: gh, git, jq.
0007 set -euo pipefail
0008 
0009 BASE_BRANCH="${BASE_BRANCH:-master}"
0010 BRANCH="${BRANCH:-automation/update-eic-spack}"
0011 UPSTREAM_BRANCH="${UPSTREAM_BRANCH:-develop}"
0012 PIN_FILE="eic-spack.sh"
0013 MAX_LISTED=100
0014 
0015 # shellcheck source=/dev/null
0016 source "${PIN_FILE}"
0017 OLD="${EICSPACK_VERSION}"
0018 REPO="${EICSPACK_ORGREPO}"
0019 NEW=$(gh api "repos/${REPO}/commits/${UPSTREAM_BRANCH}" --jq .sha)
0020 echo "eic-spack pin: ${OLD} -> ${NEW}"
0021 
0022 existing_pr() {
0023   gh pr list --head "${BRANCH}" --base "${BASE_BRANCH}" --state open \
0024     --json number --jq '.[0].number // empty'
0025 }
0026 
0027 if [ "${OLD}" = "${NEW}" ]; then
0028   echo "Already up to date."
0029   pr=$(existing_pr)
0030   if [ -n "${pr}" ]; then
0031     gh pr close "${pr}" --delete-branch \
0032       --comment "eic-spack pin on \`${BASE_BRANCH}\` is already at the head of \`${UPSTREAM_BRANCH}\`; closing."
0033   fi
0034   exit 0
0035 fi
0036 
0037 # Changelog -----------------------------------------------------------------
0038 compare=$(gh api "repos/${REPO}/compare/${OLD}...${NEW}")
0039 total=$(jq .total_commits <<<"${compare}")
0040 # Link PR/issue references to the upstream repository, not to this one.
0041 changelog=$(jq -r --arg repo "${REPO}" --argjson max "${MAX_LISTED}" '
0042   .commits | reverse | .[:$max][] |
0043   "- [`\(.sha[0:7])`](\(.html_url)) " +
0044   ((.commit.message | split("\n")[0]) | gsub("#(?<n>[0-9]+)"; "\($repo)#\(.n)")) +
0045   " (\(.author.login // .commit.author.name))"
0046 ' <<<"${compare}")
0047 if [ "${total}" -gt "${MAX_LISTED}" ]; then
0048   changelog+=$'\n'"- … and $((total - MAX_LISTED)) more, see the full comparison below."
0049 fi
0050 
0051 body=$(cat <<BODY
0052 Bumps [${REPO}](https://github.com/${REPO}) from \`${OLD:0:7}\` to \`${NEW:0:7}\` (head of \`${UPSTREAM_BRANCH}\`).
0053 
0054 <details>
0055 <summary>Commits (${total})</summary>
0056 
0057 ${changelog}
0058 
0059 </details>
0060 
0061 Full comparison: https://github.com/${REPO}/compare/${OLD}...${NEW}
0062 
0063 ---
0064 
0065 This pull request is maintained automatically by \`.github/workflows/update-eic-spack.yml\`.
0066 It is rebuilt from \`${BASE_BRANCH}\` every night, so manual pushes to its branch will be overwritten.
0067 BODY
0068 )
0069 title="build(deps): bump eic-spack to ${NEW:0:7}"
0070 
0071 # Branch --------------------------------------------------------------------
0072 git config user.name "github-actions[bot]"
0073 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
0074 git checkout -B "${BRANCH}"
0075 sed -i "s/^EICSPACK_VERSION=.*/EICSPACK_VERSION=\"${NEW}\"/" "${PIN_FILE}"
0076 git add "${PIN_FILE}"
0077 git commit -m "${title}" -m "Bumps ${REPO} from ${OLD} to ${NEW}."
0078 
0079 # Only push when the branch content actually changes, so that CI is not
0080 # needlessly re-triggered on nights when develop has not moved.
0081 git fetch origin "${BRANCH}" 2>/dev/null || true
0082 if git rev-parse --verify -q "origin/${BRANCH}" >/dev/null \
0083    && git diff --quiet HEAD "origin/${BRANCH}" \
0084    && [ "$(git rev-parse HEAD~)" = "$(git rev-parse "origin/${BRANCH}~")" ]; then
0085   echo "Branch ${BRANCH} already contains this update."
0086 else
0087   git push --force origin "${BRANCH}"
0088 fi
0089 
0090 # Pull request --------------------------------------------------------------
0091 pr=$(existing_pr)
0092 if [ -n "${pr}" ]; then
0093   gh pr edit "${pr}" --title "${title}" --body "${body}"
0094   echo "Updated PR #${pr}"
0095 else
0096   gh pr create --base "${BASE_BRANCH}" --head "${BRANCH}" \
0097     --title "${title}" --body "${body}"
0098 fi