Skip to content

Commit ce130a9

Browse files
committed
ci(release): improve release workflow script and notification [need ci]
- Remove check for [skip android] flag and related conditional logic - Add check to skip DockerHub login if credentials are missing - Exit early if no changed projects detected - Only run npm version bump if bump is not "none" - Handle build failure with warning message instead of silent failure - Condition Docker build and push on DOCKERHUB_USER presence and allow failures - Simplify Android build step, remove skip android condition - Enhance Telegram notification with pipeline URL and better formatting - Replace curl JSON payload with form data for Telegram message sending - Add download artifacts button to Telegram notification - Refactor comments and improve script readability and robustness
1 parent 36c0ca5 commit ce130a9

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

.github/workflows/release.yml

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
node-version: 23.11.0
2525

26-
# 🔍 Определяем, есть ли флаг [need ci]
26+
# 🔍 Проверяем наличие [need ci]
2727
- name: Check if [need ci] present
2828
id: need_ci
2929
run: |
@@ -35,18 +35,6 @@ jobs:
3535
echo "ℹ️ No [need ci] found"
3636
fi
3737
38-
# 🔍 Проверяем, есть ли флаг [skip android]
39-
- name: Check if [skip android] present
40-
id: skip_android
41-
run: |
42-
if git log ${{ github.event.before }}..${{ github.sha }} --pretty=format:"%s%b" | grep -q "\[skip android\]"; then
43-
echo "skip_build=true" >> $GITHUB_OUTPUT
44-
echo "🚫 Found [skip android] — skipping Android build"
45-
else
46-
echo "skip_build=false" >> $GITHUB_OUTPUT
47-
echo "✅ No [skip android] found — proceeding with Android build"
48-
fi
49-
5038
# 🔍 Определяем изменённые проекты
5139
- name: Detect changed projects
5240
id: detect
@@ -59,7 +47,7 @@ jobs:
5947
echo "changed_projects=$CHANGED_PROJECTS" >> $GITHUB_OUTPUT
6048
echo "Changed projects: $CHANGED_PROJECTS"
6149
62-
# 🧩 Определяем тип версии
50+
# 🧩 Определяем тип bump'а
6351
- name: Determine bump type
6452
id: bump_type
6553
run: |
@@ -86,12 +74,17 @@ jobs:
8674
run: |
8775
sudo apt-get install -y jq
8876
npm install -g conventional-changelog-cli
89-
echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USER}" --password-stdin
77+
78+
if [ -n "${DOCKERHUB_USER}" ] && [ -n "${DOCKERHUB_TOKEN}" ]; then
79+
echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USER}" --password-stdin
80+
else
81+
echo "⚠️ DockerHub credentials missing — skipping Docker publish"
82+
fi
9083
9184
BUMP=${{ steps.bump_type.outputs.bump }}
9285
TAGS=""
9386
94-
# Если [need ci], прогоняем все проекты
87+
# Если [need ci] прогоняем все проекты
9588
if [ "${{ steps.need_ci.outputs.force_run }}" = "true" ]; then
9689
CHANGED_PROJECTS=$(find . -maxdepth 1 -type d ! -path . | while read d; do
9790
if [ -f "$d/package.json" ]; then echo "$(basename "$d")"; fi
@@ -100,40 +93,44 @@ jobs:
10093
CHANGED_PROJECTS=${{ steps.detect.outputs.changed_projects }}
10194
fi
10295
96+
if [ -z "$CHANGED_PROJECTS" ]; then
97+
echo "ℹ️ No changed projects detected. Exiting."
98+
exit 0
99+
fi
100+
103101
for project in $CHANGED_PROJECTS; do
104102
if [ -f "$project/package.json" ]; then
105103
cd $project
106104
NAME=$(jq -r '.name' package.json)
107105
DESC=$(jq -r '.description // "No description"' package.json)
108106
OLD_VERSION=$(jq -r '.version' package.json)
107+
109108
if [ "$BUMP" != "none" ]; then
110109
npm version $BUMP --no-git-tag-version
111110
fi
112-
NEW_VERSION=$(jq -r '.version' package.json)
113111
114-
conventional-changelog -p angular -i CHANGELOG.md -s -r 1 || echo "No changelog generated"
112+
NEW_VERSION=$(jq -r '.version' package.json)
113+
conventional-changelog -p angular -i CHANGELOG.md -s -r 1 || true
115114
116115
if jq -e '.scripts.build' package.json >/dev/null; then
117116
npm ci
118-
npm run build || echo "Build failed"
117+
npm run build || echo "⚠️ Build failed for $project"
119118
fi
120119
121-
if [ -f "Dockerfile" ]; then
120+
if [ -f "Dockerfile" ] && [ -n "${DOCKERHUB_USER}" ]; then
122121
IMAGE_NAME="${DOCKERHUB_USER}/${NAME}"
123122
docker build -t "$IMAGE_NAME:$NEW_VERSION" -t "$IMAGE_NAME:latest" \
124123
--label "org.opencontainers.image.title=$NAME" \
125124
--label "org.opencontainers.image.description=$DESC" \
126125
--label "org.opencontainers.image.version=$NEW_VERSION" \
127126
--label "org.opencontainers.image.source=https://github.com/${{ github.repository }}" \
128-
.
129-
docker push "$IMAGE_NAME:$NEW_VERSION"
130-
docker push "$IMAGE_NAME:latest"
127+
. || true
128+
docker push "$IMAGE_NAME:$NEW_VERSION" || true
129+
docker push "$IMAGE_NAME:latest" || true
131130
fi
132131
133-
# Skip Android build if [skip android] flag is present
134-
if [ -f "capacitor.config.ts" ] && [ "${{ steps.skip_android.outputs.skip_build }}" = "false" ]; then
132+
if [ -f "capacitor.config.ts" ]; then
135133
echo "${{ secrets.KEYSTORE }}" | base64 --decode > "${{ github.workspace }}/$project/my-dashboard.jks"
136-
ls "${{ github.workspace }}/$project"
137134
138135
docker run --rm \
139136
-e KEYSTORE_PASSWORD="${{ secrets.KEYSTORE_PASSWORD }}" \
@@ -143,11 +140,8 @@ jobs:
143140
-v "${{ github.workspace }}/$project:/app" \
144141
endykaufman/ionic-capacitor:latest
145142
146-
ls -la ${{ github.workspace }}/$project/android/app/build/outputs/apk/release/
147143
mkdir -p ${{ github.workspace }}/$project/artifacts
148144
cp -R ${{ github.workspace }}/$project/android/app/build/outputs/apk/release/* ${{ github.workspace }}/$project/artifacts/
149-
elif [ -f "capacitor.config.ts" ] && [ "${{ steps.skip_android.outputs.skip_build }}" = "true" ]; then
150-
echo "⏭️ Skipping Android build for $project due to [skip android] flag"
151145
fi
152146
153147
cd -
@@ -156,6 +150,7 @@ jobs:
156150
git tag "$TAG"
157151
fi
158152
done
153+
159154
echo "tags=$TAGS" >> $GITHUB_OUTPUT
160155
161156
# 💾 Commit and push changes
@@ -212,11 +207,14 @@ jobs:
212207
213208
RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/${TAG}"
214209
PROJECT_URL="https://github.com/${{ github.repository }}/tree/main/${PROJECT}"
210+
PIPELINE_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
211+
212+
NOTES="📢 *${NAME} v${VERSION} released!*%0A%0A_${DESC}_%0A%0A"
215213
216-
NOTES="📢 *${NAME} v${VERSION} released!*\n\n_${DESC}_\n\n"
217214
if [ -f "$CHANGELOG_PATH" ]; then
218215
BODY=$(awk '/^##/{i++}i==1' "$CHANGELOG_PATH" | head -n 20)
219-
NOTES+="*Changelog:*\n\`\`\`\n$BODY\n\`\`\`\n"
216+
BODY_ESCAPED=$(echo "$BODY" | sed ':a;N;$!ba;s/\n/%0A/g')
217+
NOTES+="*Changelog:*%0A$BODY_ESCAPED%0A%0A"
220218
fi
221219
222220
if [ -d "$ARTIFACTS_PATH" ]; then
@@ -228,6 +226,7 @@ jobs:
228226
229227
if [ "$SKIP_TELEGRAM" -eq 0 ]; then
230228
BUTTONS="["
229+
BUTTONS="${BUTTONS}[{\"text\":\"💾 Download all artifacts\",\"url\":\"${PIPELINE_URL}\"}],"
231230
if [ -f "$PROJECT/Dockerfile" ]; then
232231
BUTTONS="${BUTTONS}[{\"text\":\"🐳 Docker image\",\"url\":\"https://hub.docker.com/r/${DOCKERHUB_USER}/${NAME}\"}],"
233232
fi
@@ -237,12 +236,10 @@ jobs:
237236
BUTTONS=$(echo "$BUTTONS" | sed 's/,]/]/')
238237
239238
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
240-
-H "Content-Type: application/json" \
241-
-d "{
242-
\"chat_id\": \"${TELEGRAM_CHAT_ID}\",
243-
\"parse_mode\": \"Markdown\",
244-
\"text\": \"${NOTES}\",
245-
\"reply_markup\": {\"inline_keyboard\": ${BUTTONS}}
246-
}" >/dev/null 2>&1
239+
-d "chat_id=${TELEGRAM_CHAT_ID}" \
240+
-d "parse_mode=Markdown" \
241+
-d "disable_web_page_preview=true" \
242+
-d "text=${NOTES}" \
243+
-d "reply_markup={\"inline_keyboard\":${BUTTONS}}" >/dev/null 2>&1
247244
fi
248-
done
245+
done

0 commit comments

Comments
 (0)