-
Notifications
You must be signed in to change notification settings - Fork 12
176 lines (162 loc) · 6.22 KB
/
multi-platform.yml
File metadata and controls
176 lines (162 loc) · 6.22 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
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
173
174
175
176
name: Multi-Platform Build and Release
on:
# release:
# types: [published]
# push:
# tags:
# - "v*"
# branches:
# - "master"
# paths-ignore:
# - "docs/**"
# - '.github/**'
workflow_call:
inputs:
release-channel:
description: "Release channel (stable or edge)"
required: true
type: string
default: "stable"
release-ver:
description: "Stable Release Version"
required: true
default: "v"
type: string
workflow_dispatch:
inputs:
release-channel:
description: "Release channel (stable or edge)"
required: true
type: string
default: "stable"
release-ver:
description: "Stable Release Version"
required: true
default: "v"
type: string
env:
GIT_VERSION: ${{github.event.inputs.release-ver || inputs.release-ver }}
RELEASE_CHANNEL: ${{github.event.inputs.release-channel || inputs.release-channel }}
jobs:
validate-inputs:
runs-on: ubuntu-latest
steps:
- name: Validate inputs
run: |
echo "Validating GIT_VERSION and RELEASE_CHANNEL..."
if [ -z "${{ env.GIT_VERSION }}" ]; then
echo "❌ Error: GIT_VERSION is empty!"
exit 1
fi
if [ ${#GIT_VERSION} -le 3 ]; then
echo "❌ Error: GIT_VERSION '${GIT_VERSION}' is too short. It must be > 3 characters."
exit 1
fi
if [ -z "${{ env.RELEASE_CHANNEL }}" ]; then
echo "❌ Error: RELEASE_CHANNEL is empty!"
exit 1
fi
echo "✓ Validation passed: GIT_VERSION=${{ env.GIT_VERSION }}, RELEASE_CHANNEL=${{ env.RELEASE_CHANNEL }}"
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Identify Release Values
run: |
GIT_VERSION="${{ env.GIT_VERSION }}"
GIT_STRIPPED_VERSION="${GIT_VERSION#v}"
echo "GIT_STRIPPED_VERSION=$GIT_STRIPPED_VERSION" >> $GITHUB_ENV
shell: bash
- name: Setup image tags in docker-compose.yaml
run: |
sed -i "s/kanvas-docker-extension:stable-latest/kanvas-docker-extension:${{env.RELEASE_CHANNEL}}-${{env.GIT_VERSION}}/g" docker-compose.yaml
sed -i "s/meshery:kanvas-latest/meshery:kanvas-${{env.GIT_VERSION}}/g" docker-compose.yaml
cat docker-compose.yaml
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: layer5/kanvas-docker-extension
flavor: |
latest=false
tags: |
type=raw,value=${{env.RELEASE_CHANNEL}}-{{sha}}
type=semver,pattern={{version}},value=${{env.GIT_STRIPPED_VERSION}}
type=raw,pattern={{version}},value=${{env.RELEASE_CHANNEL}}-${{env.GIT_VERSION}}
type=raw,value=${{env.RELEASE_CHANNEL}}-{{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=raw,value=${{env.RELEASE_CHANNEL}}-latest
type=raw,pattern={{version}},value=${{env.RELEASE_CHANNEL}}-${{env.GIT_VERSION}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}"
push: true
build-args: |
GIT_STRIPPED_VERSION=${{env.GIT_STRIPPED_VERSION}}
GIT_VERSION=${{env.GIT_VERSION}}
RELEASE_CHANNEL=${{env.RELEASE_CHANNEL}}
RELEASE_NOTES="See https://docs.layer5.io/kanvas/reference/releases/${{ env.GIT_VERSION }}"
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: layer5/kanvas-docker-extension
readme-filepath: README.md
email-on-failure:
needs: [docker-build]
if: ${{ failure() }}
runs-on: ubuntu-24.04
steps:
- name: Find failed jobs.
run: |
curl "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs" | jq -r '.jobs[] | select(.conclusion == "failure") | "\(.name): \(.steps[] | select(.conclusion == "failure") | .name)\n\(.html_url)\n"' >> output.txt
# Save multi-line environment variables by using the delimiters syntex.
echo "EMAIL_BODY<<EOF" >> $GITHUB_ENV
echo "$(cat ./output.txt)" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Failed jobs summary
run: |
echo "${{ env.EMAIL_BODY }}"
- name: Send Email Notification
if: ${{ env.EMAIL_BODY != '' }}
uses: dawidd6/action-send-mail@v6
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: Job(s) failure in the build-and-release-stable workflow
to: support@layer5.io
from: Docker Kanvas Extension Releaser
body: |
The workflow failed. Here are the details:
${{ env.EMAIL_BODY }}
Workflow run log URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
create-release:
needs: docker-build
runs-on: ubuntu-latest
if: ${{ needs.docker-build.result == 'success' }}
steps:
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat <<'EOF' > notes.txt
See https://docs.layer5.io/kanvas/reference/releases/${{ env.GIT_VERSION }}"
EOF
gh release create "${{ env.GIT_VERSION }}" \
--title "Kanvas Docker Extension ${{ env.GIT_VERSION }}" \
--notes-file notes.txt