Skip to content

Commit 43bba6d

Browse files
authored
Refactor e2e test (#1122)
* Refactor e2e test * Refactor
1 parent 89ce4c9 commit 43bba6d

5 files changed

Lines changed: 52 additions & 52 deletions

File tree

.github/workflows/docker.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,18 @@ jobs:
105105

106106
- run: make -C e2e_test deploy-app1
107107
env:
108-
PULL_REQUEST_BODY: "e2e-test ${{ github.repository }}#${{ github.event.pull_request.number }}"
109108
DEPLOYMENT_URL: ${{ steps.deployment-app1.outputs.url }}
110109
GITHUB_TOKEN: ${{ steps.e2e-test-token.outputs.token }}
111110

112111
- run: make -C e2e_test restart-app1
113112

114113
- run: make -C e2e_test deploy-app2
115114
env:
116-
PULL_REQUEST_BODY: "e2e-test ${{ github.repository }}#${{ github.event.pull_request.number }}"
117115
DEPLOYMENT_URL: ${{ steps.deployment-app2.outputs.url }}
118116
GITHUB_TOKEN: ${{ steps.e2e-test-token.outputs.token }}
119117

120118
- run: make -C e2e_test deploy-app3
121119
env:
122-
PULL_REQUEST_BODY: "e2e-test ${{ github.repository }}#${{ github.event.pull_request.number }}"
123120
DEPLOYMENT_URL: ${{ steps.deployment-app3.outputs.url }}
124121
GITHUB_TOKEN: ${{ steps.e2e-test-token.outputs.token }}
125122

e2e_test/Makefile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ KUBECONFIG := output/kubeconfig.yaml
33
export KUBECONFIG
44

55
GITHUB_RUN_NUMBER ?= 0
6-
FIXTURE_BASE_BRANCH := e2e-test/$(GITHUB_RUN_NUMBER)/main
6+
FIXTURE_BRANCH := e2e-test/$(GITHUB_RUN_NUMBER)/main
77
FIXTURE_DIR := argocd-commenter-e2e-test-repository
88

99
all:
1010

1111
setup-fixture-branch:
1212
test -d $(FIXTURE_DIR)
1313
rsync -av fixture/ $(FIXTURE_DIR)/
14-
$(MAKE) -C $(FIXTURE_DIR) push-base-branch
14+
$(MAKE) -C $(FIXTURE_DIR) setup-fixture-branch
1515

1616
# cluster
1717
cluster: $(KUBECONFIG)
@@ -24,7 +24,7 @@ delete-cluster:
2424

2525
deploy-argocd: cluster
2626
kustomize build argocd | kubectl apply -f -
27-
kustomize build applications | sed -e "s|FIXTURE_BASE_BRANCH|$(FIXTURE_BASE_BRANCH)|g" | kubectl apply -f -
27+
kustomize build applications | sed -e "s|FIXTURE_BRANCH|$(FIXTURE_BRANCH)|g" | kubectl apply -f -
2828

2929
deploy-controller: cluster
3030
cd controller && kustomize edit set image controller="$(CONTROLLER_IMAGE)"
@@ -33,24 +33,24 @@ deploy-controller: cluster
3333
kubectl -n argocd-commenter-system rollout status deployment argocd-commenter-controller-manager
3434

3535
wait-for-apps:
36-
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BASE_BRANCH)`" app1 app2 app3
36+
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BRANCH)`" app1 app2 app3
3737

3838
# fixture
3939
deploy-app1:
40-
$(MAKE) -C $(FIXTURE_DIR) update-manifest-app1
41-
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BASE_BRANCH)`" app1
40+
$(MAKE) -C $(FIXTURE_DIR) deploy-app1
41+
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BRANCH)`" app1
4242

4343
restart-app1:
4444
kubectl -n app1 delete pod -l app=echoserver --force
45-
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BASE_BRANCH)`" app1
45+
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BRANCH)`" app1
4646

4747
deploy-app2:
48-
$(MAKE) -C $(FIXTURE_DIR) update-manifest-app2
49-
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BASE_BRANCH)`" -sync OutOfSync -operation Failed app2
48+
$(MAKE) -C $(FIXTURE_DIR) deploy-app2
49+
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BRANCH)`" -sync OutOfSync -operation Failed app2
5050

