Skip to content

Commit

Permalink
Release flow (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: peterdeme <[email protected]>
  • Loading branch information
peterdeme authored Jun 10, 2024
1 parent 38e5547 commit 5b53cde
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 28 deletions.
12 changes: 0 additions & 12 deletions .github/actions/setup-go/action.yaml

This file was deleted.

13 changes: 10 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
name: Build
name: 👷 Build

on:
push:
branches: [ "main" ]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read
packages: write

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup go
uses: ./.github/actions/setup-go/

- name: Setup Go
uses: actions/setup-go@v5
with: { go-version-file: 'go.mod'}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
35 changes: 25 additions & 10 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
name: Lint
name: 🤓 Lint

on:
push:
branches: [ "main" ]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
generate:
name: generated files
name: Generated files up to date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup go
uses: ./.github/actions/setup-go/

- name: Setup Go
uses: actions/setup-go@v5
with: { go-version-file: 'go.mod'}

- name: Make sure generated files are up to date
run: |
make generate
Expand All @@ -22,13 +28,17 @@ jobs:
echo "Please run make generate and commit the changes."
exit 1
fi
lint-manifest:
name: Manifests
name: Manifests up to date
runs-on: ubuntu-latest-4-cores
steps:
- uses: actions/checkout@v4
- name: setup go
uses: ./.github/actions/setup-go/

- name: Setup Go
uses: actions/setup-go@v5
with: { go-version-file: 'go.mod'}

- name: Make sure manifest are up to date
run: |
make manifests
Expand All @@ -37,13 +47,17 @@ jobs:
echo "Please run make manifests and commit the changes."
exit 1
fi
lint-go:
name: GO code
name: Go code
runs-on: ubuntu-latest-4-cores
steps:
- uses: actions/checkout@v4
- name: setup go
uses: ./.github/actions/setup-go/

- name: Setup Go
uses: actions/setup-go@v5
with: { go-version-file: 'go.mod'}

- name: Make sure go.mod and go.sum are up to date
run: |
go mod tidy
Expand All @@ -52,6 +66,7 @@ jobs:
echo "Please run go mod tidy and commit the changes."
exit 1
fi
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: 🚀 Release

on:
push:
branches: [ "main" ]
tags: ["v*"]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
# When pushing the image, we push two tags: 'latest', and a version-specific tag.
# For production, the version-specific tag will be the git tag used to trigger the release (e.g. v1.0.0).
# For preprod, the version-specific tag will be the git commit SHA.
# This leads to image URLs like the following:
#
# - public.ecr.aws/spacelift/spacelift-operator:latest
# - public.ecr.aws/spacelift/spacelift-operator:v1.0.0
# - public.ecr.aws/spacelift-dev/spacelift-operator:latest
# - public.ecr.aws/spacelift-dev/spacelift-operator:4a401298262dba5980ae808d953723a31fb6f785
IMAGE_SPECIFIC_VERSION: ${{ startsWith(github.ref, 'refs/tags/v') && format('{0}:{1}', secrets.PUBLIC_ECR_REPOSITORY_URL, github.ref_name) || format('{0}:{1}', secrets.PREPROD_PUBLIC_ECR_REPOSITORY_URL, github.sha) }}
IMAGE_LATEST: ${{ startsWith(github.ref, 'refs/tags/v') && format('{0}:{1}', secrets.PUBLIC_ECR_REPOSITORY_URL, 'latest') || format('{0}:{1}', secrets.PREPROD_PUBLIC_ECR_REPOSITORY_URL, 'latest') }}
DOWNLOADS_BUCKET_PATH: "spacelift-operator"

jobs:
release:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with: { go-version-file: 'go.mod'}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ startsWith(github.ref, 'refs/tags/v') && secrets.AWS_ROLE_TO_ASSUME || secrets.PREPROD_AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 900

- name: Log in to Amazon public ECR
run: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Generate Kubernetes manifests
run: make controller-manifests
env:
# When building the manifests, we always use the specific version rather than latest.
# This means that if someone installs a new version of the manifests, it will automatically
# update to the new version without having to force a restart of the Deployment manually.
IMG: ${{ env.IMAGE_SPECIFIC_VERSION }}

- name: Create release
uses: goreleaser/goreleaser-action@v5
with:
args: release --clean --snapshot=${{ !startsWith(github.ref, 'refs/tags/v') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push the image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE_LATEST }}
${{ env.IMAGE_SPECIFIC_VERSION }}
- name: Upload the Kubernetes manifests to the Downloads bucket
run: |
aws s3 cp build/manifests/manifests.yaml s3://${DOWNLOADS_BUCKET_NAME}/${DOWNLOADS_BUCKET_PATH}/latest/manifests.yaml
${{ startsWith(github.ref, 'refs/tags/v') && format('aws s3 cp build/manifests/manifests.yaml s3://{0}/{1}/{2}/manifests.yaml', env.DOWNLOADS_BUCKET_NAME, env.DOWNLOADS_BUCKET_PATH, github.ref_name) || '' }}
env:
DOWNLOADS_BUCKET_NAME: ${{ startsWith(github.ref, 'refs/tags/v') && secrets.DOWNLOADS_S3_BUCKET_NAME || secrets.PREPROD_DOWNLOADS_S3_BUCKET_NAME }}

- name: Invalidate cache
run: |
aws cloudfront create-invalidation \
--distribution-id "${DISTRIBUTION_ID}" \
--paths "/${DOWNLOADS_BUCKET_PATH}/*"
env:
DISTRIBUTION_ID: ${{ startsWith(github.ref, 'refs/tags/v') && secrets.DOWNLOADS_CLOUDFRONT_DISTRIBUTION_ID || secrets.PREPROD_DOWNLOADS_CLOUDFRONT_DISTRIBUTION_ID }}
13 changes: 10 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
name: Test
name: 🧪 Test

on:
push:
branches: [ "main" ]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
unit:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup go
uses: ./.github/actions/setup-go/

- name: Setup Go
uses: actions/setup-go@v5
with: { go-version-file: 'go.mod'}

- name: Test
run: make test-ci
24 changes: 24 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,27 @@ builds:
- arm64
ldflags:
- -s -w -X github.com/spacelift-io/spacelift-operator/internal/build.Version={{.Version}}

changelog:
sort: asc
filters:
exclude:
- "^docs(\\(.+?\\))?:"
- "^test(\\(.+?\\))?:"
- "^chore(\\(.+?\\))?:"
- "^refactor(\\(.+?\\))?:"

release:
header: |
## Installation
The latest container image can be found at `public.ecr.aws/spacelift/spacelift-operator:{{ .Tag }}`, and the latest set of manifests can be found at https://downloads.spacelift.io/spacelift-operator/{{ .Tag }}/manifests.yaml.
To install the controller, run the following command:
```shell
kubectl apply -f https://downloads.spacelift.io/spacelift-operator/{{ .Tag }}/manifests.yaml
```
extra_files:
- glob: ./build/manifests/manifests.yaml

0 comments on commit 5b53cde

Please sign in to comment.