-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (114 loc) · 4.01 KB
/
Copy pathnode-api-preview.yaml
File metadata and controls
136 lines (114 loc) · 4.01 KB
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
135
136
name: node-api-preview
on:
pull_request:
types:
- opened
- synchronize
- reopened
paths:
- services/node-api/**
- .github/workflows/node-api-preview.yaml
concurrency:
group: node-api-preview-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: write
packages: write
pull-requests: read
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}/node-api
jobs:
build-preview-image:
runs-on: ubuntu-latest
steps:
- name: Checkout PR code
uses: actions/checkout@v4
- name: Set preview image tag
id: image
run: |
SHORT_SHA="${GITHUB_SHA::7}"
TAG="pr-${{ github.event.pull_request.number }}-${SHORT_SHA}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "image=${IMAGE_NAME}:${TAG}" >> "$GITHUB_OUTPUT"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
working-directory: services/node-api
run: npm ci
- name: Run tests
working-directory: services/node-api
run: npm test
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push preview image
uses: docker/build-push-action@v6
with:
context: services/node-api
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.image.outputs.image }}
- name: Checkout main for GitOps update
uses: actions/checkout@v4
with:
ref: main
- name: Generate preview application
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
PREVIEW_NAME="node-api-pr-${PR_NUMBER}"
PREVIEW_NAMESPACE="preview-node-api-pr-${PR_NUMBER}"
IMAGE_TAG="${{ steps.image.outputs.tag }}"
mkdir -p previews/node-api
{
echo "apiVersion: argoproj.io/v1alpha1"
echo "kind: Application"
echo "metadata:"
echo " name: ${PREVIEW_NAME}"
echo " namespace: argo-cd"
echo " finalizers:"
echo " - resources-finalizer.argocd.argoproj.io"
echo "spec:"
echo " project: default"
echo " source:"
echo " repoURL: https://github.com/devshinthant/internal-developer-platform.git"
echo " targetRevision: main"
echo " path: charts/node-api"
echo " helm:"
echo " values: |"
echo " image:"
echo " tag: ${IMAGE_TAG}"
echo " replicaCount: 1"
echo " destination:"
echo " server: https://kubernetes.default.svc"
echo " namespace: ${PREVIEW_NAMESPACE}"
echo " syncPolicy:"
echo " automated:"
echo " prune: true"
echo " selfHeal: true"
echo " syncOptions:"
echo " - CreateNamespace=true"
} > "previews/node-api/pr-${PR_NUMBER}.yaml"
- name: Commit preview application
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "previews/node-api/pr-${{ github.event.pull_request.number }}.yaml"
### Prevents duplicate commits
if git diff --cached --quiet; then
echo "No preview changes to commit"
exit 0
fi
git commit -m "Update node-api preview for PR #${{ github.event.pull_request.number }}"
git pull --rebase origin main
git push origin HEAD:main