-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (146 loc) · 5.82 KB
/
build-uid-apps.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
name: Build iAdapter UI apps
on:
workflow_dispatch:
inputs:
app_names:
description: "Comma-separated list of app names to build within the NX workspace"
default: "login,apps"
required: true
type: string
# push:
# branches:
# - develop
pull_request:
branches:
- develop
jobs:
build-and-zip:
runs-on: ubuntu-latest
strategy:
matrix:
# Use a specific Node.js version compatible with your NX workspace
node-version: [20.x]
env:
# Default list of apps to build for push and pull request events
DEFAULT_APP_NAMES: "login,client-management,dashboard,mapping-and-data-extraction,workflows-management"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install NX globally
run: npm install -g [email protected]
- name: Cache Node modules
uses: actions/cache@v3
with:
path: |
~/.npm
iadapter-applications/node_modules
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('iadapter-applications/package-lock.json', 'iadapter-applications/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-
- name: Install dependencies
run: npm install --legacy-peer-deps
working-directory: iadapter-applications
- name: Determine apps to build
id: determine-apps
run: |
# Use the app_names input if available, otherwise use the default value
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
app_names="${{ github.event.inputs.app_names }}"
else
app_names="${{ env.DEFAULT_APP_NAMES }}"
fi
echo "Apps to build: $app_names"
echo "app_names=$app_names" >> $GITHUB_ENV # Export as environment variable for future steps
- name: Build NX apps
run: |
# Get the comma-separated list of apps and convert to an array
echo "Raw app_names input: '${{ env.app_names }}'"
app_names="${{ env.app_names }}"
if [ -z "$app_names" ]; then
echo "The 'app_names' input is empty. Please provide a list of apps to build."
exit 1 # Exit with error status if the input is empty
fi
IFS=',' read -ra APPS <<< "$app_names"
if [ ${#APPS[@]} -eq 0 ]; then
echo "No apps specified to build. Exiting."
exit 1
fi
for app in "${APPS[@]}"; do
echo "Building $app in NX workspace..."
npx nx build "$app" --configuration production
done
if [ -d dist ]; then
echo "Successfully created 'dist' directory."
ls dist/
else
echo "Failed to create 'dist' directory."
fi
working-directory: iadapter-applications
- name: Zip build outputs
run: |
mkdir -p builds
if [ -d builds ]; then
echo "Successfully created 'builds' directory."
else
echo "Failed to create 'builds' directory."
fi
app_names="${{ env.app_names }}"
IFS=',' read -ra APPS <<< "$app_names"
for app in "${APPS[@]}"; do
build_dir="dist/apps/${app}/browser/"
zip_file="${app}.zip"
if [ -d "$build_dir" ]; then
cp -r dist/apps/${app}/browser builds/
cd builds || exit 1
mv browser "${app}"
ls
pwd
echo "Zipping $app build output..."
zip -r "$zip_file" "${app}"/*
cd ..
echo "Zipped $app build output to $zip_file"
pwd
else
echo "Build directory $build_dir not found, skipping zipping for $app."
fi
done
ls builds/ # List zipped files for debugging
working-directory: iadapter-applications
- name: Move zipped files to .github/apps-builds
run: |
mkdir -p .github/apps-builds
# Delete existing contents in .github/apps-builds to ensure a clean state
if [ -d ".github/apps-builds" ]; then
echo "Clearing existing contents in .github/apps-builds..."
rm -rf .github/apps-builds/*
ls -al .github/apps-builds/
fi
# Check if there are zip files in the builds directory
if ls iadapter-applications/builds/*.zip 1> /dev/null 2>&1; then
echo "Moving new zipped files to .github/apps-builds..."
mv iadapter-applications/builds/*.zip .github/apps-builds/
# List the contents of the .github/apps-builds directory for verification
echo "Moved zipped files to .github/apps-builds:"
ls -al .github/apps-builds/
else
echo "No zip files found in builds directory to move."
fi
- name: Commit zipped builds to repository
run: |
# Set up Git configuration for commit
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Checkout the branch to commit the changes
# ${{ github.ref_name }}
git branch -a
git checkout develop # Checkout to the current branch, replace with ${{ github.ref_name }} in future
# Add changes to the git index
git add .github/apps-builds
# Commit changes with a message
git commit -m "Update zipped builds for apps: ${{ env.app_names }}"
# Push the changes back to the repository
git push origin develop # Replace with ${{ github.ref_name }}