-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (121 loc) · 4.08 KB
/
ci.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
name: CI
on:
push:
branches-ignore:
- "dependabot/**"
- "gh-pages/**"
paths:
- "**"
- "!docs/**"
tags:
- "v*"
pull_request:
branches-ignore:
- "dependabot/**"
- "gh-pages/**"
paths:
- "**"
- "!docs/**"
env:
CHART_VERSION: "0.0.0"
CHARTS_TMP_DIR: dist
OCI_URL: "oci://ghcr.io/${{ github.repository }}/charts"
LC_ALL: en_US.UTF-8
MAIN_REPO: "LiferayCloud/liferay-helm-chart"
PUBLISH: "false"
SOURCE_DIR: "."
defaults:
run:
shell: bash
permissions:
packages: write
contents: write
jobs:
ci:
name: Build, Test, maybe Publish
runs-on: ubuntu-latest
steps:
- name: Clone the code
uses: actions/checkout@v4
- name: Install Helm
run: |
curl -sL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Verify Helm Installation
shell: bash
run: |
helm version
- name: Install the latest version of Kind
shell: bash
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: Verify Kind Installation
shell: bash
run: |
kind version
- name: Create Kind Cluster
shell: bash
run: |
kind create cluster
- name: Run Helm Test
id: helm-test
run: |
helm upgrade -i liferay .
helm test liferay && \
echo "PUBLISH=${{ (github.repository == env.MAIN_REPO) && startsWith(github.ref, 'refs/tags/') && (github.event_name != 'pull_request') }}" >> ${GITHUB_ENV}
- name: Calculate Chart Version
if: ${{ env.PUBLISH == 'true' }}
id: calculate-chart-version
run: |
# This is the tag name
echo GITHUB_REF=${{ github.ref }}
# This is the version
CHART_VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && CHART_VERSION=$(echo $CHART_VERSION | sed -e 's/^v//')
[ "$CHART_VERSION" == "main" ] && CHART_VERSION="0.0.0"
echo CHART_VERSION=$CHART_VERSION
echo "CHART_VERSION=${CHART_VERSION}" >> ${GITHUB_ENV}
- name: Package the Helm Chart
if: ${{ env.PUBLISH == 'true' }}
run: |
mkdir ${CHARTS_TMP_DIR}
helm package --version ${CHART_VERSION} -d ${CHARTS_TMP_DIR} .
echo "CHARTS_TMP_DIR=$(realpath $CHARTS_TMP_DIR)" >> ${GITHUB_ENV}
echo "SOURCE_DIR=$(realpath $SOURCE_DIR)" >> ${GITHUB_ENV}
- name: Log in to registry with Helm
if: ${{ env.PUBLISH == 'true' }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io/${{ github.repository }} --username ${{ github.actor }} --password-stdin
- name: Push Helm Charts to Github Container Registry (OCI)
if: ${{ env.PUBLISH == 'true' }}
working-directory: dist
run: |
OCI_URL=$(echo "$OCI_URL" | tr '[:upper:]' '[:lower:]')
for f in *.tgz ; do
echo "$f"
helm push "$f" "$OCI_URL"
done
echo "OCI_URL=$OCI_URL" >> ${GITHUB_ENV}
- name: Install YQ
if: ${{ env.PUBLISH == 'true' }}
run: |
curl -sLo ./yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
chmod +x ./yq
sudo mv ./yq /usr/local/bin/yq
- name: Test YQ Installation
if: ${{ env.PUBLISH == 'true' }}
run: |
yq --version
- name: Update and Publish the Helm Index
if: ${{ env.PUBLISH == 'true' }}
run: |
./.github/scripts/publish_helm_index.sh
env:
GIT_REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INDEX_DIR: charts
OWNER: ${{ github.actor }}
PUBLISH_BRANCH: gh-pages
REPO_URL: "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
REPOSITORY: ${{ github.event.repository.name }}