-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
168 lines (159 loc) · 4.4 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
stages:
- Testing and Linting
- Build
- Tag
- Release
Shellcheck:
stage: Testing and Linting
retry: 2
tags:
- msul-shared
image: alpine:latest
timeout: 5m
interruptible: true
rules:
- if: '$CI_COMMIT_TAG'
when: never
- if: '$CI_PIPELINE_SOURCE != "schedule"'
before_script:
- apk add shellcheck || apt install shellcheck
script:
- shellcheck run-*
Unit Testing and Linting:
stage: Testing and Linting
retry: 2
tags:
- msul-shared
image: python:3.12
except:
- tags
script:
- pip install -r requirements.txt
- pylint --fail-under=10.00 sandhill/
- pytest --junitxml=report.xml
artifacts:
when: always
reports:
junit: report.xml
Build Image:
stage: Build
retry: 2
tags:
- msul-shared
only:
- master
except:
- tags
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t registry.gitlab.msu.edu/msu-libraries/repo-team/sandhill:latest .
- docker push registry.gitlab.msu.edu/msu-libraries/repo-team/sandhill:latest
Publish Docs to GitLab:
stage: Build
tags:
- msul-shared
image: python:latest
only:
- master
except:
- tags
needs:
- job: Build Image
script:
- pip install -r requirements.txt
- mkdocs build --site-dir public
artifacts:
paths:
- public
Tag Release:
stage: Tag
tags:
- msul-shared
when: manual
only:
- master
except:
- tags
script:
- apk add git || apt install git
- rm -rf clone/ || true
- git clone https://gitlab-ci-token:[email protected]/msu-libraries/repo-team/sandhill.git clone/
- cd clone/ # doing this to avoid runner cache
- major_ver=$(date +'%y.%-m')
- latest_patch=$(git tag -l $major_ver* --sort=-v:refname | head -n 1 | cut -d'.' -f 3)
- "[ -z $latest_patch ] && cur_patch=-1 || cur_patch=$latest_patch"
- patch_ver=$(($cur_patch+1))
- TAG=$major_ver.$patch_ver
- echo "TAG=$TAG" > ../variables.env
- echo "Tagging new release with $TAG"
- git tag $TAG
- git push origin --tags
artifacts:
reports:
dotenv: variables.env
GitLab Release:
stage: Release
image: registry.gitlab.com/gitlab-org/release-cli:latest
tags:
- msul-shared
when: manual
only:
- master
except:
- tags
needs:
- job: Tag Release
artifacts: true
script:
- echo 'Creating GitLab release $TAG'
release:
tag_name: '$TAG'
description: 'Release $TAG'
GitHub Release:
stage: Release
tags:
- msul-shared
when: manual
only:
- master
except:
- tags
needs:
- job: Tag Release
artifacts: true
script:
- apk add curl git || apt install curl git
- rm -rf sandhill.git
- git clone --mirror https://gitlab-ci-token:[email protected]/msu-libraries/repo-team/sandhill.git
- cd sandhill.git
# This will trigger the GitHub CI which builds the MkDocs into the gh-pages branch
- git push --force --mirror https://[email protected]/MSU-Libraries/sandhill.git
- echo "{\"tag_name\":\"${TAG}\", \"target_commitish\":\"${CI_COMMIT_SHA}\"}" > data.json
- "curl -X POST -H 'Accept: application/vnd.github.v3+json' -u $GITHUB_USER_TOKEN https://api.github.com/repos/MSU-Libraries/sandhill/releases -d '@data.json'"
# Update the GitHub Pages branch used
- sleep 45 # Needs time to propagate the changes first or this next step will fail
- echo "{\"source\":{\"path\":\"/\", \"branch\":\"gh-pages\"}" > data.json
- "curl -X POST -H 'Accept: application/vnd.github.v3+json' -u $GITHUB_USER_TOKEN https://api.github.com/repos/MSU-Libraries/sandhill/pages -d '@data.json'"
DockerHub Release:
stage: Release
tags:
- msul-shared
image: docker:latest
when: manual
only:
- master
except:
- tags
needs:
- job: Tag Release
artifacts: true
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker login -u msulibraries -p $DOCKERHUB_TOKEN
script:
- docker pull registry.gitlab.msu.edu/msu-libraries/repo-team/sandhill:latest
- docker tag registry.gitlab.msu.edu/msu-libraries/repo-team/sandhill:latest msulibraries/sandhill:$TAG
- docker tag registry.gitlab.msu.edu/msu-libraries/repo-team/sandhill:latest msulibraries/sandhill:latest
- docker push msulibraries/sandhill:$TAG
- docker push msulibraries/sandhill:latest