|
| 1 | +--- |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + chart_name: |
| 6 | + type: string |
| 7 | + required: true |
| 8 | + description: "Chart name to release" |
| 9 | + chart_dir: |
| 10 | + type: string |
| 11 | + required: true |
| 12 | + description: "Chart path to release" |
| 13 | + chart_yaml_version_keys: |
| 14 | + type: string |
| 15 | + required: true |
| 16 | + description: "Keys in the Chart.yaml to replace with the new version" |
| 17 | + repository_owner: |
| 18 | + type: string |
| 19 | + default: elastiflow |
| 20 | + description: "Repository owner to push the Helm registry index" |
| 21 | + repository_name: |
| 22 | + type: string |
| 23 | + default: helm-chart-netobserv |
| 24 | + description: "Repository name to push the Helm registry index" |
| 25 | + runs-on: |
| 26 | + type: string |
| 27 | + default: ubuntu-latest |
| 28 | + description: "GHA runner for the job (ubuntu-latest, ubuntu-latest-4c, ubuntu-latest-8c)" |
| 29 | + timeout-minutes: |
| 30 | + type: number |
| 31 | + default: 15 |
| 32 | + description: "Job timeout in minutes" |
| 33 | + |
| 34 | +jobs: |
| 35 | + # Detect if a commit was made from a release PR with title like '[release v0.1.1] (#49)' |
| 36 | + release_or_pr: |
| 37 | + name: Release or Release PR? |
| 38 | + runs-on: ${{ inputs.runs-on }} |
| 39 | + timeout-minutes: ${{ inputs.timeout-minutes }} |
| 40 | + outputs: |
| 41 | + is_release: ${{ steps.release_or_pr.outputs.is_release }} |
| 42 | + steps: |
| 43 | + - id: release_or_pr |
| 44 | + env: |
| 45 | + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} |
| 46 | + run: | |
| 47 | + cat > /tmp/commit_message <<- EOF |
| 48 | + ${COMMIT_MESSAGE} |
| 49 | + EOF |
| 50 | +
|
| 51 | + # https://regex101.com/r/plAysi/1 |
| 52 | + echo $(grep -Pq '^\[release netobserv-[a-z]+-(?:[0-9]{1,3}\.?){3}(?:-rc(?:\.[0-9]{1,3})?)?\] \(#[0-9]{1,5}\)$' /tmp/commit_message && echo true || echo false) > /tmp/is_release |
| 53 | + echo "is_release=$(cat /tmp/is_release)" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + echo is_release=$(cat /tmp/is_release) |
| 56 | +
|
| 57 | +
|
| 58 | + release_pr_create: |
| 59 | + name: Release PR create |
| 60 | + needs: [release_or_pr] |
| 61 | + if: ${{ ! fromJson(needs.release_or_pr.outputs.is_release) }} |
| 62 | + runs-on: ${{ inputs.runs-on }} |
| 63 | + timeout-minutes: ${{ inputs.timeout-minutes }} |
| 64 | + permissions: |
| 65 | + contents: write |
| 66 | + pull-requests: write |
| 67 | + steps: |
| 68 | + - name: Checkout |
| 69 | + uses: actions/checkout@v5 |
| 70 | + - name: Prepare ${{ inputs.chart_name }} Release |
| 71 | + id: prepare_release |
| 72 | + uses: elastiflow/gha-reusable/actions/prepare-release@v0 |
| 73 | + with: |
| 74 | + semantic_release_working_directory: ${{ inputs.chart_dir }} |
| 75 | + semantic_release_monorepo: true |
| 76 | + changelog_update: true |
| 77 | + changelog_path: ${{ inputs.chart_dir }}/CHANGELOG.md |
| 78 | + bump_version_yaml: true |
| 79 | + bump_version_yaml_path: ${{ inputs.chart_dir }}/Chart.yaml |
| 80 | + bump_version_yaml_key: ${{ inputs.chart_yaml_version_keys }} |
| 81 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + - name: Create Pull Request |
| 83 | + if: ${{ fromJson(steps.prepare_release.outputs.new_release_published) }} |
| 84 | + uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 |
| 85 | + with: |
| 86 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + base: "${{ github.ref_name }}" |
| 88 | + branch: release-${{ inputs.chart_name }}-from-${{ github.ref_name }} |
| 89 | + title: '[release ${{ inputs.chart_name }}-${{ steps.prepare_release.outputs.new_release_version }}]' |
| 90 | + body: | |
| 91 | + # Description |
| 92 | + Release the v${{ steps.prepare_release.outputs.new_release_version }} version |
| 93 | +
|
| 94 | + # Changelog |
| 95 | + ${{ steps.prepare_release.outputs.new_release_notes }} |
| 96 | +
|
| 97 | + release: |
| 98 | + name: Release |
| 99 | + needs: [release_or_pr] |
| 100 | + if: ${{ fromJson(needs.release_or_pr.outputs.is_release) }} |
| 101 | + runs-on: ${{ inputs.runs-on }} |
| 102 | + timeout-minutes: ${{ inputs.timeout-minutes }} |
| 103 | + permissions: |
| 104 | + contents: write |
| 105 | + steps: |
| 106 | + - name: Checkout |
| 107 | + uses: actions/checkout@v5 |
| 108 | + with: |
| 109 | + fetch-depth: 0 |
| 110 | + - name: Prepare Release |
| 111 | + id: prepare_release |
| 112 | + uses: elastiflow/gha-reusable/actions/prepare-release@v0 |
| 113 | + with: |
| 114 | + semantic_release_working_directory: ${{ inputs.chart_dir }} |
| 115 | + semantic_release_monorepo: true |
| 116 | + add_git_notes: true |
| 117 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + - name: Configure Git |
| 119 | + run: | |
| 120 | + git config user.name "$GITHUB_ACTOR" |
| 121 | + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" |
| 122 | + - name: Install Helm |
| 123 | + uses: azure/setup-helm@v4 |
| 124 | + - name: Install Helm dependencies |
| 125 | + run: | |
| 126 | + (helm dependency list ${{ inputs.chart_dir }} || true) | grep -E 'https://' | while read -r dep; do |
| 127 | + helm repo add $(echo ${dep} | awk '{print $1}') $(echo ${dep} | awk '{print $4}') |
| 128 | + done |
| 129 | + - name: Install chart-releaser |
| 130 | + uses: helm/chart-releaser-action@v1.7.0 |
| 131 | + env: |
| 132 | + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 133 | + with: |
| 134 | + install_only: true |
| 135 | + - name: Package helm chart |
| 136 | + run: | |
| 137 | + cr package ${{ inputs.chart_dir }} |
| 138 | + - name: Create GH release |
| 139 | + if: ${{ fromJson(steps.prepare_release.outputs.new_release_published) }} |
| 140 | + uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 |
| 141 | + with: |
| 142 | + name: ${{ inputs.chart_name }}-${{ steps.prepare_release.outputs.new_release_version }} |
| 143 | + tag_name: ${{ inputs.chart_name }}-${{ steps.prepare_release.outputs.new_release_version }} |
| 144 | + body: ${{ steps.prepare_release.outputs.new_release_notes }} |
| 145 | + target_commitish: ${{ github.ref_name }} |
| 146 | + preserve_order: true |
| 147 | + make_latest: true |
| 148 | + files: ".cr-release-packages/${{ inputs.chart_name }}-*.tgz" |
| 149 | + - name: Update GH pages index |
| 150 | + run: | |
| 151 | + mkdir .cr-index |
| 152 | + cr index --push -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ inputs.repository_owner }} --git-repo ${{ inputs.repository_name }} |
0 commit comments