|
| 1 | +# Deploy Workflow |
| 2 | + |
| 3 | +A reusable GitHub Actions workflow for building and deploying Spring Cloud projects. It uses centralized configuration to determine which branches and JDK versions to build, then runs Maven with the appropriate profiles for each matrix combination. |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +The workflow is designed to be called from Spring Cloud project repositories via `workflow_call`. It: |
| 8 | + |
| 9 | +- **Determines the build matrix** using the [determine-matrix](../actions/determine-matrix/README.md) action and [`config/projects.json`](../../config/projects.json), supporting both OSS and commercial repository variants |
| 10 | +- **Builds each branch × JDK combination** in parallel with a matrix strategy |
| 11 | +- **Deploys artifacts and docs** only for designated JDK versions (e.g., JDK 8 when present, otherwise JDK 17), while other JDK versions run `install` only |
| 12 | +- **Supports custom build commands** so callers can override the default Maven behavior |
| 13 | + |
| 14 | +The workflow configures Maven settings for Artifactory (OSS and optional commercial), checks out the correct branch, sets up the JDK, and runs either the default Maven deploy/install or a custom command. |
| 15 | + |
| 16 | +## Requirements |
| 17 | + |
| 18 | +- The calling repository must use Maven with a `mvnw` wrapper |
| 19 | +- Required secrets must be configured in the calling repository (or passed from the caller) |
| 20 | + |
| 21 | +## Inputs |
| 22 | + |
| 23 | +| Input | Description | Required | Type | |
| 24 | +|-------|-------------|----------|------| |
| 25 | +| `branches` | Branch(es) to build — single branch or comma-separated list (e.g. `main,3.3.x,3.2.x`). Empty uses ref or scheduled config. | No | string | |
| 26 | +| `custom_build_command` | Custom run command for the build step (overrides default Maven command). Supports multi-line. | No | string | |
| 27 | +| `runs_on` | Runner to use for the build job. | No | string (default: `ubuntu-latest`) | |
| 28 | + |
| 29 | +## Secrets |
| 30 | + |
| 31 | +| Secret | Description | Required | |
| 32 | +|--------|-------------|----------| |
| 33 | +| `ARTIFACTORY_USERNAME` | Username for OSS Artifactory (repo.spring.io) | Yes | |
| 34 | +| `ARTIFACTORY_PASSWORD` | Password for OSS Artifactory | Yes | |
| 35 | +| `COMMERCIAL_ARTIFACTORY_USERNAME` | Username for commercial Artifactory | No (required for *-commercial repos) | |
| 36 | +| `COMMERCIAL_ARTIFACTORY_PASSWORD` | Password for commercial Artifactory | No (required for *-commercial repos) | |
| 37 | +| `DOCKERHUB_USERNAME` | Docker Hub username | Yes | |
| 38 | +| `DOCKERHUB_TOKEN` | Docker Hub token | Yes | |
| 39 | + |
| 40 | +## How It Works |
| 41 | + |
| 42 | +1. **Setup job**: Runs the [determine-matrix](../actions/determine-matrix/README.md) action to produce a matrix of `branch`, `java-version`, and `has-jdk8` from [`config/projects.json`](../../config/projects.json). |
| 43 | +2. **Build job** (matrix): For each matrix entry: |
| 44 | + - Checkout the branch, set up the JDK, configure Maven and Docker Hub |
| 45 | + - Decide whether this combination should deploy (and use the docs profile) based on `has-jdk8` and `java-version` |
| 46 | + - Run either: |
| 47 | + - **Build**: `./mvnw clean install -Pspring -B -U` when not deploying |
| 48 | + - **Build and deploy**: `./mvnw clean deploy -Pdocs,deploy,spring -B -U` for the designated deploy JDK |
| 49 | + - **Custom build command**: The caller-provided command, if set |
| 50 | + |
| 51 | +Deploy and docs are enabled for one JDK per branch (JDK 8 if the branch has JDK 8, otherwise JDK 17). |
| 52 | + |
| 53 | +## Usage |
| 54 | + |
| 55 | +### Basic usage from a Spring Cloud repo |
| 56 | + |
| 57 | +In your project’s `.github/workflows/deploy.yml`: |
| 58 | + |
| 59 | +```yaml |
| 60 | +jobs: |
| 61 | + deploy: |
| 62 | + uses: spring-cloud/spring-cloud-github-actions/.github/workflows/deploy.yml@main |
| 63 | + with: |
| 64 | + branches: ${{ inputs.branches }} |
| 65 | + runs_on: ${{ inputs.runs_on }} |
| 66 | + secrets: |
| 67 | + ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} |
| 68 | + ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} |
| 69 | + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} |
| 70 | + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} |
| 71 | +``` |
| 72 | +
|
| 73 | +For commercial projects, also pass `COMMERCIAL_ARTIFACTORY_USERNAME` and `COMMERCIAL_ARTIFACTORY_PASSWORD`. |
| 74 | + |
| 75 | +### Example caller workflow |
| 76 | + |
| 77 | +A full example with `push`, `schedule`, and `workflow_dispatch` (including optional `branches` and `runs_on`) is in [examples/deploy.yml](../../examples/deploy.yml). Copy and adapt that file into your project’s `.github/workflows/deploy.yml`. |
| 78 | + |
| 79 | +### Custom build command |
| 80 | + |
| 81 | +To override the default Maven command: |
| 82 | + |
| 83 | +```yaml |
| 84 | +with: |
| 85 | + branches: ${{ inputs.branches }} |
| 86 | + custom_build_command: | |
| 87 | + ./mvnw clean install -B |
| 88 | + ./mvnw verify -B |
| 89 | +``` |
| 90 | + |
| 91 | +## Configuration |
| 92 | + |
| 93 | +Branch and JDK version behavior is driven by [config/projects.json](../../config/projects.json) and the [determine-matrix](../actions/determine-matrix/README.md) action. The workflow does not define branches or JDK versions itself; it only consumes the matrix produced by that action. |
| 94 | + |
| 95 | +## See also |
| 96 | + |
| 97 | +- [Determine Build Matrix action](../actions/determine-matrix/README.md) — builds the matrix from `config/projects.json` |
| 98 | +- [Example caller workflow](../../examples/deploy.yml) — ready-to-adapt workflow for Spring Cloud projects |
0 commit comments