index-update.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. name: '[Index] Sync index.yaml with OCI releases'
  2. on:
  3. schedule:
  4. - cron: "*/30 * * * *"
  5. # Remove all permissions by default.
  6. permissions: {}
  7. jobs:
  8. find-new-releases:
  9. runs-on: ubuntu-latest
  10. name: Find new releases
  11. outputs:
  12. new-releases: ${{ steps.get-new-releases.outputs.new-releases }}
  13. permissions:
  14. contents: read
  15. if: ${{ github.repository_owner == 'bitnami' }}
  16. steps:
  17. - id: checkout-repo
  18. name: Checkout repo
  19. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
  20. with:
  21. ref: index
  22. path: index
  23. - uses: oras-project/setup-oras@5c0b487ce3fe0ce3ab0d034e63669e426e294e4d
  24. - id: get-oci-index
  25. name: Get OCI index
  26. run: |
  27. oras pull registry-1.docker.io/bitnamicharts/charts-index:latest
  28. cat charts-index.json | yq -P | yq eval '. | .entries[] |= .versions' > ./oci_index.yaml
  29. - id: get-charts-index
  30. name: Get Charts index
  31. run: |
  32. cp index/bitnami/index.yaml ./charts_index.yaml
  33. - id: merge
  34. name: Generate merged index
  35. run: |
  36. yq eval-all '. as $item ireduce ({}; . *+ $item )' charts_index.yaml oci_index.yaml > duplicates_index.yaml
  37. yq eval '.entries[] |= unique_by(.name + .version)' duplicates_index.yaml > merged_index.yaml
  38. - id: get-new-releases
  39. name: Find new versions
  40. run: |
  41. yq eval '.entries[][] | .name + ":" + .version' charts_index.yaml |sort| uniq > charts_index_releases
  42. yq eval '.entries[][] | .name + ":" + .version' merged_index.yaml | sort| uniq > merged_index_releases
  43. new_releases="$(comm -13 charts_index_releases merged_index_releases | tr "\n" " " | sed 's/ $//')"
  44. if [ -n "${new_releases}" ]; then
  45. echo "Found new releases: ${new_releases}"
  46. else
  47. echo "No new releases detected"
  48. fi
  49. echo "new-releases=$new_releases" >> $GITHUB_OUTPUT
  50. update-index:
  51. runs-on: ubuntu-latest
  52. needs:
  53. - find-new-releases
  54. name: Update index
  55. if: ${{ needs.find-new-releases.outputs.new-releases != '' }}
  56. steps:
  57. - name: Install helm
  58. run: |
  59. HELM_TARBALL="helm-v3.8.1-linux-amd64.tar.gz"
  60. curl -SsLfO "https://get.helm.sh/${HELM_TARBALL}" && sudo tar xf "$HELM_TARBALL" --strip-components 1 -C /usr/local/bin
  61. # Install file plugin
  62. helm plugin add https://github.com/zoobab/helm_file_repo
  63. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
  64. with:
  65. ref: 'index'
  66. path: index
  67. # The token is persisted in the local git config and enables scripts to run authenticated git commands.
  68. token: ${{ secrets.BITNAMI_BOT_TOKEN }}
  69. - id: update-index
  70. name: Pull charts and update index
  71. env:
  72. NEW_RELEASES: ${{ needs.find-new-releases.outputs.new-releases }}
  73. run: |
  74. cd index
  75. # Configure git
  76. git config user.name "Bitnami Containers"
  77. git config user.email "bitnami-bot@vmware.com"
  78. read -r -a new_releases_arr <<< $NEW_RELEASES
  79. for release in "${new_releases_arr[@]}"; do
  80. read -r -a release_arr <<< "$(tr ':' ' ' <<< "$release")"
  81. chart_name="${release_arr[0]}"
  82. chart_version="${release_arr[1]}"
  83. ## Update index
  84. # Download published asset
  85. mkdir ../download
  86. helm pull "oci://registry-1.docker.io/bitnamicharts/${chart_name}" --version "${chart_version}" --destination ../download
  87. # Rebuild index
  88. helm repo index --url oci://registry-1.docker.io/bitnamicharts --merge bitnami/index.yaml ../download
  89. # Replace .tgz in URL with OCI tag
  90. sed -i "s|oci://registry-1.docker.io/bitnamicharts/$chart_name-$chart_version.tgz|oci://registry-1.docker.io/bitnamicharts/$chart_name:$chart_version|" ../download/index.yaml
  91. # Check index integrity
  92. if [[ $(stat -c%s bitnami/index.yaml) -gt $(stat -c%s ../download/index.yaml) ]]; then
  93. echo "New index.yaml file is shorter than the current one"
  94. exit 1
  95. fi
  96. # Check repo can be loaded
  97. if ! helm repo add cache file://../download/ ; then
  98. echo "New index.yaml file can't be used as a file"
  99. exit 1
  100. else
  101. # Remove the repo
  102. helm repo remove cache
  103. fi
  104. cp ../download/index.yaml bitnami/index.yaml
  105. # Remove chart files
  106. rm -rf ../download
  107. done
  108. # Avoid overriding index branch when remote commit does not match our checkout commit
  109. current_commit_id=$(git rev-parse index)
  110. # Push changes
  111. git add bitnami/index.yaml && git commit --signoff --amend --no-edit
  112. git push origin index --force-with-lease=index:${current_commit_id}
  113. notify:
  114. name: Send notification
  115. needs:
  116. - update-index
  117. if: ${{ always() && (needs.update-index.result == 'failure') }}
  118. uses: bitnami/support/.github/workflows/gchat-notification.yml@main
  119. with:
  120. workflow: ${{ github.workflow }}
  121. job-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  122. secrets:
  123. webhook-url: ${{ secrets.GCHAT_CONTENT_ALERTS_WEBHOOK_URL }}