-
Notifications
You must be signed in to change notification settings - Fork 4
149 lines (124 loc) · 4.78 KB
/
kubernetes-agent-publish-chart.yaml
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
name: Publish Kubernetes Agent chart
on:
push:
branches:
- main
- release/kubernetes-agent/v*
pull_request:
jobs:
paths_filter:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.filter.outputs.kubernetes-agent }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
kubernetes-agent:
- charts/kubernetes-agent/**
- .github/workflows/kubernetes-agent-publish-chart.yaml
test:
needs: paths_filter
if: needs.paths_filter.outputs.result == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.13.2
- name: Run Helm unit tests
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest.git
helm unittest charts/kubernetes-agent
check-readme:
needs: paths_filter
if: needs.paths_filter.outputs.result == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
- name: Generate docs
working-directory: charts/kubernetes-agent
run: "npm run generate-agent-docs"
- name: Check readme is unchanged
run: |
echo "Ensuring readme is up-to-date"
echo "If this test fails, run 'npm run generate-agent-docs' locally and commit the changes"
git diff --ignore-cr-at-eol -w --exit-code
version_and_package:
needs: test
runs-on: ubuntu-latest
outputs:
CHART_VERSION: ${{ steps.version.outputs.CHART_VERSION }}
PACKAGE_NAME: ${{ steps.version.outputs.PACKAGE_NAME }}
steps:
- uses: actions/checkout@v4
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 'v3.13.2'
- name: Parse Chart config
uses: pietrobolcato/[email protected]
id: read_chart_yaml
with:
config: ${{ github.workspace }}/charts/kubernetes-agent/Chart.yaml
- name: Get branch names
id: branch_names
uses: OctopusDeploy/util-actions/[email protected]
- name: Generate chart version
id: version
shell: bash
run: |
chart_version="${{ steps.read_chart_yaml.outputs.version }}"
pre_release=""
if [[ "${{steps.branch_names.outputs.branch_name}}" != "main" ]]
then
# underscores in branches make for illegal version-string, replace with "-"
cleansed_branch=`echo ${{steps.branch_names.outputs.branch_name}} | sed s/_/-/g`
pre_release="-${cleansed_branch}-$(date +'%Y%m%d%H%M%S')"
fi
full_version="$chart_version$pre_release"
echo "CHART_VERSION=$full_version" >> $GITHUB_OUTPUT
echo "PACKAGE_NAME=kubernetes-agent-$full_version.tgz" >> $GITHUB_OUTPUT
- name: Package Chart
run: helm package './charts/kubernetes-agent' --version '${{ steps.version.outputs.CHART_VERSION }}'
- uses: actions/upload-artifact@v4
name: Upload packaged chart
with:
name: '${{ steps.version.outputs.PACKAGE_NAME }}'
path: '${{ github.workspace }}/kubernetes-agent-${{ steps.version.outputs.CHART_VERSION }}.tgz'
publish_to_octopus:
runs-on: ubuntu-latest
# We publish to Artifactory if this is not a main commit, or if it is, that it's a versioning commit
if: ${{ github.ref != 'refs/heads/main' || (github.ref == 'refs/heads/main' && startsWith(github.event.commits[0].message, 'Version Charts')) }}
needs: version_and_package
permissions:
# You might need to add other permissions here like `contents: read` depending on what else your job needs to do
id-token: write # This is required to obtain an ID token from GitHub Actions for the job
steps:
- name: Download packaged chart
uses: actions/download-artifact@v4
with:
name: '${{ needs.version_and_package.outputs.PACKAGE_NAME }}'
- name: Login to Octopus
uses: OctopusDeploy/login@v1
with:
server: ${{ vars.OCTOPUS_SERVER }}
service_account_id: ${{ secrets.OCTOPUS_SERVICE_ACCOUNT }}
- name: Push helm chart to Octopus Deploy 🐙
uses: OctopusDeploy/push-package-action@v3
with:
space: 'Modern Deployments'
packages: ${{ needs.version_and_package.outputs.PACKAGE_NAME }}
overwrite_mode: IgnoreIfExists
- name: Create a release in Octopus Deploy 🐙
uses: OctopusDeploy/create-release-action@v3
with:
space: 'Modern Deployments'
project: 'Octopus Kubernetes Agent'
release_number: ${{ needs.version_and_package.outputs.CHART_VERSION }}
package_version: ${{ needs.version_and_package.outputs.CHART_VERSION }}
ignore_existing: true