push-tag.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright Broadcom, Inc. All Rights Reserved.
  2. # SPDX-License-Identifier: APACHE-2.0
  3. name: '[CI/CD] Push tag'
  4. on: # rebuild any PRs and main branch changes
  5. push:
  6. branches:
  7. - main
  8. paths:
  9. - 'bitnami/**'
  10. - '!**.md'
  11. # Remove all permissions by default.
  12. permissions: {}
  13. jobs:
  14. get-chart:
  15. runs-on: ubuntu-latest
  16. name: 'Get modified charts'
  17. permissions:
  18. contents: read
  19. outputs:
  20. chart: ${{ steps.get-chart.outputs.chart }}
  21. result: ${{ steps.get-chart.outputs.result }}
  22. if: ${{ github.repository_owner == 'bitnami' }}
  23. steps:
  24. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
  25. with:
  26. path: charts
  27. fetch-depth: 2 # to be able to obtain files changed in the latest commit
  28. - id: get-chart
  29. name: 'Get modified charts'
  30. run: |
  31. cd charts
  32. files_changed="$(git show --pretty="" --name-only)"
  33. # Adding || true to avoid "Process exited with code 1" errors
  34. charts_dirs_changed="$(echo "$files_changed" | xargs dirname | grep -o "bitnami/[^/]*" | sort | uniq || true)"
  35. # Using grep -c as a better alternative to wc -l when dealing with empty strings."
  36. num_charts_changed="$(echo "$charts_dirs_changed" | grep -c "bitnami" || true)"
  37. num_version_bumps="$(echo "$files_changed" | grep "bitnami/[^/]*/Chart.yaml" | xargs git show | grep -c "+version" || true)"
  38. if [[ "$num_charts_changed" -ne "$num_version_bumps" ]]; then
  39. # Changes done in charts but version not bumped -> ERROR
  40. charts_changed_str="$(echo ${charts_dirs_changed[@]})"
  41. echo "error=Detected changes in charts without version bump in Chart.yaml. Charts changed: ${num_charts_changed} ${charts_changed_str}. Version bumps detected: ${num_version_bumps}" >> $GITHUB_OUTPUT
  42. echo "result=fail" >> $GITHUB_OUTPUT
  43. elif [[ "$num_charts_changed" -eq "1" ]]; then
  44. # Changes done in only one chart -> OK
  45. chart_name=$(echo "$charts_dirs_changed" | sed "s|bitnami/||g")
  46. echo "chart=${chart_name}" >> $GITHUB_OUTPUT
  47. echo "result=ok" >> $GITHUB_OUTPUT
  48. else
  49. # Changes done in more than chart -> FAIL
  50. charts_changed_str="$(echo ${charts_dirs_changed[@]})"
  51. echo "error=Changes detected in more than one chart directory: ${charts_changed_str}. The publish process will be stopped. Please create different commits for each chart." >> $GITHUB_OUTPUT
  52. echo "result=fail" >> $GITHUB_OUTPUT
  53. fi
  54. - id: show-error
  55. name: 'Show error'
  56. if: ${{ steps.get-chart.outputs.result == 'fail' }}
  57. uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
  58. with:
  59. script: |
  60. core.setFailed('${{ steps.get-chart.outputs.error }}')
  61. push-tag:
  62. runs-on: ubuntu-latest
  63. permissions:
  64. contents: write
  65. needs:
  66. - get-chart
  67. name: Push tag
  68. if: ${{ needs.get-chart.outputs.result == 'ok' }}
  69. steps:
  70. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
  71. with:
  72. path: charts
  73. fetch-depth: 2 # to be able to obtain files changed in the latest commit
  74. - id: push-tag
  75. name: 'Push tag'
  76. env:
  77. CHART: ${{ needs.get-chart.outputs.chart }}
  78. run: |
  79. cd charts
  80. # Get chart version and list of tags
  81. chart_version="$(yq e '.version' bitnami/${CHART}/Chart.yaml)"
  82. git fetch --tags
  83. # If the tag does not exist, create and push it (this allows re-executing the job)
  84. if ! git tag | grep ${CHART}/${chart_version}; then
  85. git tag ${CHART}/${chart_version}
  86. git push --tags
  87. fi
  88. notify:
  89. name: Send notification
  90. needs:
  91. - push-tag
  92. if: ${{ always() && (needs.push-tag.result == 'failure') }}
  93. uses: bitnami/support/.github/workflows/gchat-notification.yml@main
  94. with:
  95. workflow: ${{ github.workflow }}
  96. job-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  97. secrets:
  98. webhook-url: ${{ secrets.GCHAT_CONTENT_ALERTS_WEBHOOK_URL }}