Skip to content
Merged
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
115 changes: 115 additions & 0 deletions .github/workflows/changes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Detect Changes

on:
workflow_call:
outputs:
images_matrix:
description: "Images matrix configuration for all components"
value: ${{ jobs.collect.outputs.images_matrix }}
clients_matrix:
description: "Clients matrix configuration for all components"
value: ${{ jobs.collect.outputs.clients_matrix }}
changes:
description: "JSON object mapping each component key to true/false"
value: ${{ jobs.collect.outputs.changes }}

jobs:
collect:
name: Changes and Matrix
permissions:
contents: read
Comment thread
viktor-flamingo marked this conversation as resolved.
runs-on: ubuntu-latest
outputs:
images_matrix: ${{ steps.define.outputs.images_matrix }}
clients_matrix: ${{ steps.define.outputs.clients_matrix }}
changes: ${{ steps.changes.outputs.changes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Define components
id: define
run: |
set -euo pipefail

IMAGES='[
{
"id": "server",
"name": "fleet",
"paths": ["./server/**", "./cmd/**", "./pkg/**", "./ee/**", "./tools/**", "./Dockerfile", "./.goreleaser.yml"]
}
]'

CLIENTS='[
{
"id": "client",
"name": "macos",
"path": "./orbit",
"os": "macos-latest",
"go_os": "darwin",
"go_arch": ["arm64", "amd64"],
"artifact_name": "fleet-mac-universal"
},
{
"id": "client",
"name": "windows",
"path": "./orbit",
"os": "windows-latest",
"go_os": "windows",
"go_arch": "amd64",
"artifact_name": "fleet-windows-amd64"
}
]'

ADDONS='{
"helm": ["./charts/**"]
}'

# the go module files rebuild both the server and the client
SHARED='["./go.mod", "./go.sum"]'

images_matrix=$(jq -c '[ .[] | { name } ]' <<< "$IMAGES")
clients_matrix=$(jq -c '[ .[] | { name, os, go_os, go_arch, artifact_name } ]' <<< "$CLIENTS")

