Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/bump-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ targets:
kind: file
spec:
content: 'go {{ source "latestGoVersion" }}'
file: dev-tools/go.mod
file: dev-tools/tools/go.mod
matchpattern: 'go \d+.\d+.\d+'
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ linters:
min-occurrences: 2

gomoddirectives:
# Allow local `replace` directives. Default is false.
replace-local: false
# Allow local `replace` directives (e.g. dev-tools submodule in go.mod).
replace-local: true
gomodguard:
blocked:
# List of blocked modules.
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WORKDIR /fleet-server

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
COPY dev-tools/tools/go.mod dev-tools/tools/go.sum ./dev-tools/tools/
RUN go mod download && go mod verify
RUN go install github.com/magefile/mage # Uses version from go.mod implicitly
ENV PATH="$PATH:/go/bin"
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ USER fleet-server
WORKDIR /fleet-server/
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
COPY dev-tools/tools/go.mod dev-tools/tools/go.sum ./dev-tools/tools/
RUN go mod download && go mod verify
RUN go install github.com/magefile/mage # uses version in go.mod

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.fips
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WORKDIR /fleet-server/

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
COPY dev-tools/tools/go.mod dev-tools/tools/go.sum ./dev-tools/tools/
# GOFIPS140 must be set before go mod download so that the golang.org/fips140 module is cached during image build.
# Without this, the module would be fetched at build time by the host user who lacks write access to the module cache.
ENV GOFIPS140=certified
Expand All @@ -32,6 +33,7 @@ FROM docker.elastic.co/beats-dev/golang-crossbuild:${GO_VERSION}-${SUFFIX} AS bu
WORKDIR /fleet-server
ENV PATH="$PATH:/go/bin"
COPY go.mod go.sum ./
COPY dev-tools/tools/go.mod dev-tools/tools/go.sum ./dev-tools/tools/
RUN go mod download && go mod verify
RUN go install github.com/magefile/mage # uses version in go.mod

Expand Down
102 changes: 102 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Fleet Server Release Automation

