|
| 1 | +name: Build and Release Flyway OceanBase Plugin |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Release version (e.g., 10.16.1)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + tag_name: |
| 11 | + description: 'Git tag name (e.g., v10.16.1)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + release_name: |
| 15 | + description: 'Release name (optional, defaults to tag_name)' |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + release_notes: |
| 19 | + description: 'Release notes (optional)' |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + default: 'Automated release of Flyway OceanBase Plugin' |
| 23 | + create_tag: |
| 24 | + description: 'Create git tag if it does not exist' |
| 25 | + required: false |
| 26 | + type: boolean |
| 27 | + default: true |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: write # Required for creating releases and tags |
| 31 | + |
| 32 | +jobs: |
| 33 | + build-and-release: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout Code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 # Fetch all history for tags |
| 41 | + |
| 42 | + - name: Set up JDK 17 |
| 43 | + uses: actions/setup-java@v4 |
| 44 | + with: |
| 45 | + java-version: '17' |
| 46 | + distribution: 'temurin' |
| 47 | + cache: maven |
| 48 | + |
| 49 | + - name: Build Flyway Plugin |
| 50 | + run: | |
| 51 | + cd flyway-oceanbase-plugin |
| 52 | + ./mvnw clean package -DskipTests |
| 53 | +
|
| 54 | + - name: Find and verify JAR file |
| 55 | + id: find_jar |
| 56 | + run: | |
| 57 | + JAR_DIR="flyway-oceanbase-plugin/flyway-database-oceanbase/target" |
| 58 | + # Try to find JAR file with version |
| 59 | + JAR_FILE=$(find "$JAR_DIR" -name "flyway-database-oceanbase-*.jar" ! -name "*-sources.jar" ! -name "*-javadoc.jar" | head -1) |
| 60 | + |
| 61 | + if [ -z "$JAR_FILE" ] || [ ! -f "$JAR_FILE" ]; then |
| 62 | + echo "Error: JAR file not found in $JAR_DIR" |
| 63 | + ls -la "$JAR_DIR" || true |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + |
| 67 | + JAR_NAME=$(basename "$JAR_FILE") |
| 68 | + echo "JAR file found: $JAR_FILE" |
| 69 | + echo "JAR name: $JAR_NAME" |
| 70 | + ls -lh "$JAR_FILE" |
| 71 | + |
| 72 | + # Set output for later steps |
| 73 | + echo "jar_path=$JAR_FILE" >> $GITHUB_OUTPUT |
| 74 | + echo "jar_name=$JAR_NAME" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + - name: Create Git Tag (if not exists) |
| 77 | + if: inputs.create_tag == true |
| 78 | + run: | |
| 79 | + TAG_NAME="${{ inputs.tag_name }}" |
| 80 | + if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then |
| 81 | + echo "Tag $TAG_NAME already exists, skipping tag creation" |
| 82 | + else |
| 83 | + echo "Creating tag $TAG_NAME" |
| 84 | + git config user.name "github-actions[bot]" |
| 85 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 86 | + git tag -a "$TAG_NAME" -m "Release $TAG_NAME: ${{ inputs.release_notes }}" |
| 87 | + git push origin "$TAG_NAME" |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Create GitHub Release |
| 91 | + id: create_release |
| 92 | + uses: softprops/action-gh-release@v1 |
| 93 | + with: |
| 94 | + tag_name: ${{ inputs.tag_name }} |
| 95 | + name: ${{ inputs.release_name || inputs.tag_name }} |
| 96 | + body: | |
| 97 | + ## Flyway OceanBase Plugin Release ${{ inputs.tag_name }} |
| 98 | + |
| 99 | + ${{ inputs.release_notes }} |
| 100 | + |
| 101 | + ### Installation |
| 102 | + |
| 103 | + Download the JAR file and place it in your Flyway plugins directory. |
| 104 | + |
| 105 | + ### Build Information |
| 106 | + - Version: ${{ inputs.version }} |
| 107 | + - Build Date: ${{ github.run_started_at }} |
| 108 | + - Commit: ${{ github.sha }} |
| 109 | + - Workflow Run: ${{ github.run_id }} |
| 110 | + draft: false |
| 111 | + prerelease: false |
| 112 | + files: ${{ steps.find_jar.outputs.jar_path }} |
| 113 | + |
| 114 | + - name: Display Release URL |
| 115 | + run: | |
| 116 | + echo "Release created successfully!" |
| 117 | + echo "Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ inputs.tag_name }}" |
0 commit comments