Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 63d6385

Browse files
authored
Merge pull request #7 from open-component-model/add_testing_and_release_flow
feat: add release flow and basic test for the controller
2 parents 9604f7b + f7f20b2 commit 63d6385

File tree

15 files changed

+481
-92
lines changed

15 files changed

+481
-92
lines changed

.github/workflows/ghcr.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name-template: '$NEXT_MINOR_VERSION'
2+
tag-template: '$NEXT_MINOR_VERSION'
3+
version-template: '$COMPLETE'
4+
change-template: '- $TITLE (#$NUMBER)'
5+
change-title-escapes: '\<*_&#@`'
6+
template: |
7+
# Release $NEXT_MINOR_VERSION
8+
9+
$CHANGES
10+
exclude-labels:
11+
- 'kind/skip-release-notes'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Check for diff after manifest and generated targets
2+
3+
on:
4+
pull_request: {}
5+
6+
jobs:
7+
check:
8+
name: Check for diff
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- name: Make manifests && generate
16+
run: |
17+
make manifests && make generate
18+
- name: Setup Go
19+
uses: actions/setup-go@v3
20+
with:
21+
go-version-file: '${{ github.workspace }}/go.mod'
22+
- name: Restore Go cache
23+
uses: actions/cache@v3
24+
with:
25+
path: /home/runner/work/_temp/_github_home/go/pkg/mod
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
29+
- name: go mod tidy
30+
run: |
31+
go mod tidy
32+
- name: Check for diff
33+
run: |
34+
git diff --exit-code --shortstat
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: e2e
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- 'CODE_OF_CONDUCT.md'
7+
- 'README.md'
8+
- 'Contributing.md'
9+
10+
push:
11+
branches:
12+
- main
13+
14+
permissions:
15+
contents: read # for actions/checkout to fetch code
16+
17+
jobs:
18+
kind-linux:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
- name: Setup Go
24+
uses: actions/setup-go@v3
25+
with:
26+
go-version-file: '${{ github.workspace }}/go.mod'
27+
- name: Restore Go cache
28+
uses: actions/cache@v3
29+
with:
30+
path: /home/runner/work/_temp/_github_home/go/pkg/mod
31+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
32+
restore-keys: |
33+
${{ runner.os }}-go-
34+
- name: Setup Kubernetes
35+
uses: helm/[email protected]
36+
with:
37+
version: v0.17.0
38+
cluster_name: ocm-e2e
39+
- name: Setup Kustomize
40+
uses: fluxcd/pkg/actions/kustomize@main
41+
- name: Run E2E tests
42+
run: make e2e
43+
env:
44+
KIND_CLUSTER_NAME: ocm-e2e
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
# The release-drafter action adds PR titles to the release notes once these are merged to main.
11+
# A draft release is kept up-to-date listing the changes for the next minor release version.
12+
jobs:
13+
update_release_draft:
14+
permissions:
15+
contents: write
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: release-drafter/release-drafter@v5
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_candidate:
7+
type: boolean
8+
description: "Release Candidate"
9+
required: false
10+
default: false
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
DOCKERFILE: ${{ github.workspace }}/goreleaser.dockerfile
15+
16+
jobs:
17+
tests:
18+
uses: ./.github/workflows/tests.yaml
19+
permissions:
20+
contents: read
21+
pull-requests: 'read'
22+
release:
23+
needs: tests
24+
name: Trigger release build
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: 'write'
28+
id-token: 'write'
29+
pull-requests: 'read'
30+
repository-projects: 'write'
31+
packages: 'write'
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
with:
36+
fetch-depth: 0
37+
- name: Setup Go
38+
uses: actions/setup-go@v3
39+
with:
40+
go-version-file: '${{ github.workspace }}/go.mod'
41+
- name: Cache go-build and mod
42+
uses: actions/cache@v3
43+
with:
44+
path: |
45+
~/.cache/go-build/
46+
~/go/pkg/mod/
47+
key: go-${{ hashFiles('go.sum') }}
48+
restore-keys: |
49+
go-
50+
- name: Set release version
51+
run: |
52+
if ${{ inputs.release_candidate }}; then
53+
echo "RELEASE_VERSION=$(go run $GITHUB_WORKSPACE/pkg/version/generate/release_generate.go print-rc-version)" >> $GITHUB_ENV
54+
else
55+
echo "RELEASE_VERSION=$(go run $GITHUB_WORKSPACE/pkg/version/generate/release_generate.go print-version)" >> $GITHUB_ENV
56+
fi
57+
- name: Set release notes file
58+
run: |
59+
echo "RELEASE_NOTES_FILE=docs/release_notes/$(go run $GITHUB_WORKSPACE/pkg/version/generate/release_generate.go print-version).md" >> $GITHUB_ENV
60+
- name: Validate release notes
61+
run: |
62+
if [[ ! -f ${{ env.RELEASE_NOTES_FILE }} ]]; then
63+
>&2 echo "Must have release notes ${{ env.RELEASE_NOTES_FILE }}"
64+
exit 6
65+
fi
66+
- name: Create and push branch
67+
env:
68+
RELEASE_BRANCH: release-${{ env.RELEASE_VERSION }}
69+
run: |
70+
if ! git checkout ${RELEASE_BRANCH} >/dev/null; then
71+
echo "Creating ${RELEASE_BRANCH} from $(git branch --show-current)"
72+
git checkout -b ${RELEASE_BRANCH}
73+
git push origin "$(git branch --show-current)"
74+
else
75+
git checkout ${RELEASE_BRANCH}
76+
git pull --ff-only origin ${RELEASE_BRANCH}
77+
fi
78+
- name: Setup git config
79+
run: |
80+
git config user.name "GitHub Actions Bot"
81+
git config user.email "<41898282+github-actions[bot]@users.noreply.github.com>"
82+
- name: Create and push tag
83+
run: |
84+
msg="Release ${{ env.RELEASE_VERSION }}"
85+
git tag --annotate --message "${msg}" ${{ env.RELEASE_VERSION }}
86+
git push origin ${{ env.RELEASE_VERSION }}
87+
- name: Log in to the Container registry
88+
uses: docker/login-action@v2
89+
with:
90+
registry: ${{ env.REGISTRY }}
91+
username: ${{ github.actor }}
92+
password: ${{ secrets.GITHUB_TOKEN }}
93+
- name: Generate manifests
94+
run: |
95+
mkdir -p output
96+
kustomize build ./config/default > ./output/install.yaml
97+
- name: Run goreleaser
98+
uses: goreleaser/goreleaser-action@v4
99+
with:
100+
distribution: goreleaser
101+
version: latest
102+
args: release --clean --timeout 60m --skip-validate --config=./.goreleaser.yaml --release-notes=${{ env.RELEASE_NOTES_FILE }}
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
GORELEASER_CURRENT_TAG: ${{ env.RELEASE_VERSION }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: tests
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- 'CODE_OF_CONDUCT.md'
7+
- 'README.md'
8+
- 'Contributing.md'
9+
workflow_call:
10+
11+
push:
12+
branches:
13+
- main
14+
15+
permissions:
16+
contents: read # for actions/checkout to fetch code
17+
18+
jobs:
19+
test-linux:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
- name: Setup Go
25+
uses: actions/setup-go@v3
26+
with:
27+
go-version-file: '${{ github.workspace }}/go.mod'
28+
- name: Restore Go cache
29+
uses: actions/cache@v3
30+
with:
31+
path: /home/runner/work/_temp/_github_home/go/pkg/mod
32+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
33+
restore-keys: |
34+
${{ runner.os }}-go-
35+
- name: Run tests
36+
run: make test
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package controllers
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
v1 "k8s.io/api/core/v1"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/types"
12+
ctrl "sigs.k8s.io/controller-runtime"
13+
14+
ocmv1 "github.com/open-component-model/ocm-controller/api/v1alpha1"
15+
16+
"github.com/open-component-model/git-sync-controller/api/v1alpha1"
17+
"github.com/open-component-model/git-sync-controller/pkg"
18+
)
19+
20+
func TestGitSyncReconciler(t *testing.T) {
21+
cv := DefaultComponent.DeepCopy()
22+
snapshot := DefaultSnapshot.DeepCopy()
23+
secret := &v1.Secret{
24+
ObjectMeta: metav1.ObjectMeta{
25+
Name: "auth-secret",
26+
Namespace: "default",
27+
},
28+
Data: map[string][]byte{
29+
"username": []byte("username"),
30+
"password": []byte("password"),
31+
},
32+
}
33+
gitSync := &v1alpha1.GitSync{
34+
ObjectMeta: metav1.ObjectMeta{
35+
Name: "git-sync-test",
36+
Namespace: "default",
37+
},
38+
Spec: v1alpha1.GitSyncSpec{
39+
ComponentRef: v1alpha1.Ref{
40+
Name: cv.Name,
41+
Namespace: cv.Namespace,
42+
},
43+
SnapshotRef: v1alpha1.Ref{
44+
Name: snapshot.Name,
45+
Namespace: snapshot.Namespace,
46+
},
47+
AuthRef: v1alpha1.Ref{
48+
Name: secret.Name,
49+
Namespace: secret.Namespace,
50+
},
51+
URL: "https://github.com/Skarlso/test",
52+
Branch: "main",
53+
CommitTemplate: &v1alpha1.CommitTemplate{
54+
Name: "Skarlso",
55+
56+
Message: "This is my message",
57+
},
58+
SubPath: "./subpath",
59+
Prune: true,
60+
},
61+
}
62+
63+
client := env.FakeKubeClient(WithObjets(gitSync, snapshot, cv, secret), WithAddToScheme(ocmv1.AddToScheme))
64+
m := &mockGit{
65+
digest: "test-digest",
66+
}
67+
gsr := GitSyncReconciler{
68+
Client: client,
69+
Scheme: env.scheme,
70+
Git: m,
71+
}
72+
73+
_, err := gsr.Reconcile(context.Background(), ctrl.Request{
74+
NamespacedName: types.NamespacedName{
75+
Namespace: gitSync.Namespace,
76+
Name: gitSync.Name,
77+
},
78+
})
79+
require.NoError(t, err)
80+
81+
err = client.Get(context.Background(), types.NamespacedName{
82+
Name: gitSync.Name,
83+
Namespace: gitSync.Namespace,
84+
}, gitSync)
85+
require.NoError(t, err)
86+
87+
assert.Equal(t, "test-digest", gitSync.Status.Digest)
88+
}
89+
90+
type mockGit struct {
91+
digest string
92+
err error
93+
}
94+
95+
func (g *mockGit) Push(ctx context.Context, opts *pkg.PushOptions) (string, error) {
96+
return g.digest, g.err
97+
}

0 commit comments

Comments
 (0)