-
Notifications
You must be signed in to change notification settings - Fork 2
189 lines (159 loc) · 5.84 KB
/
cd-develop.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Develop CD
on:
pull_request:
types: [ closed ]
branches:
- develop
env:
REGISTRY: ghcr.io
IMAGE_NAME: usermaven-js-stage
DOCKERFILE_PATH: packages/javascript-sdk/docker/Dockerfile
jobs:
dev_publish:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
always-auth: true
node-version: '20'
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Ignore Workspace root check
run: npm install -g npm-cli-login
- name: add pnpm typescript
run: pnpm add typescript@latest -w
- name: Build project
run: pnpm build
- name: Generate RC version
id: rc_version
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 --match "[0-9]*.[0-9]*.[0-9]*" 2>/dev/null || echo "0.0.0")
IFS='.' read -r -a version_parts <<< "$LATEST_TAG"
MAJOR="${version_parts[0]}"
MINOR="${version_parts[1]}"
PATCH="${version_parts[2]}"
NEW_PATCH=$((PATCH + 1))
RC_VERSION="$MAJOR.$MINOR.$NEW_PATCH-rc.${{ github.run_number }}"
echo "RC_VERSION=${RC_VERSION}" >> $GITHUB_OUTPUT
- name: Set token
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NODE_AUTH_TOKEN }}" > ~/.npmrc
- name: Update package versions and dependencies
run: |
RC_VERSION="${{ steps.rc_version.outputs.RC_VERSION }}"
# First update SDK version
cd packages/javascript-sdk
npm version $RC_VERSION --no-git-tag-version
SDK_VERSION=$(node -p "require('./package.json').version")
cd ../..
# Then update other packages and their dependencies
for package in packages/*; do
if [ -d "$package" ] && [ "$package" != "packages/javascript-sdk" ]; then
echo "Processing $package"
cd $package
# Update package version
npm version $RC_VERSION --no-git-tag-version
# Update workspace dependency to specific version
if [ -f "package.json" ]; then
sed -i.bak "s|\"@usermaven/sdk-js\": \"workspace:\\*\"|\"@usermaven/sdk-js\": \"$SDK_VERSION\"|" package.json
rm package.json.bak
fi
cd ../..
fi
done
- name: Publishing RC packages
run: |
# Publish SDK first
cd packages/javascript-sdk
echo "//registry.npmjs.org/:_authToken=${{ secrets.NODE_AUTH_TOKEN }}" > .npmrc
npm publish --tag rc --access=public
cd ../..
# Wait a bit for the SDK package to be available
sleep 10
# Then publish other packages
for package in packages/*; do
if [ -d "$package" ] && [ "$package" != "packages/javascript-sdk" ]; then
cd $package
echo "Publishing $package"
echo "//registry.npmjs.org/:_authToken=${{ secrets.NODE_AUTH_TOKEN }}" > .npmrc
npm publish --tag rc --access=public
cd ../..
fi
done
- name: Deploy to BunnyCDN
uses: ayeressian/[email protected]
with:
source: "packages/javascript-sdk/dist"
destination: ""
storageZoneName: "${{ secrets.BCDN_STAGE_STORAGE_NAME }}"
storagePassword: "${{ secrets.BCDN_STAGE_STORAGE_PASSWORD }}"
accessKey: "${{ secrets.BCDN_STAGE_ACCESS_KEY }}"
pullZoneId: "${{ secrets.BCDN_STAGE_ZONE_ID }}"
upload: "true"
remove: "true"
purgePullZone: "true"
dev-publish-docker:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.PAT }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: List directory contents
run: |
echo "Root directory:"
ls -R
echo "packages/javascript-sdk directory:"
ls -R packages/javascript-sdk
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ env.DOCKERFILE_PATH }}
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
update-k8s-manifest:
needs: dev-publish-docker
runs-on: ubuntu-latest
steps:
- name: Checkout kubernetes manifests repository
uses: actions/checkout@v4
with:
repository: usermaven/kubernetes-manifests-staging
token: ${{ secrets.PAT }}
- name: Update Kubernetes deployment
run: |
sed -i 's|image: .*|image: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}|' usermaven-js/usermaven-js-deployment.yaml
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add usermaven-js/usermaven-js-deployment.yaml
git commit -m "Update image to ${{ github.sha }}"
git push