Mage-based release workflows for Fleet Server, replacing the former ingest-dev
[`fleet-server.mak`](https://github.com/elastic/ingest-dev/blob/main/release_scripts/fleet-server.mak)
Makefile process. Process shape matches beats and elastic-agent (feature-freeze
and patch merge-timing labels); file updates stay limited to `version/version.go`
and `.mergify.yml`.

## Quick start

```bash
export PROJECT_OWNER="your-user"
export NEXT_RELEASE="9.6.0" # must already match version/version.go on main
export GITHUB_TOKEN=$(gh auth token)
export DRY_RUN=true

# Feature freeze
mage release:runMajorMinor

# Patch: NEXT_RELEASE is the version to land (NEW_VERSION)
export NEXT_RELEASE="9.6.1" # release branch must still be at 9.6.0
mage release:runPatch

go test ./dev-tools/mage/... -count=1
```

Use plain `X.Y.Z` semver for `NEXT_RELEASE` (no `-test` or `-SNAPSHOT` suffixes).

## Feature freeze (`mage release:runMajorMinor`)

`NEXT_RELEASE` is the version **already on** `main` (the line being frozen).

| Slot | Branch → base | Changes | Merge label |
|---|---|---|---|
| Release branch | `X.Y` from `main` | pushed | — |
| **PR-A** | `ff-prep-main-{CURRENT}` → `main` | Mergify backport + bump to next minor | `merge:1-ff-day` |
| **PR-B** | `ff-release-{CURRENT}` → `X.Y` | ensure `version.go` = CURRENT (often no-op) | `merge:2-after-branch` |
| **PR-C** | — | **omitted** (no docs/test-env) | — |

Next-patch bumps are **not** opened here; use `mage release:runPatch`.

## Patch (`mage release:runPatch`)

`NEXT_RELEASE` is the version to land (`NEW_VERSION` from version-bump). The
release branch must already be at the previous patch. Docs stay off this path.

| Slot | Branch → base | Changes | Merge label |
|---|---|---|---|
| **bump** | `update-version-{CURRENT}` → `X.Y` | bump `version.go` to CURRENT | `merge:4-after-release` |

## Environment variables

| Variable | Required | Default | Description |
|---|---|---|---|
| `NEXT_RELEASE` | yes | — | FF: version on base; patch: version to land (`NEW_VERSION`) |
| `GITHUB_TOKEN` | yes (unless dry run) | — | GitHub API token |
| `DRY_RUN` | no | `false` | Only `true` enables dry run |
| `BASE_BRANCH` | no | `main` | Base branch for feature freeze |
| `PROJECT_OWNER` | no | `elastic` | GitHub owner |
| `PROJECT_REPO` | no | `fleet-server` | GitHub repository |
| `PROJECT_REVIEWERS` | no | `elastic/elastic-agent-control-plane` | PR reviewers |

Derived (not env-overridable): `NEXT_PROJECT_MINOR_VERSION` (minor+1), `RELEASE_BRANCH` (`X.Y`), `LATEST_RELEASE` (patch−1 from `NEXT_RELEASE`; empty when patch is 0).

## Files updated

- `version/version.go` — `DefaultVersion`
- `.mergify.yml` — backport rule (PR-A)

## Idempotency

| Step | Re-run behavior |
|---|---|
| `UpdateVersion` | No-op when version already matches |
| `UpdateMergify` | No-op when backport rule already exists |
| Branch creation | Reuses existing branch |
| `CommitAll` | Skips when worktree is clean |
| `CreatePR` | Returns existing open PR for same head/base |

## Package layout

```
dev-tools/mage/
├── release_settings.go # ReleaseSettings + env load (root module)
└── release/
├── config.go # type alias + Validate/EnsureLatestRelease
├── release.go
├── mergify.go
├── workflows.go
├── git.go / github.go / issue.go / version.go
└── README.md
```

Root `mage release:*` targets call the release package directly (same root `go.mod`).

## Testing

```bash
go test ./dev-tools/mage/... -count=1
```

Discard local workflow changes after review with `git reset --hard HEAD`.
70 changes: 70 additions & 0 deletions dev-tools/mage/release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Fleet Server release package

Operator reference for `dev-tools/mage/release/`. Release managers should start with [`RELEASE.md`](../../../RELEASE.md) at the repository root.

## Mage targets

| Target | Purpose |
|---|---|
| `mage release:ensureIssueTracker` | Create/update release checklist issue |
| `mage release:runMajorMinor` | Feature freeze: release branch + PR-A/B (no next-patch) |
| `mage release:runPatch` | Patch: post-release bump to `NEXT_RELEASE` |
| `mage release:updateMergify` | Append backport rule |
| `mage release:updateVersion` | Update `version/version.go` only |

There is **no** `runNextRelease` target; version bumps after a patch release are opened only by `runPatch` (not `runMajorMinor`).

## Architecture

- Release tooling lives in the root module (`github.com/elastic/fleet-server/v7`), same pattern as elastic-agent.
- Settings load via `dev-tools/mage.LoadReleaseSettings`; mage targets call package functions directly.
- File allowlist: only `version/version.go` and `.mergify.yml`.

## Alignment with beats / elastic-agent

Shared process: merge-timing labels, idempotent branches/PRs, issue tracker, root-module release package.
Patch `NEXT_RELEASE` is the version to land (`NEW_VERSION`); the release branch must already be at the previous patch.

Fleet Server differences (from former `fleet-server.mak`):

- No K8s / Helm / docs / test-env updates → **PR-C omitted**
- Patch opens a single version bump PR (no docs PR)

## Local testing

```bash
export PROJECT_OWNER="$USER"
export NEXT_RELEASE="$(grep DefaultVersion version/version.go | sed -E 's/.*"([^"]+)".*/\1/')"
export DRY_RUN=true
export GITHUB_TOKEN="$(gh auth token)"

mage release:runMajorMinor
```

`DRY_RUN` does **not** exercise Buildkite reference clones or a real token push.
Before merging changes under `dev-tools/mage/release/`, run the ingest
**release smoke** (below).

## Buildkite ingest release smoke (pre-merge)

Pipeline: [observability-robots-ingest-release-smoke](https://buildkite.com/elastic/observability-robots-ingest-release-smoke)
on [`elastic/observability-robots`](https://github.com/elastic/observability-robots)
([tools/ingest-release-smoke](https://github.com/elastic/observability-robots/tree/main/tools/ingest-release-smoke)).

It clones this repo at a candidate SHA, seeds `release-smoke/base` on
`elastic/observability-robots` (never `main`), runs `mage release:runMajorMinor`
then `mage release:runPatch` with a Vault-minted `GITHUB_TOKEN`, then deletes
smoke branches/PRs/issues.

Create a build with:

```text
SOURCE_REPO=fleet-server
SOURCE_SHA=<pr-head-sha>
```

Optional: `SOURCE_OWNER` (default `elastic`), `WORKFLOWS` (default
`major-minor,patch`).

Details: [ingest-release-smoke README](https://github.com/elastic/observability-robots/blob/main/tools/ingest-release-smoke/README.md).

61 changes: 61 additions & 0 deletions dev-tools/mage/release/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

package release

import (
"fmt"

devtools "github.com/elastic/fleet-server/v7/dev-tools/mage"
)

// ReleaseConfig is the release automation configuration loaded via mage settings.
type ReleaseConfig = devtools.ReleaseSettings

// fetchLatestReleaseBefore looks up the previous published release from GitHub.
// Tests may replace this to avoid network calls.
var fetchLatestReleaseBefore = func(token, owner, repo, current string) (string, error) {
return newGitHubClient(token).latestReleaseBefore(owner, repo, current)
}

const (
releasesLookupOwner = "elastic"
releasesLookupRepo = "fleet-server"
)

// ensureLatestRelease sets LatestRelease when unset by querying fleet-server releases/tags.
func ensureLatestRelease(c *ReleaseConfig) error {
if err := c.EnsureParsedVersions(); err != nil {
return err
}
if c.LatestReleaseVersion != nil {
return nil
}
if c.LatestRelease != "" {
return c.SetLatestReleaseFromString(c.LatestRelease)
}

latest, err := fetchLatestReleaseBefore(c.GitHubToken, releasesLookupOwner, releasesLookupRepo, c.NextRelease)
if err != nil {
return fmt.Errorf("failed to resolve LatestRelease from GitHub: %w", err)
}
if err := c.SetLatestReleaseFromString(latest); err != nil {
return fmt.Errorf("failed to parse LatestRelease from GitHub (%s): %w", latest, err)
}
printf("Resolved LatestRelease from %s/%s: %s\n", releasesLookupOwner, releasesLookupRepo, c.LatestRelease)
return nil
}

// validateReleaseConfig checks if the configuration is valid for release workflows.
func validateReleaseConfig(c *ReleaseConfig) error {
if err := c.EnsureParsedVersions(); err != nil {
return err
}

if !c.DryRun && c.GitHubToken == "" {
return fmt.Errorf("GITHUB_TOKEN is required when not in dry-run mode")
}

return nil
}
49 changes: 49 additions & 0 deletions dev-tools/mage/release/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

package release

import (
"testing"

"github.com/stretchr/testify/require"

devtools "github.com/elastic/fleet-server/v7/dev-tools/mage"
)

func TestValidateReleaseConfig(t *testing.T) {
require.Error(t, validateReleaseConfig(&ReleaseConfig{DryRun: true, LatestRelease: testVersion940}))
require.Error(t, validateReleaseConfig(&ReleaseConfig{NextRelease: testVersion950, LatestRelease: testVersion940}))
require.NoError(t, validateReleaseConfig(&ReleaseConfig{
NextRelease: testVersion950,
LatestRelease: testVersion940,
DryRun: true,
}))
}

func TestEnsureLatestRelease(t *testing.T) {
orig := fetchLatestReleaseBefore
t.Cleanup(func() { fetchLatestReleaseBefore = orig })
fetchLatestReleaseBefore = func(token, owner, repo, current string) (string, error) {
return testVersion943, nil
}

cfg := &ReleaseConfig{NextRelease: testVersion950, DryRun: true}
require.NoError(t, ensureLatestRelease(cfg))
require.Equal(t, testVersion943, cfg.LatestRelease)

cfg.LatestRelease = testVersion940
require.NoError(t, ensureLatestRelease(cfg))
require.Equal(t, testVersion940, cfg.LatestRelease)
}

func TestLoadReleaseSettings(t *testing.T) {
t.Setenv("NEXT_RELEASE", testVersion950)
t.Setenv("DRY_RUN", "true")
settings, err := devtools.LoadReleaseSettings()
require.NoError(t, err)
require.NoError(t, settings.RequireRelease())
require.Equal(t, testVersion950, settings.NextRelease)
require.True(t, settings.DryRun)
}
Loading
Loading