-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (108 loc) · 5.16 KB
/
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
# name: CI
# on:
# push:
# branches:
# - main
# pull_request:
# env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}
# permissions:
# actions: read
# contents: read
# packages: write
# jobs:
# docker_build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0
# # Connect your workspace on nx.app and uncomment this to enable task distribution.
# # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested
# # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci"
# # Cache node_modules
# - uses: actions/setup-node@v3
# with:
# node-version: 20
# cache: 'npm'
# - run: npm ci
# - uses: nrwl/nx-set-shas@v4
# # TODO: check why failed
# # - run: npx nx-cloud record -- nx format:check
# # - run: npx nx affected -t lint test build e2e-ci
# - run: npm run build:backend
# - name: Get version from package.json
# id: package_version
# run: echo "version=v$(jq -r .version package.json)" >> $GITHUB_OUTPUT
# - name: Login to GHCR
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v2
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Docker meta
# id: meta
# uses: docker/metadata-action@v4
# with:
# # generate Docker tags based on the following events/attributes
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# tags: |
# type=ref,event=branch
# type=semver,pattern={{version}},value=${{ steps.package_version.outputs.version }}
# type=semver,pattern={{major}}.{{minor}},value=${{ steps.package_version.outputs.version }}
# type=semver,pattern={{major}},value=${{ steps.package_version.outputs.version }}
# type=sha
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Build, cache and push docker image
# uses: docker/build-push-action@v3
# with:
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
# deploy_do:
# needs: docker_build
# runs-on: ubuntu-latest
# strategy:
# matrix:
# namespace: ['production', 'develop']
# permissions:
# # The "id-token: write" permission is required or Machine ID will not be able to authenticate with the cluster.
# id-token: write
# contents: read
# steps:
# - uses: actions/checkout@v3
# - name: Set environment variables
# run: |
# # Short name for current branch. For PRs, use target branch (base ref)
# GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
# GIT_BRANCH=${GIT_BRANCH//\//-} # Replace / with -
# GIT_BRANCH=${GIT_BRANCH//_/-} # Replace _ with -
# GIT_BRANCH=${GIT_BRANCH,,} # Lower case
# HELM_SHORT=`echo "${{ github.event.repository.name }}" | cut -c -52`
# echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV
# echo "HELM_SHORT=$HELM_SHORT" >> $GITHUB_ENV
# - name: Install doctl and Authorize to Digital Ocean
# uses: digitalocean/action-doctl@v2
# with:
# token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
# - name: Login to registry
# run: doctl registry login --expiry-seconds 3600
# - name: Save DigitalOcean kubeconfig with short-lived credentials
# run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.DIGITALOCEAN_K8S_CLUSTER_ID }}
# - name: Docker Image Tag
# id: meta
# uses: docker/metadata-action@v4
# with:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# tags: |
# type=sha
# - name: Deploy
# if: github.ref == 'refs/heads/main' || matrix.namespace != 'production'
# run: |
# helm upgrade --install $HELM_SHORT ./.helm --namespace ${{ matrix.namespace }} --set image=${{ steps.meta.outputs.tags }} --set branch=$GIT_BRANCH --dry-run
# helm upgrade --install $HELM_SHORT ./.helm --namespace ${{ matrix.namespace }} --set image=${{ steps.meta.outputs.tags }} --set branch=$GIT_BRANCH --wait