|
| 1 | +name: Test Git Worktree Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + branch: |
| 7 | + description: 'Branch to test' |
| 8 | + required: false |
| 9 | + default: 'develop' |
| 10 | + |
| 11 | +jobs: |
| 12 | + test-worktree: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + ref: ${{ github.event.inputs.branch }} |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Set up JDK 11 |
| 22 | + uses: actions/setup-java@v4 |
| 23 | + with: |
| 24 | + java-version: "11" |
| 25 | + distribution: "adopt" |
| 26 | + cache: maven |
| 27 | + |
| 28 | + - name: Create git worktree |
| 29 | + run: git worktree add --detach ../obp-api-worktree HEAD |
| 30 | + |
| 31 | + - name: Build from worktree |
| 32 | + working-directory: ../obp-api-worktree |
| 33 | + run: | |
| 34 | + set -o pipefail |
| 35 | + MAVEN_OPTS="-Xmx3G -Xss2m -XX:MaxMetaspaceSize=1G" mvn clean package -DskipTests 2>&1 | tee "$GITHUB_WORKSPACE/worktree-build.log" |
| 36 | +
|
| 37 | + - name: Verify git.properties was generated |
| 38 | + run: | |
| 39 | + PROPS_FILE="../obp-api-worktree/obp-api/target/classes/git.properties" |
| 40 | + if [ ! -f "$PROPS_FILE" ]; then |
| 41 | + echo "FAIL: git.properties not found" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + echo "Contents of git.properties:" |
| 45 | + cat "$PROPS_FILE" |
| 46 | +
|
| 47 | + check_field() { |
| 48 | + local field=$1 |
| 49 | + local value |
| 50 | + value=$(grep "^${field}=" "$PROPS_FILE" | cut -d'=' -f2-) |
| 51 | + if [ -z "$value" ]; then |
| 52 | + echo "FAIL: $field is empty or missing" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + echo "OK: $field=$value" |
| 56 | + } |
| 57 | +
|
| 58 | + check_field "git.commit.id" |
| 59 | + check_field "git.branch" |
| 60 | + check_field "git.build.time" |
| 61 | +
|
| 62 | + - name: Upload build log |
| 63 | + if: always() |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: worktree-build-log |
| 67 | + if-no-files-found: ignore |
| 68 | + path: worktree-build.log |
| 69 | + |
| 70 | + - name: Clean up worktree |
| 71 | + if: always() |
| 72 | + run: git worktree remove ../obp-api-worktree --force || true |
0 commit comments