-
Notifications
You must be signed in to change notification settings - Fork 2
131 lines (131 loc) · 4.78 KB
/
ci.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
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
name: ci
# Trigger on push to main branch and any pull requests to main branch
on:
push:
branches:
- main
tags:
# Match semantic version tags:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#patterns-to-match-branches-and-tags
- v[0-9]+.[0-9]+.[0-9]+
pull_request:
branches:
- main
# https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#comments-and-annotations
permissions:
contents: read
pull-requests: read
checks: write
jobs:
# https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#how-to-use
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.23.4'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
args: --timeout=10m
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.23.4'
- run: go mod download
- name: Verify generated code
run: make verify
- name: Run unit tests
run: make test
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Build without pushing to first validate that the image works as expected:
# https://docs.docker.com/build/ci/github-actions/test-before-push/
- name: Build Docker image
uses: docker/build-push-action@v5
id: docker-build
with:
context: .
platforms: linux/amd64
tags: docker.io/dippynark/cost-manager:test
cache-from: type=gha
cache-to: type=gha,mode=max
# Export to Docker so we can load into kind cluster:
# https://docs.docker.com/build/ci/github-actions/export-docker/
load: true
- name: Setup Helm
uses: azure/setup-helm@v4
with:
version: v3.16.4
- name: Helm lint
run: helm lint --strict ./charts/cost-manager
- name: Install kind
uses: helm/kind-action@v1
with:
install_only: true
- name: Run E2E tests
run: make e2e IMAGE=${{ fromJSON(steps.docker-build.outputs.metadata)['image.name'] }}
release:
# Make sure the tests have passed before releasing
needs:
- lint
- test
runs-on: ubuntu-latest
# Do not release for forked repositories since secrets are not available:
# https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
if: ${{ ! github.event.pull_request.head.repo.fork }}
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
id: docker-login
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# https://github.com/docker/metadata-action#basic
- name: Docker meta
uses: docker/metadata-action@v5
id: meta
with:
images: docker.io/dippynark/cost-manager
# Do not handle the latest tag by default. In particular this prevents the latest tag being
# pushed when the repository is tagged with a semantic version:
# https://github.com/docker/metadata-action#flavor-input
flavor: latest=false
tags: |
# Push semantic version tags: https://github.com/docker/metadata-action#typesemver
type=semver,pattern={{raw}}
# To make sure that we cannot accidentally push a semantic version tag from a pull request
# we only generate tags from the pull request number:
# https://github.com/docker/metadata-action#typeref
type=ref,event=pr
# Set the latest tag for the main branch:
# https://github.com/docker/metadata-action#latest-tag
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
# Buildx does not currently support pushing a previously built image so we rebuild from cache:
# https://github.com/docker/buildx/issues/1915
- name: Push Docker image
uses: docker/build-push-action@v5
with:
context: .
# We do not build the ARM64 image for pull requests since it takes a very long time:
# https://github.com/docker/setup-qemu-action/issues/22
# https://github.com/DSpace/DSpace/pull/8315
platforms: linux/amd64${{ github.event_name != 'pull_request' && ',linux/arm64' || '' }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
push: true