-
Notifications
You must be signed in to change notification settings - Fork 31
Add GitHub Actions workflow to build and deploy plugin to OMCSI #1948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
2c807c2
06dff41
b8d5e13
99dd43c
0660c24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,116 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Workflow to automatically build the Medieval-Factions plugin JAR and deploy it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # to a running omcsi (open-mc-server-infrastructure) instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ─── Setup ─────────────────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Required GitHub repository secrets: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # OMCSI_DEPLOY_URL – Base URL of your omcsi instance, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # e.g. https://mc.example.com:8092 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # OMCSI_DEPLOY_TOKEN – The value set as DEPLOY_AUTH_TOKEN in your omcsi .env | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Required GitHub repository variables: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # PLUGIN_JAR_NAME – Filename of the plugin JAR on the server, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # e.g. MedievalFactions.jar (the file that will be replaced) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Optional GitHub repository variables: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # DEPLOY_BRANCH – Branch that triggers a deployment (default: main) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ───────────────────────────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Deploy Plugin to omcsi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Trigger on pushes (branch-gated via the job condition) and on manual runs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # via the "Run workflow" button in the Actions tab. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Note: ${{ vars.* }} expressions are NOT evaluated inside the `on:` event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # filter – only inside job steps and conditions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workflow_dispatch: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build-and-deploy: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Build and Deploy Plugin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Run on manual dispatch (any branch) or when the pushed branch matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # DEPLOY_BRANCH (default: main). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == (vars.DEPLOY_BRANCH || 'main') }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Set up JDK 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/setup-java@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| distribution: temurin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| distribution: temurin | |
| distribution: zulu |
Outdated
Copilot
AI
Mar 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The find command picks the first JAR it encounters, but build/libs/ will contain both the regular JAR (medieval-factions-5.7.2.jar) and the shadow/fat JAR (medieval-factions-5.7.2-all.jar) since the shadow plugin sets archiveClassifier.set('all') in build.gradle. The order find returns files is non-deterministic, so this may deploy the regular JAR (without bundled dependencies) instead of the shadow JAR, which would fail at runtime.
You should either:
- Target the shadow JAR specifically by matching
*-all.jar(e.g.,find build/libs -name '*-all.jar' -print -quit), or - Use
./gradlew shadowJaras the build command (consistent withpublish-release.yml) and only match the shadow JAR.
| run: ./gradlew build | |
| - name: Locate built JAR | |
| id: locate-jar | |
| run: | | |
| # Use find to reliably locate the shadow JAR, excluding any | |
| # *-sources / *-javadoc JARs. | |
| JAR_FILE=$(find build/libs -maxdepth 1 -name '*.jar' \ | |
| ! -name '*-sources.jar' \ | |
| ! -name '*-javadoc.jar' \ | |
| -print -quit) | |
| if [ -z "${JAR_FILE}" ]; then | |
| echo "❌ No JAR found in build/libs/" | |
| exit 1 | |
| fi | |
| echo "jar_file=${JAR_FILE}" >> "$GITHUB_OUTPUT" | |
| echo "✅ Found JAR: ${JAR_FILE}" | |
| run: ./gradlew shadowJar | |
| - name: Locate built JAR | |
| id: locate-jar | |
| run: | | |
| # Use find to reliably locate the shadow/fat JAR (with the `-all` classifier). | |
| JAR_FILE=$(find build/libs -maxdepth 1 -name '*-all.jar' -print -quit) | |
| if [ -z "${JAR_FILE}" ]; then | |
| echo "❌ No shadow JAR (-all.jar) found in build/libs/" | |
| exit 1 | |
| fi | |
| echo "jar_file=${JAR_FILE}" >> "$GITHUB_OUTPUT" | |
| echo "✅ Found shadow JAR: ${JAR_FILE}" |
Outdated
Copilot
AI
Mar 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${{ vars.PLUGIN_JAR_NAME }} is interpolated directly into the shell script, which means if the variable contains shell metacharacters (e.g., spaces, semicolons, backticks), it could break the script or lead to injection. Consider assigning it to an environment variable using the env: block (similar to how DEPLOY_TOKEN and DEPLOY_URL are handled) instead of using direct ${{ }} interpolation in the run: block.
| run: | | |
| PLUGIN_JAR_NAME="${{ vars.PLUGIN_JAR_NAME }}" | |
| PLUGIN_JAR_NAME: ${{ vars.PLUGIN_JAR_NAME }} | |
| run: | |
Outdated
Copilot
AI
Mar 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to PLUGIN_JAR_NAME, ${{ github.ref_name }} on this line is directly interpolated into the shell script. Branch names can contain characters that are special in shell (e.g., single quotes). This is a script injection risk. Consider passing these values via the env: block and referencing them as shell variables instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
on: pushtrigger without any branch filter will cause this workflow to appear (as skipped) for every push to every branch in the repository. While theifcondition correctly gates execution, this adds noise to the Actions tab. Consider adding a branch filter that covers the expected deploy branch(es), e.g.branches: [main], and still keep theifcondition as a safeguard for the variable-based override. Alternatively, if supporting arbitraryDEPLOY_BRANCHvalues is important, the current approach is acceptable but worth documenting.