-
Notifications
You must be signed in to change notification settings - Fork 5
104 lines (88 loc) · 3.18 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
name: CI
on:
workflow_dispatch:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
env:
NODE_VERSION: 20
PNPM_VERSION: 8
IMAGE_PLATFORMS: 'linux/amd64,linux/arm64'
IMAGE_REGISTRY: 'ghcr.io'
COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
BRANCH_OR_TAG: ${{ github.event.pull_request.head.ref || github.ref_name }}
jobs:
check:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install NPM dependencies
run: make install-ci
- name: Build TypeScript
run: make build-ci
- name: Run tests
run: make test-ci
- name: Format & lint
run: make lint-ci
docker:
needs: [check]
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
if: contains(env.IMAGE_PLATFORMS, ',')
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Extract metadata for Docker
id: docker-meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.IMAGE_REGISTRY }}/smartlook/relay-proxy
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Git metadata
id: git-meta
run: |
echo "BRANCH_OR_TAG_NORMALIZED_WITH_SHA=$(echo ${{ env.BRANCH_OR_TAG }} | tr '/' '-'),${{ env.COMMIT_SHA }}" >> $GITHUB_OUTPUT
- name: Build and push image to registry
uses: docker/build-push-action@v4
with:
context: .
push: true
provenance: false
build-args: |
COMMIT_SHA=${{ steps.git-meta.outputs.BRANCH_OR_TAG_NORMALIZED_WITH_SHA }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ env.IMAGE_PLATFORMS }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}