-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
182 lines (169 loc) · 4.67 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
image: fedora:latest
stages:
- build_docker
- build_pdf
- build_png
- deploy
variables:
DOCKER_DRIVER: overlay2
IMAGE_TAG: $CI_REGISTRY_IMAGE:fedora-texlive
GIT_HOST: github.com
#GIT_HOST: gitlab.com
# YAML anchor for all jobs build exceptions. This keeps the CI
# from looping on itself, since we have it commit back to the repo
# to update the PNG/PDF files
.build_exceptions: &build_exceptions
except:
variables:
- $CI_COMMIT_MESSAGE =~ /\[CI\]/
#####################################
# Build Fedora texlive image
####################################
build_docker: &build_docker
<<: *build_exceptions
image: docker:stable
stage: build_docker
services:
- docker:stable-dind
before_script:
- echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
# - apk --no-cache add make
script:
- docker build -t "${IMAGE_TAG}" .
- docker push "${IMAGE_TAG}"
# after_script:
# - cat build.log
when: manual
only:
- web
####################################
# Build template
####################################
.build_artifacts: &build_artifacts
<<: *build_exceptions
image:
name: $IMAGE_TAG
entrypoint: []
services: []
variables:
GIT_STRAGEGY: fetch
GIT_CHECKOUT: "true"
after_script:
- cat build.log
####################################
# Build PDF
####################################
build_pdf:
<<: *build_artifacts
stage: build_pdf
script:
- rm -f *.pdf
- make resume.pdf
artifacts:
expire_in: '300'
paths:
- '*.pdf'
####################################
# Build PNG
####################################
build_png:
<<: *build_artifacts
stage: build_png
script:
- rm *.png
- make resume.png
dependencies:
- build_pdf
artifacts:
expire_in: '300'
paths:
- '*.png'
####################################
# Deploy
####################################
deploy:
<<: *build_exceptions
stage: deploy
variables:
DEPENDENCIES: >-
ssh-agent
ssh-keyscan
git
curl
file
jq
before_script:
- RELEASE_TAG=$(date +'%F-%H-%M')
# Compose a JSON string to be used with the release creation cURL later
- |-
API_JSON=$(
printf '{ "tag_name": "%s", "body": "%s", "draft": false, "prerelease": false }' \
"${RELEASE_TAG}" "Latest Release of my Resume as of: ${RELEASE_TAG}"
)
# Build a list of dependencies to pass to DNF
- |-
for i in ${DEPENDENCIES};
do command -v "${i}" || INSTALL_PKGS+=" /usr/bin/${i}"
done
# Speed things up by removing the modular repos (so they don't download metadata)
- rm -f /etc/*.repos.d/*-modular.repo
- dnf install -q -y ${INSTALL_PKGS}
- eval $(ssh-agent -s)
- set +x; echo "$GIT_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan ${GIT_HOST} >> ~/.ssh/known_hosts
script:
- git remote set-url origin "git@${GIT_HOST}:${CI_PROJECT_PATH}"
- git config user.name "Gitlab-CI"
- git config user.email "[email protected]"
- git checkout ${CI_COMMIT_REF_NAME}
- git add resume.pdf resume-*.png
- "git commit -m \"[CI]: Update PNG/PDF files in repository\""
- git push -u origin ${CI_COMMIT_REF_NAME}
- git tag ${RELEASE_TAG}
- git push --tags
# Create the release
- |-
API_RESPONSE=$(
curl -sS --data "${API_JSON}" \
"https://api.${GIT_HOST}/repos/${CI_PROJECT_PATH}/releases?access_token=${GITHUB_TOKEN}" \
)
echo "$API_RESPONSE" | jq -CS .
- API_ASSET_URL=$( echo "$API_RESPONSE" | jq -r '.upload_url|split("{")[0]' )
- |-
for i in resume.pdf resume*.png; do
curl -sS \
--user "${CI_PROJECT_NAMESPACE}:${GITHUB_TOKEN}" \
--header "Content-Type: $( file -b --mime-type ${i} )" \
--upload-file "${i}" \
-X POST "${API_ASSET_URL}?name=${i}" \
| jq -CS .
done
dependencies:
- build_pdf
- build_png
artifacts:
paths:
- '*.png'
- '*.pdf'
only:
- master
- tags
####################################
# Restore pipeline status
####################################
mock_build_status:
stage: deploy
image: alpine:latest
variables:
GIT_STRATEGY: none
script:
# Since this CI pipeline commits back into the repo, but doesn't run a futher pipeline, the status remains "Unknown"
# This restores the correct status of the pipeline badge, as in order to run this job, everything prior must have
# already been successful anyway, so the status isn't meaningless just because we're mocking it
- 'true'
only:
variables:
- $CI_COMMIT_MESSAGE =~ /\[CI\]/