-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (114 loc) · 4.08 KB
/
services-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
name: services - CI
on:
pull_request:
branches:
- main
paths:
- services/**
env:
REGISTRY: ${{ vars.REGISTRY || 'ghcr.io' }}
TARGET_PLATFORMS: linux/amd64
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
changed:
name: Prepare
uses: ./.github/workflows/changes.yml
with:
path: services
dir_names_max_depth: 2
build-and-test:
name: Build-Test (${{ matrix.service-path }})
needs: [changed]
runs-on: ubuntu-latest
if: needs.changed.outputs.any_changed == 'true'
strategy:
matrix:
go-version: ['1.21.x']
service-path: ${{ fromJSON(needs.changed.outputs.matrix) }}
env:
GOPRIVATE: github.com/home-cloud-io/core
steps:
- uses: actions/checkout@v4
- name: Git config
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
run: |
git config --global url."https://${GH_ACCESS_TOKEN}:[email protected]/".insteadOf "https://github.com/"
- name: Check for web client
uses: andstor/file-existence-action@v3
id: check_files
with:
files: "services/${{ matrix.service-path }}/web-client/package-lock.json"
- uses: actions/setup-node@v4
if: steps.check_files.outputs.files_exists == 'true'
with:
node-version: 18
cache-dependency-path: services/${{ matrix.service-path }}/web-client/package-lock.json
- name: Install Node dependencies
if: steps.check_files.outputs.files_exists == 'true'
run: |
cd services/${{ matrix.service-path }}/web-client &&
npm i -D @swc/cli @swc/core &&
npm install
- name: Build web-client
if: steps.check_files.outputs.files_exists == 'true'
run: |
cd services/${{ matrix.service-path }}/web-client &&
npm run build
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: services/${{ matrix.service-path }}/go.sum
- name: Test
working-directory: services/${{ matrix.service-path }}
run: go test ./...
- name: Build
working-directory: services/${{ matrix.service-path }}
run: go build main.go
docker-image:
name: Docker Image (${{ matrix.service-path }})
needs: [changed]
runs-on: ubuntu-latest
if: needs.changed.outputs.any_changed == 'true'
strategy:
matrix:
service-path: ${{ fromJSON(needs.changed.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Extract service info
id: info
run: |
echo "domain=$(dirname ${{ matrix.service-path }})" >> $GITHUB_OUTPUT
echo "service=$(basename ${{ matrix.service-path }})" >> $GITHUB_OUTPUT
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME || (env.REGISTRY == 'ghcr.io' && github.actor) }}
password: ${{ secrets.DOCKER_PASSWORD || (env.REGISTRY == 'ghcr.io' && secrets.GITHUB_TOKEN) }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}-${{ steps.info.outputs.domain}}-${{ steps.info.outputs.service }}
tags: |
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.TARGET_PLATFORMS }}
build-args: |
DOMAIN=${{ steps.info.outputs.domain}}
SERVICE=${{ steps.info.outputs.service}}
GITHUB_TOKEN=${{ secrets.GH_ACCESS_TOKEN }}