-
Notifications
You must be signed in to change notification settings - Fork 9
262 lines (225 loc) · 9.64 KB
/
cfdeploy.yml
File metadata and controls
262 lines (225 loc) · 9.64 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
name: Choose and Deploy 🚀
on:
workflow_dispatch:
inputs:
workflow_choice:
description: 'Select the workflow to run'
required: true
type: choice
options:
- Deploy
- Snapshot Deploy
cf_space:
description: 'Specify the Cloud Foundry space to deploy to'
required: true
default: 'developcap'
deploy_branch:
description: 'Specify the branch to deploy from (only for Deploy workflow)'
required: false
repository_id:
description: 'Specify the Repository ID (leave blank if deploying to developcap)'
required: false
cds_services_version:
description: 'Optional override for <cds.services.version> (e.g. 4.3.1). Leave blank to use existing value.'
required: false
default: ''
permissions:
pull-requests: read
packages: read # Added permission to read packages
jobs:
Deploy:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.workflow_choice == 'Deploy' }}
steps:
- name: Checkout repository 📁
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.deploy_branch }}
- name: Set up Java 17 ☕
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Build and package 🔨
run: |
echo "🚀 Building and packaging..."
mvn clean install -P unit-tests -DskipIntegrationTests
echo "✅ Build and packaging completed successfully!"
- name: Verify and Checkout Deploy Branch 🔄
run: |
git fetch origin
echo "📂 Verifying 'local_deploy' branch..."
if git rev-parse --verify origin/local_deploy; then
git checkout local_deploy
echo "✅ Branch checked out successfully!"
else
echo "❌ Branch 'local_deploy' not found. Please verify the branch name."
exit 1
fi
- name: Set REPOSITORY_ID 🔍
id: set_repository_id
run: |
echo "🔄 Setting Repository ID..."
if [ "${{ github.event.inputs.cf_space }}" = "developcap" ]; then
echo "Using REPOSITORY_ID from secrets"
echo "::set-output name=repository_id::${{ secrets.REPOSITORY_ID }}"
else
if [ -z "${{ github.event.inputs.repository_id }}" ]; then
echo "❌ REPOSITORY_ID must be provided for non-developcap spaces"
exit 1
else
echo "Using provided REPOSITORY_ID"
echo "::set-output name=repository_id::${{ github.event.inputs.repository_id }}"
fi
fi
- name: Prepare and Deploy to Cloud Foundry ☁️
run: |
echo "🔄 Preparing to deploy..."
echo "Current Branch: 📂"
git branch
pwd
cd /home/runner/work/sdm/sdm/cap-notebook/demoapp/app
echo "Changed to app directory 📂"
pwd
echo "🔄 Installing npm dependencies..."
npm i
cd ..
echo "Changed to demoapp directory 📂"
pwd
echo "🔧 Configuring mta.yaml..."
sed -i 's|__REPOSITORY_ID__|'${{ steps.set_repository_id.outputs.repository_id }}'|g' ./mta.yaml
echo "📦 Downloading and setting up MBT..."
wget -P /tmp https://github.com/SAP/cloud-mta-build-tool/releases/download/v1.2.28/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz
tar -xvzf /tmp/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz
sudo mv mbt /usr/local/bin/
echo "🚀 Building with MBT..."
mbt build
echo "✅ Build completed!"
echo "🔧 Installing Cloud Foundry CLI..."
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo tee /etc/apt/trusted.gpg.d/cloudfoundry.asc
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
sudo apt update
sudo apt install cf-cli
cf install-plugin multiapps -f
echo "🔑 Logging into Cloud Foundry..."
cf login -a ${{ secrets.CF_API }} -u ${{ secrets.CF_USER }} -p ${{ secrets.CF_PASSWORD }} -o ${{ secrets.CF_ORG }} -s ${{ github.event.inputs.cf_space }}
echo "✅ Logged in successfully!"
echo "🚀 Running cf deploy..."
cf deploy mta_archives/demoappjava_1.0.0.mtar -f
echo "✅ Deployment complete!"
SnapshotDeploy:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.workflow_choice == 'Snapshot Deploy' }}
steps:
- name: Checkout repository 📁
uses: actions/checkout@v6
with:
ref: develop
- name: Set up Java 17 ☕
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Verify and Checkout Deploy Branch 🔄
run: |
git fetch origin
echo "📂 Verifying 'develop_deploy' branch..."
if git rev-parse --verify origin/develop_deploy; then
git checkout develop_deploy
echo "✅ Branch checked out successfully!"
else
echo "❌ Branch 'develop_deploy' not found. Please verify the branch name."
exit 1
fi
- name: Override cds.services.version (runtime only)
if: ${{ github.event.inputs.cds_services_version != '' }}
env:
TARGET_CDS_SERVICES_VERSION: ${{ github.event.inputs.cds_services_version }}
run: |
echo "Override requested: cds.services.version -> ${TARGET_CDS_SERVICES_VERSION}"
FILES=$(grep -Rl "<cds.services.version>" . | grep pom.xml || true)
if [ -z "$FILES" ]; then
echo "No pom.xml files with <cds.services.version> found" >&2; exit 1;
fi
echo "Updating files:"; echo "$FILES" | sed 's/^/ - /'
for f in $FILES; do
sed -i "s|<cds.services.version>[^<]*</cds.services.version>|<cds.services.version>${TARGET_CDS_SERVICES_VERSION}</cds.services.version>|" "$f"
done
echo "Post-update values:"; grep -R "<cds.services.version>" $FILES || true
echo "(Not committing these changes)"
shell: bash
- name: Deleting the sdm directory for fresh build ⚙️
run: |
echo "🔄 Deleting 'sdm' directory for fresh build..."
pwd
cd
rm -rf .m2/repository/com/sap/cds
echo "✅ 'sdm' directory deleted!"
- name: Set REPOSITORY_ID 🔍
id: set_repository_id
run: |
echo "🔄 Setting Repository ID..."
if [ "${{ github.event.inputs.cf_space }}" = "developcap" ]; then
echo "Using REPOSITORY_ID from secrets"
echo "::set-output name=repository_id::${{ secrets.REPOSITORY_ID }}"
else
if [ -z "${{ github.event.inputs.repository_id }}" ]; then
echo "❌ REPOSITORY_ID must be provided for non-developcap spaces"
exit 1
else
echo "Using provided REPOSITORY_ID"
echo "::set-output name=repository_id::${{ github.event.inputs.repository_id }}"
fi
fi
- name: Configure Maven for GitHub Packages 📦
run: |
echo "🔧 Configuring Maven for GitHub Packages..."
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<EOF
<settings>
<servers>
<server>
<id>github-snapshot</id>
<username>${{ github.actor }}</username>
<password>${{ secrets.GITHUB_TOKEN }}</password>
</server>
</servers>
</settings>
EOF
echo "✅ Maven configuration complete!"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare and Deploy to Cloud Foundry ☁️
run: |
echo "🔄 Preparing to deploy..."
echo "Current Branch: 📂"
git branch
pwd
cd /home/runner/work/sdm/sdm/cap-notebook/demoapp
cd app
echo "🔄 Removing node_modules for fresh install..."
rm -rf node_modules package-lock.json
echo "🔧 Installing npm dependencies..."
npm i
cd ..
echo "🔧 Configuring mta.yaml..."
sed -i 's|__REPOSITORY_ID__|'${{ steps.set_repository_id.outputs.repository_id }}'|g' ./mta.yaml
echo "📦 Downloading and setting up MBT..."
wget -P /tmp https://github.com/SAP/cloud-mta-build-tool/releases/download/v1.2.28/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz
tar -xvzf /tmp/cloud-mta-build-tool_1.2.28_Linux_amd64.tar.gz
sudo mv mbt /usr/local/bin/
echo "🚀 Building with MBT..."
mbt build
echo "✅ Build completed!"
echo "🔧 Installing Cloud Foundry CLI..."
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo tee /etc/apt/trusted.gpg.d/cloudfoundry.asc
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
sudo apt update
sudo apt install cf-cli
cf install-plugin multiapps -f
echo "🔑 Logging into Cloud Foundry..."
cf login -a ${{ secrets.CF_API }} -u ${{ secrets.CF_USER }} -p ${{ secrets.CF_PASSWORD }} -o ${{ secrets.CF_ORG }} -s ${{ github.event.inputs.cf_space }}
echo "✅ Logged in successfully!"
echo "🚀 Running cf deploy..."
cf deploy mta_archives/demoappjava_1.0.0.mtar -f
echo "✅ Deployment complete!"