Repository navigation
164 lines (152 loc) · 6.94 KB
/
Copy pathchart-pr.yml
File metadata and controls
164 lines (152 loc) · 6.94 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
# Reusable workflow for pull requests that change Helm charts: requires a semver label (major, minor or
# patch) and bumps the version of every chart the pull request changes, committing the result to the
# pull request branch. See README.md for how to call it.
name: Chart version
on:
workflow_call:
inputs:
charts-dir:
description: Directory that holds one directory per chart
type: string
default: charts
exclude:
description: Space-separated paths that never count as a chart change (default <charts-dir>/README.md)
type: string
default: ""
helm-docs-version:
description: Version of the jnorwood/helm-docs image to regenerate the charts' README.md with, e.g. v1.14.2 (default none, no regeneration)
type: string
default: ""
jobs:
semver-label:
name: Semver label
runs-on: ubuntu-latest
permissions:
contents: read # check out the label script
pull-requests: write
outputs:
bump: ${{ steps.label.outputs.bump }}
steps:
- name: Locate this workflow
env:
WORKFLOW_REPOSITORY: ${{ job.workflow_repository }}
WORKFLOW_SHA: ${{ job.workflow_sha }}
run: |
if [ -z "$WORKFLOW_REPOSITORY" ] || [ -z "$WORKFLOW_SHA" ]; then
echo "::error::job.workflow_repository and job.workflow_sha are empty: this workflow has to run as a reusable workflow on github.com"
exit 1
fi
echo "Using $WORKFLOW_REPOSITORY@$WORKFLOW_SHA"
- name: Check out the label script
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: chart-workflows
persist-credentials: false
# The labels the pull request has now, not the ones of the event that started the run: a pull
# request opened with a label (gh pr create --label) gets it right after the `opened` event, and
# the `labeled` event of the workflow token starts no run. Reading them now also lets a re-run
# pick up a label added later.
- name: Read the semver label
id: label
env:
GH_TOKEN: ${{ github.token }}
EVENT: pull_request
PR: ${{ github.event.pull_request.number }}
run: chart-workflows/scripts/semver-label.sh
# only when the label is the problem: a failure of the GitHub API is not the author's to fix
- name: Ask for the label
if: failure() && steps.label.outputs.label-missing == 'true'
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
run: |
gh pr comment "$PR" --repo "$GITHUB_REPOSITORY" \
--body "Please apply exactly one of the following labels to the PR: 'patch', 'minor', 'major'." \
|| echo "::warning::Could not comment on the pull request"
prepare-release:
name: Bump chart versions
needs: semver-label
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out the pull request branch
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
fetch-depth: 0
path: pr
# the script from the same commit as this workflow, not from the caller's repository
- name: Locate this workflow
env:
WORKFLOW_REPOSITORY: ${{ job.workflow_repository }}
WORKFLOW_SHA: ${{ job.workflow_sha }}
run: |
if [ -z "$WORKFLOW_REPOSITORY" ] || [ -z "$WORKFLOW_SHA" ]; then
echo "::error::job.workflow_repository and job.workflow_sha are empty: this workflow has to run as a reusable workflow on github.com"
exit 1
fi
echo "Using $WORKFLOW_REPOSITORY@$WORKFLOW_SHA"
- name: Check out the bump script
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: chart-workflows
persist-credentials: false
- name: Bump the versions
id: bump
working-directory: pr
env:
BUMP: ${{ needs.semver-label.outputs.bump }}
BASE_REF: ${{ github.base_ref }}
BASE_REPOSITORY: ${{ github.server_url }}/${{ github.repository }}
CHARTS_DIR: ${{ inputs.charts-dir }}
EXCLUDE: ${{ inputs.exclude }}
run: ../chart-workflows/scripts/bump-chart-versions.sh
# after the bump, so that the documentation shows the new versions. Only the charts the pull
# request changes: documentation another chart left stale would change that chart without a new
# version, which chart-release.yml refuses.
- name: Regenerate the chart documentation
id: docs
if: inputs.helm-docs-version != '' && steps.bump.outputs.changed != ''
working-directory: pr
env:
HELM_DOCS_VERSION: ${{ inputs.helm-docs-version }}
CHARTS_DIR: ${{ inputs.charts-dir }}
CHANGED: ${{ steps.bump.outputs.changed }}
run: |
for chart in $CHANGED; do
docker run --rm --volume "$PWD:/helm-docs" --user "$(id -u)" "jnorwood/helm-docs:$HELM_DOCS_VERSION" \
--chart-search-root "$CHARTS_DIR/$chart"
done
if git diff --quiet; then
echo "The chart documentation is up to date"
echo "committed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git add --update
bot_name="github-actions[bot]"
bot_email="41898282+github-actions[bot]@users.noreply.github.com"
GIT_AUTHOR_NAME="$bot_name" GIT_AUTHOR_EMAIL="$bot_email" \
GIT_COMMITTER_NAME="$bot_name" GIT_COMMITTER_EMAIL="$bot_email" \
git commit --quiet -m "Update helm documentation"
git show --stat --format='%s' HEAD
echo "committed=true" >> "$GITHUB_OUTPUT"
# the workflow token cannot push to a fork
- name: Versions to set in a pull request from a fork
if: (steps.bump.outputs.committed == 'true' || steps.docs.outputs.committed == 'true') && github.event.pull_request.head.repo.full_name != github.repository
working-directory: pr
run: |
echo "::error::This pull request comes from a fork, so the chart versions and documentation cannot be updated automatically. Set them in the pull request:"
git diff "origin/$GITHUB_HEAD_REF" HEAD
exit 1
- name: Push the versions
if: (steps.bump.outputs.committed == 'true' || steps.docs.outputs.committed == 'true') && github.event.pull_request.head.repo.full_name == github.repository
working-directory: pr
env:
HEAD_REF: ${{ github.head_ref }}
run: git push origin "HEAD:refs/heads/$HEAD_REF"