-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (75 loc) · 3.28 KB
/
Copy pathauto-tag-on-merge.yaml
File metadata and controls
90 lines (75 loc) · 3.28 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
name: Release Chart on PR Merge
on:
pull_request:
types: [closed]
branches: [main]
jobs:
trigger-release:
name: Tag and Release Chart
if: |
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'chart-update')
runs-on: ubuntu-latest
permissions:
contents: write # Required to push tags
actions: write # Required to dispatch workflow_dispatch
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract chart info from PR
id: extract
run: |
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
# Extract chart name and version from branch name
# Format: update-{chart-name}-{version}
if [[ "$PR_BRANCH" =~ ^update-([a-zA-Z0-9-]+)-([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
CHART_NAME="${BASH_REMATCH[1]}"
VERSION="${BASH_REMATCH[2]}"
echo "chart_name=$CHART_NAME" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Chart: $CHART_NAME"
echo "Version: $VERSION"
else
echo "::error::Could not parse chart info from branch: $PR_BRANCH"
exit 1
fi
- name: Verify chart version in Chart.yaml
run: |
CHART_NAME="${{ steps.extract.outputs.chart_name }}"
EXPECTED="${{ steps.extract.outputs.version }}"
CHART_VERSION=$(yq '.version' "./charts/$CHART_NAME/Chart.yaml")
if [ "$CHART_VERSION" != "$EXPECTED" ]; then
echo "::error::Chart.yaml version ($CHART_VERSION) does not match expected ($EXPECTED)"
exit 1
fi
echo "Chart.yaml version matches: $CHART_VERSION"
- name: Create release tag
run: |
TAG_NAME="${{ steps.extract.outputs.chart_name }}-v${{ steps.extract.outputs.version }}"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists, skipping tag creation"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG_NAME" -m "Release ${{ steps.extract.outputs.chart_name }} v${{ steps.extract.outputs.version }}
Chart version: ${{ steps.extract.outputs.version }}
Automated release from PR #${{ github.event.pull_request.number }}"
# Push with GITHUB_TOKEN — tag won't trigger other workflows,
# but that's fine since we dispatch helm-release.yaml explicitly below.
git push origin "$TAG_NAME"
echo "Created tag: $TAG_NAME"
fi
- name: Trigger chart release workflow
env:
GH_TOKEN: ${{ github.token }}
run: |
CHART="${{ steps.extract.outputs.chart_name }}"
VERSION="v${{ steps.extract.outputs.version }}"
echo "Dispatching helm-release.yaml for $CHART $VERSION..."
gh workflow run helm-release.yaml \
--field chart="$CHART" \
--field version="$VERSION"
echo "Dispatched release workflow for $CHART $VERSION"
echo "Monitor: https://github.com/${{ github.repository }}/actions/workflows/helm-release.yaml"