|
| 1 | +name: "Update an shpc registry from a cache" |
| 2 | +description: "Install the container_discovery module for your own usage." |
| 3 | +inputs: |
| 4 | + token: |
| 5 | + description: Token (required if pull_request is true) |
| 6 | + required: true |
| 7 | + namespace: |
| 8 | + description: Add a namespace prefix to containers in listing (if listing defined) |
| 9 | + required: false |
| 10 | + cache: |
| 11 | + description: GitHub repository that has cache to use |
| 12 | + required: true |
| 13 | + registry: |
| 14 | + description: path to root of cloned registry |
| 15 | + required: false |
| 16 | + min-count-inclusion: |
| 17 | + description: Minimum alias count for inclusion |
| 18 | + required: false |
| 19 | + default: 10 |
| 20 | + max-count-inclusion: |
| 21 | + description: Do not include counts over this value |
| 22 | + required: false |
| 23 | + default: 1000 |
| 24 | + additional-count-inclusion: |
| 25 | + description: Additional container binaries to include after initial set derived. |
| 26 | + required: false |
| 27 | + default: 25 |
| 28 | + branch: |
| 29 | + description: Branch to open pull request against (defaults to main) |
| 30 | + required: false |
| 31 | + default: "main" |
| 32 | + pull_request: |
| 33 | + description: Open a pull request with changes |
| 34 | + required: false |
| 35 | + default: true |
| 36 | + maintainer: |
| 37 | + description: GitHub maintainer of recipe |
| 38 | + required: false |
| 39 | + default: "@vsoch" |
| 40 | + url_format_string: |
| 41 | + required: false |
| 42 | + listing: |
| 43 | + description: Containers listing to update from (to supplement cache). |
| 44 | + required: false |
| 45 | + |
| 46 | +runs: |
| 47 | + using: "composite" |
| 48 | + steps: |
| 49 | + # Install container_discovery module |
| 50 | + - name: Install Container Discovery and Dependencies |
| 51 | + uses: singularityhub/container-executable-discovery/install@main |
| 52 | + |
| 53 | + - name: Install Additional Dependencies |
| 54 | + run: pip install git+https://github.com/singularityhub/singularity-hpc@main |
| 55 | + shell: bash |
| 56 | + |
| 57 | + - name: Set root url and namespace |
| 58 | + env: |
| 59 | + namespace: ${{ inputs.namespace }} |
| 60 | + url: ${{ inputs.url_format_string }} |
| 61 | + maintainer: ${{ inputs.maintainer }} |
| 62 | + root: ${{ inputs.registry }} |
| 63 | + run: | |
| 64 | + if [ "${root}" == "" ]; then |
| 65 | + root=$(pwd) |
| 66 | + fi |
| 67 | + if [ "${url}" != "" ]; then |
| 68 | + url="--url ${url}" |
| 69 | + fi |
| 70 | + if [ "${namespace}" != "" ]; then |
| 71 | + namespace="--namespace ${namespace}" |
| 72 | + fi |
| 73 | + echo "registry=${root}" >> $GITHUB_ENV |
| 74 | + echo "url=${url}" >> $GITHUB_ENV |
| 75 | + echo "namespace=${namespace}" >> $GITHUB_ENV |
| 76 | + shell: bash |
| 77 | + |
| 78 | + - name: Clone Cache |
| 79 | + env: |
| 80 | + cache: ${{ inputs.cache }} |
| 81 | + run: git clone ${cache} /tmp/cache |
| 82 | + shell: bash |
| 83 | + |
| 84 | + - name: Update Containers |
| 85 | + env: |
| 86 | + registry: ${{ env.registry }} |
| 87 | + add_count: ${{ inputs.additional-count-inclusion }} |
| 88 | + min_count: ${{ inputs.min-count-inclusion }} |
| 89 | + max_count: ${{ inputs.max-count-inclusion }} |
| 90 | + maintainer: ${{ inputs.maintainer }} |
| 91 | + url: ${{ env.url }} |
| 92 | + run: | |
| 93 | + cmd="python ${{ github.action_path }}/scripts/update-from-cache.py --cache /tmp/cache --registry ${registry} --min-count-inclusion ${min_count} --additional-count-inclusion ${add_count} --max-count-inclusion ${max_count} --maintainer ${maintainer} ${url}" |
| 94 | + echo "${cmd}" |
| 95 | + ${cmd} |
| 96 | + shell: bash |
| 97 | + |
| 98 | + - name: Update from Listing |
| 99 | + if: (inputs.listing != '') |
| 100 | + env: |
| 101 | + listing: ${{ inputs.listing }} |
| 102 | + registry: ${{ env.registry }} |
| 103 | + maintainer: ${{ inputs.maintainer }} |
| 104 | + namespace: ${{ env.namespace }} |
| 105 | + url: ${{ env.url }} |
| 106 | + run: | |
| 107 | + cmd="python ${{ github.action_path }}/scripts/update-from-listing.py --listing ${listing} --registry ${registry} --maintainer ${maintainer} ${url} ${namespace}" |
| 108 | + echo "${cmd}" |
| 109 | + ${cmd} |
| 110 | + shell: bash |
| 111 | + |
| 112 | + - name: Checkout Update branch |
| 113 | + if: (inputs.pull_request == 'true') |
| 114 | + env: |
| 115 | + GITHUB_TOKEN: ${{ inputs.token }} |
| 116 | + BRANCH_AGAINST: ${{ inputs.branch }} |
| 117 | + run: | |
| 118 | + printf "GitHub Actor: ${GITHUB_ACTOR}\n" |
| 119 | + export BRANCH_FROM="update/containers-$(date '+%Y-%m-%d')" |
| 120 | + git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" |
| 121 | + BRANCH_EXISTS=$(git ls-remote --heads origin ${BRANCH_FROM}) |
| 122 | + if [[ -z ${BRANCH_EXISTS} ]]; then |
| 123 | + printf "Branch does not exist in remote.\n" |
| 124 | + else |
| 125 | + printf "Branch already exists in remote.\n" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | + git branch |
| 129 | + git checkout -b "${BRANCH_FROM}" || git checkout "${BRANCH_FROM}" |
| 130 | + git branch |
| 131 | + git config --global user.name "github-actions" |
| 132 | + git config --global user.email "[email protected]" |
| 133 | + git add ./* |
| 134 | + git status |
| 135 | + if git diff-index --quiet HEAD --; then |
| 136 | + export OPEN_PULL_REQUEST=0 |
| 137 | + printf "No changes\n" |
| 138 | + else |
| 139 | + export OPEN_PULL_REQUEST=1 |
| 140 | + printf "Changes\n" |
| 141 | + git commit -a -m "Automated deployment to update containers $(date '+%Y-%m-%d')" |
| 142 | + git push origin "${BRANCH_FROM}" |
| 143 | + fi |
| 144 | + echo "OPEN_PULL_REQUEST=${OPEN_PULL_REQUEST}" >> $GITHUB_ENV |
| 145 | + echo "PULL_REQUEST_FROM_BRANCH=${BRANCH_FROM}" >> $GITHUB_ENV |
| 146 | + echo "PULL_REQUEST_TITLE=[bot] ${BRANCH_FROM}" >> $GITHUB_ENV |
| 147 | + echo "PULL_REQUEST_BODY=Update container modules pull request." >> $GITHUB_ENV |
| 148 | + shell: bash |
| 149 | + |
| 150 | + - name: Open Pull Request |
| 151 | + uses: vsoch/pull-request-action@50f22f6d146226ee6b73b7a001f26a3d4579f360 # 1.0.22 |
| 152 | + if: ${{ env.OPEN_PULL_REQUEST == '1' }} |
| 153 | + env: |
| 154 | + GITHUB_TOKEN: ${{ inputs.token }} |
| 155 | + PULL_REQUEST_BRANCH: ${{ inputs.branch }} |
0 commit comments