1+ name : Build & Release
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ architectures :
7+ description : A JSON list of GOARCH values for which to build
8+ default : ' ["amd64", "arm64"]'
9+ required : false
10+ type : string
11+ push-container-image :
12+ description : Whether to push the resulting container image to the registry
13+ default : false
14+ required : false
15+ type : boolean
16+ create-release :
17+ description : Whether to create a Github release and attach the artifacts to it
18+ default : false
19+ required : false
20+ type : boolean
21+
22+ permissions :
23+ contents : write
24+ packages : write
25+
26+ jobs :
27+ build-go :
28+ runs-on : ubuntu-latest
29+ strategy :
30+ matrix :
31+ arch : ${{ fromJson(inputs.architectures) }}
32+ steps :
33+ - name : Check out code
34+ uses : actions/checkout@v5
35+
36+ - name : Install Go
37+ uses : actions/setup-go@v5
38+ with :
39+ go-version-file : go.mod
40+
41+ - name : Run linter
42+ uses : golangci/golangci-lint-action@v8
43+
44+ - name : Run tests
45+ run : |-
46+ go test -v ./...
47+
48+ - name : Build
49+ run : |-
50+ mkdir -p $GITHUB_WORKSPACE/dist
51+
52+ CGO_ENABLED=0 \
53+ GOARCH=${{ matrix.arch }} \
54+ GOOS=linux \
55+ go build \
56+ -ldflags '\
57+ -s -w \
58+ -buildid=${{ github.sha }} \
59+ -X main.version=${{ github.ref_name }} \
60+ -X main.commit=${{ github.sha }} \
61+ ' \
62+ -trimpath -mod=readonly \
63+ -o $GITHUB_WORKSPACE/dist/multigres-operator-${{ matrix.arch }} \
64+ ./cmd/multigres-operator
65+
66+ - name : Upload artifacts
67+ uses : actions/upload-artifact@v4
68+ with :
69+ name : multigres-operator-${{matrix.arch}}
70+ path : dist/*
71+
72+ build-push-container :
73+ needs : [ build-go ]
74+ runs-on : ubuntu-latest
75+ steps :
76+ - name : Check out code
77+ uses : actions/checkout@v5
78+
79+ - name : Set up QEMU
80+ uses : docker/setup-qemu-action@v3
81+
82+ - name : Setup Docker buildx
83+ uses : docker/setup-buildx-action@v3
84+
85+ - name : Log into registry
86+ uses : docker/login-action@v3
87+ with :
88+ registry : ghcr.io
89+ username : ${{ github.actor }}
90+ password : ${{ secrets.GITHUB_TOKEN }}
91+
92+ - name : Extract container metadata
93+ id : meta
94+ uses : docker/metadata-action@v5
95+ with :
96+ github-token : ${{ secrets.GITHUB_TOKEN }}
97+ images : ghcr.io/${{ github.repository }}
98+ tags : |
99+ type=ref,event=branch,prefix=
100+ type=ref,event=tag,prefix=
101+ type=sha,format=short,prefix=
102+ type=sha,format=long,prefix=
103+
104+ - uses : actions/download-artifact@v5
105+ with :
106+ pattern : multigres-operator-*
107+ path : dist/
108+
109+ - name : Build and push container image
110+ id : build-and-push
111+ uses : docker/build-push-action@v5
112+ with :
113+ context : .
114+ file : Containerfile
115+ platforms : linux/${{ join(fromJson(inputs.architectures), ',linux/') }}
116+ push : ${{ inputs.push-container-image }}
117+ tags : ${{ steps.meta.outputs.tags }}
118+ labels : ${{ steps.meta.outputs.labels }}
119+ provenance : false
120+ cache-from : type=gha
121+ cache-to : type=gha,mode=max
122+
123+ create-release :
124+ needs : [ build-go ]
125+ runs-on : ubuntu-latest
126+ if : ${{ inputs.create-release }}
127+ steps :
128+ - uses : actions/download-artifact@v5
129+ with :
130+ pattern : " *"
131+ path : dist/
132+
133+ - name : Release
134+ uses : softprops/action-gh-release@v2
135+ with :
136+ files : dist/**
0 commit comments