-
Notifications
You must be signed in to change notification settings - Fork 21
103 lines (95 loc) · 3.61 KB
/
build-hub.yaml
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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Build Hub
on:
push:
branches:
- 'main'
tags:
- '*'
pull_request:
jobs:
build:
name: Build
timeout-minutes: 10
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Go
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version-file: 'go.mod'
check-latest: true
cache-dependency-path: |
go.sum
- name: Setup node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '22'
cache: npm
registry-url: 'https://registry.npmjs.org'
- name: Generate commit hash
id: hash
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Install frontend dependencies with npm
run: npm ci
- name: Lint with prettier
run: npm run lint
- name: Lint with golangci-lint
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
with:
version: latest
- name: Build frontend
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: npm run build:prod
- name: Build frontend and upload source maps (tag only)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
npm run build:prod -- --source-map=true || exit 1
npm run sentry-upload || exit 1
rm internal/frontend/dist/ui/browser/*.map || exit 1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
VERSION: ${{ github.ref_name }}
- name: Build application
run: go build -ldflags="$LDFLAGS" -o dist/distr ./cmd/hub/
env:
CGO_ENABLED: '0'
LDFLAGS: >-
-X github.com/glasskube/distr/internal/buildconfig.version=${{ github.ref_name }}
-X github.com/glasskube/distr/internal/buildconfig.commit=${{ steps.hash.outputs.sha_short }}
- name: Login to GitHub Container Registry (tag only)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- name: Generate Docker Metadata
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: ghcr.io/glasskube/distr
tags: |
type=ref,event=branch
type=sha,event=branch
type=semver,pattern={{version}}
labels: |
org.opencontainers.image.description=Distr Hub
org.opencontainers.image.vendor=Glasskube
- name: Docker build (push on tag only)
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
with:
platforms: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
context: .
file: Dockerfile.hub
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max