-
Notifications
You must be signed in to change notification settings - Fork 23
172 lines (147 loc) · 5.45 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
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
165
166
167
168
169
170
171
172
name: Publish Image and Chart # and create GitHub release if v* tag
on:
push:
branches: [ main ]
tags: [ "v*" ]
pull_request:
branches: [ main ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup version info
id: version
run: |
if [[ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]]; then
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
else
echo "version=$(date +%Y%m%d-%H%M%S)-g$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
chart:
name: Publish chart
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs: [docker]
env:
APP_VERSION: ${{ needs.docker.outputs.version }}
CHART_REGISTRY: "ghcr.io/${{ github.repository_owner }}/charts"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Fetching all history as we may use the latest tag for versioning
# Unfortunately, just using 'fetch-tags: true' on the actions/checkout configuration
# above doesn't get what we need; see https://github.com/actions/checkout/issues/1471
fetch-depth: 0
- name: Install helm
uses: Azure/setup-helm@v4
with:
version: v3.14.0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
- name: Install dependencies
run: go mod download
- name: Determine chart version
run: |
if [[ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]]; then
# NOTE: We remove the leading 'v' to comply with helm's versioning requirements
echo "CHART_VERSION=$(echo -n ${{ github.ref_name }} | sed -rn 's/(v)?(.*)/\2/p')" >> $GITHUB_ENV
else
# NOTE: 'git describe --tags --abbrev=0' always seems to return a commit; hence approach used below
echo "CHART_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1) | sed -rn 's/(v)?(.*)/\2/p')-${{ env.APP_VERSION }}" >> $GITHUB_ENV
fi
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build chart
run: make helm-generate
- name: Package chart
run: make dist
- name: Lint packaged chart
run: |
# Remove staged chart directory and lint the packaged version
rm -rf _dist/spin-operator-${{ env.CHART_VERSION }}
helm lint _dist/spin-operator-${{ env.CHART_VERSION }}.tgz
- name: Upload chart and manifests as GitHub artifact
uses: actions/upload-artifact@v4
with:
name: spin-operator
path: _dist
- name: Publish chart
run: make helm-publish
- name: Artifact summary - ${{ env.RELEASE_VERSION }}
run: |
echo '### Spin Operator artifacts published:' >> $GITHUB_STEP_SUMMARY
echo '- `Docker image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.APP_VERSION }}`' >> $GITHUB_STEP_SUMMARY
echo '- `Helm chart reference: ${{ env.CHART_REGISTRY }}/spin-operator`' >> $GITHUB_STEP_SUMMARY
echo '- `Helm chart version: ${{ env.CHART_VERSION }}`' >> $GITHUB_STEP_SUMMARY
release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs: [chart]
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: download release assets
uses: actions/download-artifact@v4
with:
name: spin-operator
path: _dist
- name: check if pre-release
shell: bash
run: |
if [[ ! "${{ github.ref_name }}" =~ ^v[0-9]+.[0-9]+.[0-9]+$ ]]
then
echo "PRERELEASE=--prerelease" >> "$GITHUB_ENV"
fi
- name: create GitHub release
run: |
gh release create ${{ github.ref_name }} _dist/* \
--title ${{ github.ref_name }} \
--generate-notes ${{ env.PRERELEASE }}