5151
deploy-app3:
52-
$(MAKE) -C $(FIXTURE_DIR) update-manifest-app3
53-
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BASE_BRANCH)`" app3
52+
$(MAKE) -C $(FIXTURE_DIR) deploy-app3
53+
go run ./waitforapp -revision "`git -C $(FIXTURE_DIR) rev-parse $(FIXTURE_BRANCH)`" app3
5454

5555
logs-controller:
5656
-kubectl -n argocd-commenter-system logs -l control-plane=controller-manager --all-containers --tail=-1

e2e_test/applications/e2e-test-set.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
generators:
1111
- git:
1212
repoURL: https://github.com/int128/argocd-commenter-e2e-test
13-
revision: FIXTURE_BASE_BRANCH
13+
revision: FIXTURE_BRANCH
1414
files:
1515
- path: "*/metadata.yaml"
1616
requeueAfterSeconds: 5 # To update the deploymentURL within e2e-test
@@ -25,7 +25,7 @@ spec:
2525
project: e2e-test-project
2626
source:
2727
repoURL: https://github.com/int128/argocd-commenter-e2e-test
28-
targetRevision: FIXTURE_BASE_BRANCH
28+
targetRevision: FIXTURE_BRANCH
2929
path: "{{ .path.basename }}"
3030
destination:
3131
server: https://kubernetes.default.svc

e2e_test/fixture/Makefile

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,37 @@
11
GITHUB_RUN_NUMBER ?= 0
2-
FIXTURE_BASE_BRANCH := e2e-test/$(GITHUB_RUN_NUMBER)/main
3-
FIXTURE_BRANCH_PREFIX := e2e-test/$(GITHUB_RUN_NUMBER)
2+
FIXTURE_BRANCH := e2e-test/$(GITHUB_RUN_NUMBER)/main
43

54
all:
65

7-
push-base-branch:
6+
setup-fixture-branch:
87
git config user.name 'github-actions[bot]'
98
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
10-
git checkout -B "$(FIXTURE_BASE_BRANCH)"
9+
git checkout -B "$(FIXTURE_BRANCH)"
1110
git add .
12-
git commit -a -m "Initial commit"
13-
git push origin -f "$(FIXTURE_BASE_BRANCH)"
11+
git commit -m "Initial commit"
12+
git push origin -f "$(FIXTURE_BRANCH)"
1413

1514
# Test#1
1615
# It updates an image tag of Deployment.
1716
# It will cause the rolling update, that is, Progressing state.
18-
update-manifest-app1:
19-
git checkout "$(FIXTURE_BASE_BRANCH)"
20-
git checkout -b "$(FIXTURE_BRANCH_PREFIX)/update-manifest-app1"
17+
deploy-app1:
18+
git checkout "$(FIXTURE_BRANCH)"
2119
sed -i -e 's/echoserver:1.8/echoserver:1.9/g' app1/deployment/echoserver.yaml
22-
echo 'deploymentURL: $(DEPLOYMENT_URL)' > app1/metadata.yaml
23-
git commit -a -m 'e2e-test: update-manifest-app1'
24-
git push origin -f "$(FIXTURE_BRANCH_PREFIX)/update-manifest-app1"
25-
gh pr create --base "$(FIXTURE_BASE_BRANCH)" --fill --body "$(PULL_REQUEST_BODY)" --label e2e-test
26-
gh pr merge --squash
27-
git checkout "$(FIXTURE_BASE_BRANCH)"
28-
git pull origin "$(FIXTURE_BASE_BRANCH)" --ff-only
20+
bash deploy.sh app1
2921

3022
# Test#2
3123
# It updates the label to invalid value.
3224
# It will cause this error:
3325
# one or more objects failed to apply, reason: Deployment.apps "echoserver" is invalid: spec.selector: Invalid value: v1.LabelSelector
34-
update-manifest-app2:
35-
git checkout "$(FIXTURE_BASE_BRANCH)"
36-
git checkout -b "$(FIXTURE_BRANCH_PREFIX)/update-manifest-app2"
26+
deploy-app2:
27+
git checkout "$(FIXTURE_BRANCH)"
3728
sed -i -e 's/app: echoserver/app: echoserver-test2/g' app2/deployment/echoserver.yaml
38-
echo 'deploymentURL: $(DEPLOYMENT_URL)' > app2/metadata.yaml
39-
git commit -a -m 'e2e-test: update-manifest-app2'
40-
git push origin -f "$(FIXTURE_BRANCH_PREFIX)/update-manifest-app2"
41-
gh pr create --base "$(FIXTURE_BASE_BRANCH)" --fill --body "$(PULL_REQUEST_BODY)" --label e2e-test
42-
gh pr merge --squash
43-
git checkout "$(FIXTURE_BASE_BRANCH)"
44-
git pull origin "$(FIXTURE_BASE_BRANCH)" --ff-only
29+
bash deploy.sh app2
4530

4631
# Test#3
4732
# It updates an image tag of CronJob template.
4833
# Application will not transit to Progressing state.
49-
update-manifest-app3:
50-
git checkout "$(FIXTURE_BASE_BRANCH)"
51-
git checkout -b "$(FIXTURE_BRANCH_PREFIX)/update-manifest-app3"
34+
deploy-app3:
35+
git checkout "$(FIXTURE_BRANCH)"
5236
sed -i -e 's/busybox:1.28/busybox:1.30/g' app3/cronjob/echoserver.yaml
53-
echo 'deploymentURL: $(DEPLOYMENT_URL)' > app3/metadata.yaml
54-
git commit -a -m 'e2e-test: update-manifest-app3'
55-
git push origin -f "$(FIXTURE_BRANCH_PREFIX)/update-manifest-app3"
56-
gh pr create --base "$(FIXTURE_BASE_BRANCH)" --fill --body "$(PULL_REQUEST_BODY)" --label e2e-test
57-
gh pr merge --squash
58-
git checkout "$(FIXTURE_BASE_BRANCH)"
59-
git pull origin "$(FIXTURE_BASE_BRANCH)" --ff-only
37+
bash deploy.sh app3

e2e_test/fixture/deploy.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -eux -o pipefail
3+
4+
: "$GITHUB_REPOSITORY"
5+
: "$GITHUB_REF_NAME"
6+
: "$GITHUB_RUN_NUMBER"
7+
8+
app="$1"
9+
head_branch="e2e-test/$GITHUB_RUN_NUMBER/deploy-$app"
10+
base_branch="e2e-test/$GITHUB_RUN_NUMBER/main"
11+
12+
# Commit the changes
13+
echo "deploymentURL: $DEPLOYMENT_URL" > "$app/metadata.yaml"
14+
git checkout -b "$head_branch"
15+
git add .
16+
git commit -m "e2e-test: Update $app"
17+
18+
# Push and merge it
19+
git push origin -f "$head_branch"
20+
gh pr create --base "$base_branch" --fill --body "$GITHUB_REPOSITORY#${GITHUB_REF_NAME%%/*}" --label e2e-test
21+
gh pr merge --squash
22+
23+
# Reset the local state
24+
git checkout "$base_branch"
25+
git pull origin "$base_branch" --ff-only

0 commit comments

Comments
 (0)