feat: publish to Modtale (#1) #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This file should be placed in: nitrado/hytale-plugin-workflows/.github/workflows/plugin-ci.yml | ||
|
Check failure on line 1 in .github/workflows/plugin-ci.yml
|
||
| # Then delete this file from this repository. | ||
| name: Plugin CI (Reusable) | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| java-version: | ||
| description: "Java version for building" | ||
| type: string | ||
| default: "25" | ||
| java-version-publish: | ||
| description: "Java version for Maven publishing" | ||
| type: string | ||
| default: "25" | ||
| artifact-retention-days: | ||
| description: "Number of days to retain build artifacts" | ||
| type: number | ||
| default: 7 | ||
| manifest-path: | ||
| description: "Path to manifest.json file" | ||
| type: string | ||
| default: "src/main/resources/manifest.json" | ||
| secrets: | ||
| MAVEN_REPO_URL: | ||
| description: "Maven repository URL for dependencies" | ||
| required: false | ||
| MAVEN_USERNAME: | ||
| description: "Maven repository username" | ||
| required: false | ||
| MAVEN_PASSWORD: | ||
| description: "Maven repository password" | ||
| required: false | ||
| MAVEN_PUBLISH_URL: | ||
| description: "Maven repository URL for publishing" | ||
| required: false | ||
| MAVEN_PUBLISH_USERNAME: | ||
| description: "Maven publish username" | ||
| required: false | ||
| MAVEN_PUBLISH_PASSWORD: | ||
| description: "Maven publish password" | ||
| required: false | ||
| GCP_CREDENTIALS: | ||
| description: "GCP credentials JSON" | ||
| required: false | ||
| GCS_BUCKET: | ||
| description: "GCS bucket for artifact upload" | ||
| required: false | ||
| MODTALE_API_KEY: | ||
| description: "Modtale API key for authentication" | ||
| required: false | ||
| MODTALE_PROJECT_ID: | ||
| description: "Modtale project ID" | ||
| required: false | ||
| outputs: | ||
| version: | ||
| description: "The resolved version" | ||
| value: ${{ jobs.build.outputs.version }} | ||
| artifact_id: | ||
| description: "The Maven artifact ID" | ||
| value: ${{ jobs.build.outputs.artifact_id }} | ||
| is_release: | ||
| description: "Whether this is a release build" | ||
| value: ${{ jobs.build.outputs.is_release }} | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.version.outputs.version }} | ||
| tag_name: ${{ steps.version.outputs.tag_name }} | ||
| is_release: ${{ steps.version.outputs.is_release }} | ||
| is_prerelease: ${{ steps.version.outputs.is_prerelease }} | ||
| artifact_id: ${{ steps.artifact.outputs.artifact_id }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| - name: Determine version | ||
| id: version | ||
| run: | | ||
| # Semver regex with required leading v | ||
| SEMVER_REGEX='^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$' | ||
| if [[ "$GITHUB_REF" == refs/tags/* ]]; then | ||
| TAG_NAME="${GITHUB_REF#refs/tags/}" | ||
| if [[ "$TAG_NAME" =~ $SEMVER_REGEX ]]; then | ||
| # Strip leading 'v' for maven/jar version | ||
| VERSION="${TAG_NAME#v}" | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT | ||
| echo "is_release=true" >> $GITHUB_OUTPUT | ||
| # Check for prerelease suffix (e.g., -rc1, -alpha1, -beta2) | ||
| if [[ "$VERSION" == *-* ]]; then | ||
| echo "is_prerelease=true" >> $GITHUB_OUTPUT | ||
| echo "Detected semver prerelease tag: $TAG_NAME (version: $VERSION)" | ||
| else | ||
| echo "is_prerelease=false" >> $GITHUB_OUTPUT | ||
| echo "Detected semver release tag: $TAG_NAME (version: $VERSION)" | ||
| fi | ||
| else | ||
| echo "Tag '$TAG_NAME' does not match required format (vX.Y.Z), using snapshot version" | ||
| COMMIT_HASH=$(git rev-parse --short HEAD) | ||
| echo "version=0.0.0-${COMMIT_HASH}" >> $GITHUB_OUTPUT | ||
| echo "is_release=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| else | ||
| COMMIT_HASH=$(git rev-parse --short HEAD) | ||
| echo "version=0.0.0-${COMMIT_HASH}" >> $GITHUB_OUTPUT | ||
| echo "is_release=false" >> $GITHUB_OUTPUT | ||
| echo "No tag detected, using snapshot version" | ||
| fi | ||
| - name: Set up Java | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: temurin | ||
| java-version: ${{ inputs.java-version }} | ||
| cache: maven | ||
| - name: Determine artifact ID | ||
| id: artifact | ||
| run: | | ||
| ARTIFACT_ID=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout) | ||
| echo "artifact_id=$ARTIFACT_ID" >> $GITHUB_OUTPUT | ||
| echo "Detected artifact ID: $ARTIFACT_ID" | ||
| - name: Set up Maven settings.xml with additional repository | ||
| env: | ||
| MAVEN_REPO_URL: ${{ secrets.MAVEN_REPO_URL }} | ||
| MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} | ||
| MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} | ||
| if: ${{ env.MAVEN_REPO_URL && env.MAVEN_USERNAME && env.MAVEN_PASSWORD }} | ||
| run: | | ||
| mkdir -p $HOME/.m2 | ||
| echo "<settings> | ||
| <servers> | ||
| <server> | ||
| <id>custom-repo</id> | ||
| <username>$MAVEN_USERNAME</username> | ||
| <password>$MAVEN_PASSWORD</password> | ||
| </server> | ||
| </servers> | ||
| <profiles> | ||
| <profile> | ||
| <id>additional-repo</id> | ||
| <repositories> | ||
| <repository> | ||
| <id>custom-repo</id> | ||
| <url>$MAVEN_REPO_URL</url> | ||
| </repository> | ||
| </repositories> | ||
| </profile> | ||
| </profiles> | ||
| <activeProfiles> | ||
| <activeProfile>additional-repo</activeProfile> | ||
| </activeProfiles> | ||
| </settings>" > $HOME/.m2/settings.xml | ||
| - name: Update manifest version for release | ||
| if: ${{ steps.version.outputs.is_release == 'true' }} | ||
| run: | | ||
| VERSION="${{ steps.version.outputs.version }}" | ||
| sed -i "s/\"Version\": \"[^\"]*\"/\"Version\": \"$VERSION\"/" ${{ inputs.manifest-path }} | ||
| echo "Updated manifest.json to version $VERSION" | ||
| cat ${{ inputs.manifest-path }} | ||
| - name: Build (clean package) | ||
| run: > | ||
| mvn -B -V | ||
| clean | ||
| package | ||
| -Drevision=${{ steps.version.outputs.version }} | ||
| - name: Upload Build Artifacts | ||
| if: ${{ success() }} | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: build-artifacts | ||
| path: | | ||
| target/${{ steps.artifact.outputs.artifact_id }}-*.jar | ||
| !target/original-*.jar | ||
| retention-days: ${{ inputs.artifact-retention-days }} | ||
| publish: | ||
| needs: [build] | ||
| if: ${{ needs.build.outputs.is_release == 'true' && needs.build.result == 'success' }} | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| HAVE_GCP: ${{ secrets.GCP_CREDENTIALS != '' }} | ||
| HAVE_GCS_BUCKET: ${{ secrets.GCS_BUCKET != '' }} | ||
| steps: | ||
| - name: Download Build Artifacts | ||
| uses: actions/download-artifact@v7 | ||
| with: | ||
| name: build-artifacts | ||
| - name: Generate release archive | ||
| if: ${{ success() }} | ||
| run: | | ||
| ls -la | ||
| mkdir dist | ||
| mv ${{ needs.build.outputs.artifact_id }}-*.jar dist/ | ||
| cd dist | ||
| zip -r ../${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.version }}.zip . | ||
| - name: Create GitHub Release | ||
| if: ${{ success() }} | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ needs.build.outputs.tag_name }} | ||
| name: Release ${{ needs.build.outputs.version }} | ||
| prerelease: ${{ needs.build.outputs.is_prerelease == 'true' }} | ||
| files: | | ||
| ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.version }}.zip | ||
| dist/${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.version }}.jar | ||
| generate_release_notes: true | ||
| - name: Log in to Google Cloud | ||
| if: ${{ success() && env.HAVE_GCP == 'true' }} | ||
| uses: google-github-actions/auth@v3 | ||
| with: | ||
| credentials_json: ${{ secrets.GCP_CREDENTIALS }} | ||
| - name: Upload to Google Cloud Storage | ||
| if: ${{ success() && env.HAVE_GCP == 'true' && env.HAVE_GCS_BUCKET == 'true' }} | ||
| uses: google-github-actions/upload-cloud-storage@v3 | ||
| with: | ||
| path: ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.version }}.zip | ||
| destination: ${{ secrets.GCS_BUCKET }} | ||
| publish-maven: | ||
| needs: [build] | ||
| if: ${{ needs.build.outputs.is_release == 'true' && needs.build.result == 'success' }} | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| HAVE_MAVEN_PUBLISH: ${{ secrets.MAVEN_PUBLISH_URL != '' && secrets.MAVEN_PUBLISH_USERNAME != '' && secrets.MAVEN_PUBLISH_PASSWORD != '' }} | ||
| HAVE_MAVEN_REPO: ${{ secrets.MAVEN_REPO_URL != '' && secrets.MAVEN_USERNAME != '' && secrets.MAVEN_PASSWORD != '' }} | ||
| steps: | ||
| - name: Checkout | ||
| if: ${{ env.HAVE_MAVEN_PUBLISH == 'true' }} | ||
| uses: actions/checkout@v6 | ||
| - name: Set up Java | ||
| if: ${{ env.HAVE_MAVEN_PUBLISH == 'true' }} | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: temurin | ||
| java-version: ${{ inputs.java-version-publish }} | ||
| cache: maven | ||
| - name: Set up Maven settings.xml for publishing | ||
| if: ${{ env.HAVE_MAVEN_PUBLISH == 'true' }} | ||
| env: | ||
| MAVEN_REPO_URL: ${{ secrets.MAVEN_REPO_URL }} | ||
| MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} | ||
| MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} | ||
| run: | | ||
| mkdir -p $HOME/.m2 | ||
| # Build servers section | ||
| SERVERS="<server> | ||
| <id>publish-repo</id> | ||
| <username>${{ secrets.MAVEN_PUBLISH_USERNAME }}</username> | ||
| <password>${{ secrets.MAVEN_PUBLISH_PASSWORD }}</password> | ||
| </server>" | ||
| PROFILES="" | ||
| ACTIVE_PROFILES="" | ||
| # Add custom repo for dependencies if configured | ||
| if [[ -n "$MAVEN_REPO_URL" && -n "$MAVEN_USERNAME" && -n "$MAVEN_PASSWORD" ]]; then | ||
| SERVERS="$SERVERS | ||
| <server> | ||
| <id>custom-repo</id> | ||
| <username>$MAVEN_USERNAME</username> | ||
| <password>$MAVEN_PASSWORD</password> | ||
| </server>" | ||
| PROFILES="<profiles> | ||
| <profile> | ||
| <id>additional-repo</id> | ||
| <repositories> | ||
| <repository> | ||
| <id>custom-repo</id> | ||
| <url>$MAVEN_REPO_URL</url> | ||
| </repository> | ||
| </repositories> | ||
| </profile> | ||
| </profiles>" | ||
| ACTIVE_PROFILES="<activeProfiles> | ||
| <activeProfile>additional-repo</activeProfile> | ||
| </activeProfiles>" | ||
| fi | ||
| cat > $HOME/.m2/settings.xml << EOF | ||
| <settings> | ||
| <servers> | ||
| $SERVERS | ||
| </servers> | ||
| $PROFILES | ||
| $ACTIVE_PROFILES | ||
| </settings> | ||
| EOF | ||
| - name: Deploy to Maven repository | ||
| if: ${{ env.HAVE_MAVEN_PUBLISH == 'true' }} | ||
| run: > | ||
| mvn -B -V | ||
| clean | ||
| deploy | ||
| -Drevision=${{ needs.build.outputs.version }} | ||
| -DaltDeploymentRepository=publish-repo::${{ secrets.MAVEN_PUBLISH_URL }} | ||
| -DskipTests | ||
| fetch-release-notes: | ||
| needs: [build, publish] | ||
| if: ${{ needs.build.outputs.is_release == 'true' && needs.build.result == 'success' && needs.publish.result == 'success' }} | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| changelog: ${{ steps.get-notes.outputs.changelog }} | ||
| steps: | ||
| - name: Fetch GitHub Release Notes | ||
| id: get-notes | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| TAG_NAME="${{ needs.build.outputs.tag_name }}" | ||
| echo "Fetching release notes for tag: $TAG_NAME" | ||
| RELEASE_BODY=$(gh api repos/${{ github.repository }}/releases/tags/$TAG_NAME --jq '.body // empty' 2>/dev/null || echo "") | ||
| if [[ -n "$RELEASE_BODY" ]]; then | ||
| echo "Found GitHub release notes" | ||
| # Use EOF delimiter to handle multi-line output | ||
| { | ||
| echo 'changelog<<EOF' | ||
| echo "$RELEASE_BODY" | ||
| echo 'EOF' | ||
| } >> $GITHUB_OUTPUT | ||
| else | ||
| echo "No GitHub release notes found, using default" | ||
| echo "changelog=Automated Build & Release from GitHub" >> $GITHUB_OUTPUT | ||
| fi | ||
| publish-modtale: | ||
| needs: [build, publish, fetch-release-notes] | ||
| if: ${{ needs.build.outputs.is_release == 'true' && secrets.MODTALE_API_KEY != '' && secrets.MODTALE_PROJECT_ID != '' }} | ||
| uses: ./.github/workflows/modtale-publish.yml | ||
| with: | ||
| artifact-id: ${{ needs.build.outputs.artifact_id }} | ||
| version: ${{ needs.build.outputs.version }} | ||
| channel: ${{ (needs.build.outputs.is_prerelease == 'true') && 'BETA' || 'RELEASE' }} | ||
| changelog: ${{ needs.fetch-release-notes.outputs.changelog }} | ||
| secrets: | ||
| MODTALE_API_KEY: ${{ secrets.MODTALE_API_KEY }} | ||
| MODTALE_PROJECT_ID: ${{ secrets.MODTALE_PROJECT_ID }} | ||