-
-
Notifications
You must be signed in to change notification settings - Fork 15
129 lines (125 loc) · 4.17 KB
/
packaging.yml
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
name: Packaging
on:
release:
types: [published]
pull_request:
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
container-image:
name: Container Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Assemble metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
# We want to set the following tags:
# - `main` if executed for build on main branch
# - SemVer when running for a release
tags: |
type=ref,enable=${{ github.ref_name == 'main' }},event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Login to GitHub container registry
# We only need to log in if we want to push to GHCR
if: github.event_name == 'release' || github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build multi-platform image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
# Only push when building for a tag or the main branch
push: ${{ github.event_name == 'release' || github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
# Only export and upload the image if used for testing
- name: Export image for test platform
if: github.event_name != 'release'
uses: docker/build-push-action@v5
with:
context: .
push: false
outputs: type=docker,dest=/tmp/image.tar
- name: Upload image for testing
uses: actions/upload-artifact@v4
if: github.event_name != 'release'
with:
name: docker-image
path: /tmp/image.tar
helm-chart:
name: Helm Chart
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Helm
uses: azure/setup-helm@v4
- name: Login to GitHub OCI Registry
run: |
echo ${{ github.token }} | \
helm registry login ghcr.io --username ${{ github.actor }} --password-stdin
- name: Download Dependencies
run: helm dependency build
working-directory: ./chart
- name: Package Chart
run: |
VERSION=${{ github.ref_name }}
helm package . \
--app-version ${VERSION#v} \
--version ${VERSION#v}
working-directory: ./chart
- name: Push Chart
run: |
VERSION=${{ github.ref_name }}
helm push switchboard-${VERSION#v}.tgz oci://ghcr.io/${{ github.actor }}/charts
working-directory: ./chart
e2e-tests:
name: End-to-end Tests
if: github.event_name != 'release'
needs: container-image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: "16"
- name: Install bats
run: npm install -g bats@1.6.0
shell: bash
- name: Download image for testing
uses: actions/download-artifact@v4
with:
name: docker-image
path: /tmp
- name: Setup just
uses: extractions/setup-just@v2
- name: Setup Kubernetes cluster
uses: container-tools/kind-action@v2.0.4
with:
config: tests/config/kind.yaml
- name: Import Docker image
run: |
IMAGE_ID=$(docker load -i /tmp/image.tar | rev | cut -d' ' -f1 | rev)
docker tag $IMAGE_ID $KIND_REGISTRY/switchboard:dev
docker push $KIND_REGISTRY/switchboard:dev
- name: Run tests
run: just e2e-test-ci "${{ env.KIND_REGISTRY }}/switchboard" "dev"