Skip to content

Commit 313adaf

Browse files
Address review feedback: workflow_dispatch, JDK 8, --batch-mode, env vars for secrets, curl error handling
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
1 parent e2fec98 commit 313adaf

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717

1818
name: Deploy Plugin to omcsi
1919

20-
# Trigger on all pushes; the job condition below restricts execution to the
21-
# configured branch. Note: ${{ vars.* }} expressions are NOT evaluated inside
22-
# the `on:` event filter – only inside job steps and conditions.
20+
# Trigger on pushes (branch-gated via the job condition) and on manual runs
21+
# via the "Run workflow" button in the Actions tab.
22+
# Note: ${{ vars.* }} expressions are NOT evaluated inside the `on:` event
23+
# filter – only inside job steps and conditions.
2324
on:
2425
push:
26+
workflow_dispatch:
2527

2628
jobs:
2729
build-and-deploy:
2830
name: Build and Deploy Plugin
29-
# Only run when the pushed branch matches DEPLOY_BRANCH (default: main)
30-
if: ${{ github.ref_name == (vars.DEPLOY_BRANCH || 'main') }}
31+
# Run on manual dispatch (any branch) or when the pushed branch matches
32+
# DEPLOY_BRANCH (default: main).
33+
if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == (vars.DEPLOY_BRANCH || 'main') }}
3134
runs-on: ubuntu-latest
3235
permissions:
3336
contents: read
@@ -36,14 +39,14 @@ jobs:
3639
- name: Checkout code
3740
uses: actions/checkout@v4
3841

39-
- name: Set up JDK 21
42+
- name: Set up JDK 8
4043
uses: actions/setup-java@v4
4144
with:
4245
distribution: temurin
43-
java-version: '21'
46+
java-version: '8'
4447

4548
- name: Build plugin JAR
46-
run: mvn package
49+
run: mvn --batch-mode package
4750

4851
- name: Locate built JAR
4952
id: locate-jar
@@ -63,29 +66,42 @@ jobs:
6366
echo "✅ Found JAR: ${JAR_FILE}"
6467
6568
- name: Deploy plugin to omcsi
69+
env:
70+
DEPLOY_TOKEN: ${{ secrets.OMCSI_DEPLOY_TOKEN }}
71+
DEPLOY_URL: ${{ secrets.OMCSI_DEPLOY_URL }}
72+
JAR_FILE: ${{ steps.locate-jar.outputs.jar_file }}
6673
run: |
6774
PLUGIN_JAR_NAME="${{ vars.PLUGIN_JAR_NAME }}"
6875
if [ -z "${PLUGIN_JAR_NAME}" ]; then
6976
echo "❌ PLUGIN_JAR_NAME variable is not set"
7077
exit 1
7178
fi
7279
73-
HTTP_STATUS=$(curl --silent --output /dev/null --write-out "%{http_code}" \
80+
RESPONSE_BODY=$(mktemp)
81+
trap 'rm -f "${RESPONSE_BODY}"' EXIT
82+
HTTP_STATUS=$(curl --silent --write-out "%{http_code}" \
83+
--output "${RESPONSE_BODY}" \
7484
--request POST \
75-
--header "Authorization: Bearer ${{ secrets.OMCSI_DEPLOY_TOKEN }}" \
85+
--header "Authorization: Bearer ${DEPLOY_TOKEN}" \
7686
--form "pluginName=${PLUGIN_JAR_NAME}" \
77-
--form "file=@${{ steps.locate-jar.outputs.jar_file }}" \
78-
"${{ secrets.OMCSI_DEPLOY_URL }}/api/plugins/deploy")
87+
--form "file=@${JAR_FILE}" \
88+
"${DEPLOY_URL}/api/plugins/deploy") || {
89+
echo "❌ curl failed – network error or invalid URL"
90+
exit 1
91+
}
7992
8093
if [ "${HTTP_STATUS}" -eq 200 ]; then
8194
echo "✅ Plugin deployed successfully (HTTP ${HTTP_STATUS})"
8295
elif [ "${HTTP_STATUS}" -eq 401 ]; then
8396
echo "❌ Authentication failed – check OMCSI_DEPLOY_TOKEN (HTTP ${HTTP_STATUS})"
97+
echo "Response body:"; cat "${RESPONSE_BODY}"
8498
exit 1
8599
elif [ "${HTTP_STATUS}" -eq 400 ]; then
86100
echo "❌ Bad request – check PLUGIN_JAR_NAME and the uploaded JAR (HTTP ${HTTP_STATUS})"
101+
echo "Response body:"; cat "${RESPONSE_BODY}"
87102
exit 1
88103
else
89104
echo "❌ Deployment failed (HTTP ${HTTP_STATUS})"
105+
echo "Response body:"; cat "${RESPONSE_BODY}"
90106
exit 1
91107
fi

0 commit comments

Comments
 (0)