-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (123 loc) · 5.06 KB
/
release.yml
File metadata and controls
134 lines (123 loc) · 5.06 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
name: Build silta cli binary on release creation
on:
release:
types: [created]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
tests-matrix:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v6
- uses: azure/setup-helm@v5.0.0
with:
version: 'v3.18.4'
name: Install Helm
- name: Add wunderio Helm repo
run: helm repo add wunderio https://storage.googleapis.com/charts.wdr.io
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: 1.25.0
- name: Run tests
run: go test -v ./tests
releases-matrix:
name: Cross compile and release Go Binaries
runs-on: ubuntu-latest
needs: tests-matrix
strategy:
matrix:
goos: [linux, windows]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v6
- name: Auth to GCP
uses: google-github-actions/auth@v3
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v3
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Set output
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Build binary
run: |
mkdir -p dist
RELEASE_TAG="${{ steps.vars.outputs.tag }}"
BIN_NAME="silta-${{ matrix.goos }}-${{ matrix.goarch }}"
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 \
go build -ldflags "-X github.com/wunderio/silta-cli/internal/common.Version=${RELEASE_TAG} -s -w" \
-o dist/$BIN_NAME
tar -czf dist/silta-${RELEASE_TAG}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz \
-C dist $BIN_NAME --transform="s|$BIN_NAME|silta|"
- name: Upload release asset
uses: softprops/action-gh-release@v3
with:
tag_name: "${{ steps.vars.outputs.tag }}"
files: dist/silta-${{ steps.vars.outputs.tag }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to GCS
run: |
RELEASE_TAG="${{ steps.vars.outputs.tag }}"
FILE_NAME="silta-${RELEASE_TAG}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz"
gsutil cp "dist/$FILE_NAME" \
"gs://${{ secrets.GCP_BUCKET_NAME }}/releases/${RELEASE_TAG}/$FILE_NAME"
# Upload as latest version
gsutil cp "dist/$FILE_NAME" \
"gs://${{ secrets.GCP_BUCKET_NAME }}/releases/latest/silta-latest-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz"
circleci-k8s-test-build:
name: Test released CLI
runs-on: ubuntu-latest
needs: releases-matrix
strategy:
matrix:
project: [
{org: "wunderio", repo: "drupal-project-k8s", branch: "master"},
{org: "wunderio", repo: "frontend-project-k8s", branch: "master"},
{org: "wunderio", repo: "simple-project-k8s", branch: "master"}
]
steps:
- uses: actions/checkout@v6
- name: Validate released cli with ${{ matrix.project.REPO_NAME }}
run: |
REPO_NAME="${{ matrix.project.repo }}"
ORG_NAME="${{ matrix.project.org }}"
BRANCH_NAME="${{ matrix.project.branch }}"
CIRCLECI_DEV_API_TOKEN_B64=$(echo -n "${{ secrets.CIRCLECI_DEV_API_TOKEN }}:" | base64)
if [ -z "${{ secrets.CIRCLECI_DEV_API_TOKEN }}" ]; then
echo "Repository secrets is missing CIRCLECI_DEV_API_TOKEN variable."
exit 1
fi
echo "Running ${ORG_NAME}/${REPO_NAME}/${BRANCH_NAME} build on CircleCI"
echo "Project link: https://app.circleci.com/pipelines/github/${ORG_NAME}/${REPO_NAME}?branch=${BRANCH_NAME}"
# Trigger a new pipeline
PIPELINE_ID=$(curl --request POST \
--url "https://circleci.com/api/v2/project/gh/wunderio/${REPO_NAME}/pipeline" \
--header "content-type: application/json" \
--data "{\"branch\":\"${BRANCH_NAME}\"}" \
--header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.id')
echo "Pipeline ID: ${PIPELINE_ID}"
sleep 10
# Wait for pipeline to be complete
while true; do
PIPELINE_STATUS=$(curl --request GET \
--url "https://circleci.com/api/v2/pipeline/${PIPELINE_ID}/workflow" \
--header "authorization: Basic ${CIRCLECI_DEV_API_TOKEN_B64}" --silent | jq -r '.items[0].status')
if [ "${PIPELINE_STATUS}" = "success" ]; then
echo "Pipeline completed successfully"
break
elif [ "${PIPELINE_STATUS}" != "created" ] && [ "${PIPELINE_STATUS}" != "running" ]; then
echo "Pipeline status: ${PIPELINE_STATUS}, failing the test"
exit 1
fi
echo "current status: ${PIPELINE_STATUS}"
sleep 10
done