generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (119 loc) · 4.23 KB
/
publish.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
name: Publish artifacts
on:
release:
types: [published]
concurrency: release-${{ github.event.release.tag_name }}
env:
REGCTL_VERSION: v0.4.8
REGISTRY: ghcr.io
CHART_DIRECTORY: chart
defaults:
run:
shell: bash
jobs:
validate:
name: Run validations
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate chart version/appVersion
run: |
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
app_version=$(yq .appVersion $CHART_DIRECTORY/Chart.yaml)
if [ "v$chart_version" != "${{ github.event.release.tag_name }}" ]; then
>&2 echo "Version in $CHART_DIRECTORY/Chart.yaml ($chart_version) does not match release version (${{ github.event.release.tag_name }})."
exit 1
fi
if [ "$app_version" != "${{ github.event.release.tag_name }}" ]; then
>&2 echo "AppVersion in $CHART_DIRECTORY/Chart.yaml ($app_version) does not match release version (${{ github.event.release.tag_name }})."
exit 1
fi
publish-docker:
name: Publish Docker image
runs-on: ubuntu-22.04
needs: validate
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Prepare repository name
id: prepare-repository-name
run: |
repository=$REGISTRY/${{ github.repository }}
echo "repository=${repository,,}" >> $GITHUB_OUTPUT
- name: Prepare custom labels for Docker
id: extract-custom-labels
run: |
echo "labels<<EOF" >> $GITHUB_OUTPUT
for c in pkg/operator/data/charts/*/Chart.yaml; do
name=$(yq .name $c)
version=$(yq .version $c)
app_version=$(yq .appVersion $c)
echo "com.sap.cs.image.content.charts.$name.version=$version" >> $GITHUB_OUTPUT
if [ ! -z "$app_version" ]; then
echo "com.sap.cs.image.content.charts.$name.app-version=$app_version" >> $GITHUB_OUTPUT
fi
done
echo "EOF" >> $GITHUB_OUTPUT
- name: Extract metadata (tags, labels) for Docker
id: extract-metadata
uses: docker/metadata-action@v4
with:
images: ${{ steps.prepare-repository-name.outputs.repository }}
labels: ${{ steps.extract-custom-labels.outputs.labels }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
context: .
cache-from: |
type=gha,scope=sha-${{ github.sha }}
type=gha,scope=${{ github.ref_name }}
type=gha,scope=${{ github.base_ref || 'main' }}
type=gha,scope=main
cache-to: |
type=gha,scope=sha-${{ github.sha }},mode=max
type=gha,scope=${{ github.ref_name }},mode=max
push: true
tags: ${{ steps.extract-metadata.outputs.tags }}
labels: ${{ steps.extract-metadata.outputs.labels }}
publish-crds:
name: Publish CRD image
runs-on: ubuntu-22.04
needs: validate
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup regctl
uses: regclient/actions/regctl-installer@main
with:
release: ${{ env.REGCTL_VERSION }}
install-dir: ${{ runner.temp }}/bin
- name: Log in to the registry
# regctl-login action is currently broken ...
# uses: regclient/actions/regctl-login@main
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ github.token }}
run: |
regctl registry login $REGISTRY --user ${{ github.actor }} --pass-stdin <<< ${{ github.token }}
- name: Build and push artifact
run: |
cd crds
repository=$REGISTRY/${{ github.repository }}/crds
tar cvz * | regctl artifact put -m application/gzip ${repository,,}:${{ github.event.release.tag_name }}