|
| 1 | +name: '[Index] Generate the full bitnami/charts index.yaml' |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - index |
| 6 | +jobs: |
| 7 | + get: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + name: Get |
| 10 | + steps: |
| 11 | + - id: checkout-repo-index |
| 12 | + name: Checkout repo |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + ref: index |
| 16 | + path: index |
| 17 | + - id: checkout-repo-full-index |
| 18 | + name: Checkout repo |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + ref: archive-full-index |
| 22 | + path: full-index |
| 23 | + - id: get-last-indexes |
| 24 | + name: Get indexes |
| 25 | + run: | |
| 26 | + cp index/bitnami/index.yaml ./last_index.yaml |
| 27 | + cp full-index/bitnami/index.yaml ./previous_index.yaml |
| 28 | + - id: upload-artifact |
| 29 | + name: Upload artifacts |
| 30 | + uses: actions/upload-artifact@v4 |
| 31 | + with: |
| 32 | + name: indexes |
| 33 | + path: ./*index.yaml |
| 34 | + retention-days: 2 |
| 35 | + if-no-files-found: error |
| 36 | + merge: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: get |
| 39 | + name: Merge |
| 40 | + steps: |
| 41 | + - id: download-artifact |
| 42 | + name: Download artifacts |
| 43 | + uses: actions/download-artifact@v4 |
| 44 | + with: |
| 45 | + name: indexes |
| 46 | + - id: merge |
| 47 | + name: Merge |
| 48 | + run: yq eval-all '. as $item ireduce ({}; . *+ $item )' previous_index.yaml last_index.yaml > duplicates_index.yaml |
| 49 | + - id: remove |
| 50 | + name: Remove duplicates |
| 51 | + # Removes duplicates per entry using 'digest' as value. |
| 52 | + run: yq eval '.entries[] |= unique_by(.digest)' duplicates_index.yaml > index.yaml |
| 53 | + - id: upload-artifact |
| 54 | + name: Upload artifacts |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: archive-full-index |
| 58 | + path: index.yaml |
| 59 | + retention-days: 2 |
| 60 | + if-no-files-found: error |
| 61 | + checks: |
| 62 | + runs-on: ubuntu-latest |
| 63 | + needs: merge |
| 64 | + name: Checks |
| 65 | + steps: |
| 66 | + - id: download-artifacts |
| 67 | + name: Download artifacts |
| 68 | + uses: actions/download-artifact@v4 |
| 69 | + - id: index-lint |
| 70 | + name: Lint archive full index |
| 71 | + # Lint the resulting archive full index using ignoring identation and lin-length rules. |
| 72 | + run: | |
| 73 | + cat << EOF > config |
| 74 | + extends: relaxed |
| 75 | +
|
| 76 | + rules: |
| 77 | + indentation: |
| 78 | + level: error |
| 79 | + line-length: disable |
| 80 | + EOF |
| 81 | + yamllint -c config archive-full-index/index.yaml |
| 82 | + - id: check-no-dups |
| 83 | + name: Checks there are not any duplicates |
| 84 | + # Try to find duplicate digest attributes which would mean there are duplicates. |
| 85 | + run: | |
| 86 | + yq eval '.entries[][].digest' archive-full-index/index.yaml | sort | uniq -d | ( ! grep sha256 ) |
| 87 | + - id: check-missing-releases |
| 88 | + name: Checks there are not missing releases |
| 89 | + # Available URLs should be fine if everything went well during the merge & deduplication. |
| 90 | + run: | |
| 91 | + yq eval '.entries[][].urls[]' indexes/last_index.yaml |sort| uniq > last_index_urls |
| 92 | + yq eval '.entries[][].urls[]' archive-full-index/index.yaml | sort| uniq > index_urls |
| 93 | + missing_urls="$(comm -13 index_urls last_index_urls)" |
| 94 | + if [ -n "${missing_urls}" ]; then |
| 95 | + echo "Found missing URLs:\n${missing_urls}" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + echo "No missing releases detected" |
| 99 | + update: |
| 100 | + runs-on: ubuntu-latest |
| 101 | + needs: checks |
| 102 | + name: Update |
| 103 | + steps: |
| 104 | + - id: checkout-repo |
| 105 | + name: Checkout repo |
| 106 | + uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + ref: archive-full-index |
| 109 | + token: ${{ secrets.BITNAMI_BOT_TOKEN }} |
| 110 | + - id: download-artifact-archive-full-index |
| 111 | + name: Download artifacts |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + with: |
| 114 | + name: archive-full-index |
| 115 | + - id: update-index |
| 116 | + name: git-add-push |
| 117 | + run: | |
| 118 | + git config user.name "Bitnami Containers" |
| 119 | + git config user.email "bitnami-bot@vmware.com" |
| 120 | + git fetch origin archive-full-index |
| 121 | + git reset --hard $(git commit-tree origin/archive-full-index^{tree} -m "Update index.yaml") |
| 122 | + # Compare size of files |
| 123 | + if [[ $(stat -c%s bitnami/index.yaml) -gt $(stat -c%s index.yaml) ]]; then |
| 124 | + echo "New index.yaml file is shorter than the current one" |
| 125 | + exit 1 |
| 126 | + fi |
| 127 | + cp index.yaml bitnami/index.yaml |
| 128 | + git add bitnami/index.yaml && git commit --signoff --amend --no-edit && git push origin archive-full-index --force-with-lease |
0 commit comments