filters=$(jq -nc \
--argjson images "$IMAGES" \
--argjson clients "$CLIENTS" \
--argjson addons "$ADDONS" \
--argjson shared "$SHARED" '
( [ $images[] | { key: (.id // .name), value: ((.paths // ["\(.path)/**"]) + $shared) } ]
+ [ $clients[] | { key: (.id // .name), value: ((.paths // ["\(.path)/**"]) + $shared) } ]
| from_entries )
+ $addons
')

keys=$(jq -nc --argjson f "$filters" '$f | keys')

# fail fast if the matrix or filters came out empty
[ "$(jq 'length' <<< "$images_matrix")" -gt 0 ] || { echo "images_matrix is empty" >&2; exit 1; }
[ "$(jq 'length' <<< "$clients_matrix")" -gt 0 ] || { echo "clients_matrix is empty" >&2; exit 1; }
[ "$(jq 'length' <<< "$keys")" -gt 0 ] || { echo "no change filters" >&2; exit 1; }

{
echo "images_matrix=$images_matrix"
echo "clients_matrix=$clients_matrix"
echo "filters=$filters"
echo "keys=$keys"
} >> "$GITHUB_OUTPUT"

- uses: dorny/paths-filter@v4.0.2
id: filter
with:
filters: ${{ steps.define.outputs.filters }}

- name: Build changes map
id: changes
env:
CHANGED: ${{ steps.filter.outputs.changes || '[]' }}
KEYS: ${{ steps.define.outputs.keys }}
run: |
set -euo pipefail
changes=$(jq -nc --argjson changed "$CHANGED" --argjson keys "$KEYS" '
reduce $keys[] as $k ({}; .[$k] = ((($changed | index($k)) != null) | tostring))
')
echo "changes=$changes" >> "$GITHUB_OUTPUT"
44 changes: 0 additions & 44 deletions .github/workflows/changes.yml

This file was deleted.

24 changes: 9 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:

changes:
name: Detect Changes
uses: ./.github/workflows/changes.yml
uses: ./.github/workflows/changes.yaml
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push'


Expand All @@ -54,23 +54,15 @@ jobs:
needs: [version, changes]
runs-on: ${{ matrix.os }}
if: |
(github.event_name == 'push' && needs.changes.outputs.client == 'true') ||
(github.event_name == 'push' && fromJSON(needs.changes.outputs.changes || '{}').client == 'true') ||
(github.event_name == 'workflow_dispatch' && needs.version.outputs.version != '')
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
go_os: darwin
go_arch: ["arm64", "amd64"]
artifact_name: fleet-mac-universal
- os: windows-latest
go_os: windows
go_arch: amd64
artifact_name: fleet-windows-amd64
include: ${{ fromJson(needs.changes.outputs.clients_matrix) }}

steps:
- name: Checkout
Expand Down Expand Up @@ -147,7 +139,7 @@ jobs:
needs: [version, changes]
runs-on: ubuntu-latest
if: |
(github.event_name == 'push' && needs.changes.outputs.server == 'true') ||
(github.event_name == 'push' && fromJSON(needs.changes.outputs.changes || '{}').server == 'true') ||
(github.event_name == 'workflow_dispatch' && needs.version.outputs.version != '')
steps:
- name: Harden Runner
Expand Down Expand Up @@ -210,7 +202,7 @@ jobs:
needs: [version, changes]
runs-on: ubuntu-latest
if: |
(github.event_name == 'push' && needs.changes.outputs.helm == 'true') ||
(github.event_name == 'push' && fromJSON(needs.changes.outputs.changes || '{}').helm == 'true') ||
(github.event_name == 'workflow_dispatch' && needs.version.outputs.version != '')
steps:
- name: Checkout
Expand Down Expand Up @@ -268,9 +260,11 @@ jobs:
- name: Generate release header
run: |
VERSION="${{ needs.version.outputs.version }}"
IMAGES=$(echo '${{ needs.changes.outputs.images_matrix }}' | jq -r '.[] | "- `${{ env.REGISTRY }}/${{ github.repository }}/\(.name):'"${VERSION}"'`"')

cat > RELEASE_HEADER.md <<EOF
## Images
- \`${{ env.REGISTRY }}/${{ github.repository }}/fleet:${VERSION}\`
${IMAGES}

## Fleet Clients
- **macOS** (Universal): \`fleet-macos-universal.tar.gz\`
Expand Down
29 changes: 5 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ env:
jobs:
changes:
name: Detect Changes
uses: ./.github/workflows/changes.yml
uses: ./.github/workflows/changes.yaml
if: |
github.event_name == 'pull_request' &&
!github.event.pull_request.draft
Expand All @@ -38,23 +38,10 @@ jobs:
name: "Test Client (${{ matrix.name }})"
needs: [changes]
runs-on: ${{ matrix.os }}
if: |
github.event_name == 'pull_request' &&
!github.event.pull_request.draft &&
needs.changes.outputs.client == 'true'
if: fromJSON(needs.changes.outputs.changes || '{}').client == 'true' # draft gate inherited from changes
strategy:
matrix:
include:
- name: macos
os: macos-latest
go_os: darwin
go_arch: ["arm64", "amd64"]
artifact_name: fleet-mac-universal
- name: windows
os: windows-latest
go_os: windows
go_arch: amd64
artifact_name: fleet-windows-amd64.exe
include: ${{ fromJson(needs.changes.outputs.clients_matrix) }}

steps:
- name: Checkout
Expand Down Expand Up @@ -122,10 +109,7 @@ jobs:
name: "Test Server"
needs: [changes]
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' &&
!github.event.pull_request.draft &&
needs.changes.outputs.server == 'true'
if: fromJSON(needs.changes.outputs.changes || '{}').server == 'true' # draft gate inherited from changes
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
Expand Down Expand Up @@ -175,10 +159,7 @@ jobs:
name: "Test Helm Chart"
needs: [changes]
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' &&
!github.event.pull_request.draft &&
needs.changes.outputs.helm == 'true'
if: fromJSON(needs.changes.outputs.changes || '{}').helm == 'true' # draft gate inherited from changes
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM alpine:3.23.0@sha256:51183f2cfa6320055da30872f211093f9ff1d3cf06f39a0bdb212314c5dc7375
FROM alpine:3.24@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b
LABEL maintainer="Fleet Developers"

RUN apk --no-cache add ca-certificates \
&& addgroup -S fleet \
&& adduser -S fleet -G fleet
RUN apk upgrade --no-cache \
&& apk add --no-cache ca-certificates \
&& addgroup -g 3333 -S fleet \
&& adduser -u 3333 -S fleet -G fleet

USER fleet

Expand Down
Loading
Loading