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