-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
94 lines (86 loc) · 3.29 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
image: golang:1.17.3
stages:
- test
- build
- prepare-release
- release
variables:
REPO_NAME: gitlab.com/aoterocom/changelog-guardian
before_script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
format:
stage: test
script:
- go fmt $(go list ./... | grep -v /vendor/)
- go vet $(go list ./... | grep -v /vendor/)
- go test -race $(go list ./... | grep -v /vendor/)
only:
- merge_requests
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
compile:
stage: build
script:
- go build -race -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/main
artifacts:
paths:
- main
only:
- merge_requests
prepare-release:
stage: prepare-release
script:
- git config user.name "$GIT_USERNAME"
- git config user.email "$GIT_EMAIL"
- go get $(go list ./... | grep -v /vendor/)
- go run main.go release --silent > VERSION
- git branch release/$(cat VERSION)
- git checkout release/$(cat VERSION)
- git add VERSION CHANGELOG.md
- git commit -m "[AUTOMATED] Release $(cat VERSION)"
- RELEASE_NOTES=$(go run main.go release-notes --echo)
- git push -o ci-skip https://gitlab-ci-token:${GITLAB_PUSH_TOKEN}@gitlab.com/aoterocom/changelog-guardian.git
- |
curl --location --request POST "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/merge_requests" \
--header "PRIVATE-TOKEN:$GITLAB_PUSH_TOKEN" \
--form 'id="'"$CI_PROJECT_ID"'"' \
--form "title=\"Release $(cat VERSION)\"" \
--form "source_branch="release/$(cat VERSION)"" \
--form 'target_branch="main"' \
--form 'description="'"$RELEASE_NOTES"'"'
rules:
- if: '$TRIGGER == "RELEASE"'
release:
stage: release
before_script:
- project_url=$(echo $CI_PROJECT_URL | sed 's/https:\/\///')
- git remote set-url origin https://gitlab-ci-token:$GITLAB_PUSH_TOKEN@gitlab.com/aoterocom/changelog-guardian.git
script:
- git config user.name "$GIT_USERNAME"
- git config user.email "$GIT_EMAIL"
- git tag v$(cat VERSION)
- git push origin HEAD:refs/tags/v$(cat VERSION) --force
- go get $(go list ./... | grep -v /vendor/)
- go run main.go calculate-release --minor --pre SNAPSHOT > VERSION
- git branch release/prepare-iteration-$(cat VERSION)
- git checkout release/prepare-iteration-$(cat VERSION)
- git add VERSION
- git commit -m "[AUTOMATED] Prepare for next iteration $(cat VERSION)"
- git push -o ci-skip https://gitlab-ci-token:${GITLAB_PUSH_TOKEN}@gitlab.com/aoterocom/changelog-guardian.git
- go run main.go release-notes
- go install github.com/goreleaser/goreleaser@v1.6.2
- GITLAB_TOKEN=$GITLAB_PUSH_TOKEN goreleaser release --skip-validate --rm-dist --release-notes RELEASE-NOTES.md
- |
curl --location --request POST "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/merge_requests" \
--header "PRIVATE-TOKEN:$GITLAB_PUSH_TOKEN" \
--form 'id="'"$CI_PROJECT_ID"'"' \
--form "title=\"Prepare develop iteration $(cat VERSION)\"" \
--form "source_branch="release/prepare-iteration-$(cat VERSION)"" \
--form 'target_branch="develop"' \
--form 'description="This PR will prepare develop for the next release iteration $(cat VERSION)"'
only:
- main