generated from crossplane/function-template-go
-
Notifications
You must be signed in to change notification settings - Fork 9
147 lines (124 loc) · 4.16 KB
/
ci.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: CI
on:
push:
branches:
- main
- release-*
pull_request: {}
workflow_dispatch:
inputs:
version:
description: Package version (e.g. v0.1.0)
required: false
env:
# Common versions
GO_VERSION: '1.21.3'
GOLANGCI_VERSION: 'v1.54.2'
DOCKER_BUILDX_VERSION: 'v0.11.2'
XP_CHANNEL: master # TODO(negz): Pin to stable once v1.14 is released.
XP_VERSION: current # TODO(negz): Pin to a version once v1.14 is released.
# Common users. We can't run a step 'if secrets.USR != ""' but we can run
# a step 'if env.USR' != ""', so we copy these to succinctly test whether
# credentials have been provided before trying to run steps that need them.
XPKG_ACCESS_ID: ${{ secrets.XPKG_ACCESS_ID }}
# The package to push, without a version tag.
XPKG: xpkg.upbound.io/${{ github.repository}}
XPKG_VERSION: ${{ inputs.version }}
jobs:
lint:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache: false # The golangci-lint action does its own caching.
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCI_VERSION }}
unit-test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Run Unit Tests
run: go test -v -cover ./...
build:
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
arch:
- amd64
- arm64
steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true
- name: Checkout
uses: actions/checkout@v4
- name: Build Runtime
id: image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: image
build-args:
GO_VERSION=${{ env.GO_VERSION }}
outputs: type=docker,dest=runtime-${{ matrix.arch }}.tar
- name: Setup the Crossplane CLI
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
- name: Build Package
run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
- name: Upload Single-Platform Package
uses: actions/upload-artifact@v3
with:
name: packages
path: "*.xpkg"
if-no-files-found: error
retention-days: 1
push:
runs-on: ubuntu-22.04
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Single-Platform Packages
uses: actions/download-artifact@v3
with:
name: packages
path: .
- name: Setup the Crossplane CLI
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
- name: Login to Upbound
uses: docker/login-action@v3
if: env.XPKG_ACCESS_ID != ''
with:
registry: xpkg.upbound.io
username: ${{ secrets.XPKG_ACCESS_ID }}
password: ${{ secrets.XPKG_TOKEN }}
# If a version wasn't explicitly passed as a workflow_dispatch input we
# default to version v0.0.0-shortsha, for example v0.0.0-8ed5691.
- name: Set Default Multi-Platform Package Version
if: env.XPKG_VERSION == ''
run: echo "XPKG_VERSION=v0.0.0-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Push Multi-Platform Package to Upbound
if: env.XPKG_ACCESS_ID != ''
run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}"