forked from icpctools/icpctools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
129 lines (123 loc) · 3.9 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
---
# GitLab build configuration
default:
image: ubuntu:20.04
stages:
- build
- test
- deploy
- website
- docker
build:
image: icpctools/builder
stage: build
rules:
- if: '$CI_COMMIT_REF_NAME != "HEAD"'
when: always
- when: never
script:
- ant build
- echo $CI_JOB_ID > dist/ci_job_id.txt
artifacts:
paths:
- dist/*.*
expire_in: 1 month
test:
stage: test
rules:
- if: '$CI_COMMIT_REF_NAME != "HEAD"'
when: always
- when: never
script:
- echo "Future tests here"
push release to GitHub:
image: icpctools/website
stage: deploy
rules:
- if: '$CI_COMMIT_REF_NAME == "main"'
when: always
- when: never
script:
- export VERSION_PREFIX=$(awk -F '=' '{ print $2 } ' version.properties)
- VERSION=${VERSION_PREFIX}.$(git rev-list $CI_COMMIT_SHA --count)
- RELEASE_COMMIT=$(git rev-parse HEAD)
- |
http --ignore-stdin POST \
https://api.github.com/repos/icpctools/icpctools/releases \
"Authorization: token $GITHUB_TOKEN" \
"Accept: application/vnd.github.v3+json" \
tag_name=v$VERSION \
target_commitish=$RELEASE_COMMIT \
name=v$VERSION \
prerelease:=true | tee ~/new-release.txt
- RELEASE_ID=$(cat ~/new-release.txt | jq .id)
- RELEASE_ASSET_UPLOAD_URL=https://uploads.github.com/repos/icpctools/icpctools/releases/${RELEASE_ID}/assets
- cd $CI_PROJECT_DIR/dist
- echo "Uploading release $VERSION"
- |
for zip in *.zip
do
echo $zip...
cat $zip | http --timeout 300 POST ${RELEASE_ASSET_UPLOAD_URL}\?name=$zip \
"Authorization: token $GITHUB_TOKEN" \
'Accept: application/vnd.github.v3+json' \
'Content-Type: application/zip' | jq .state
echo $zip.sha256...
cat $zip.sha256 | http POST ${RELEASE_ASSET_UPLOAD_URL}\?name=$zip.sha256 \
"Authorization: token $GITHUB_TOKEN" \
'Accept: application/vnd.github.v3+json' \
'Content-Type: text/plain' | jq .state
echo $zip.sha512...
cat $zip.sha512 | http POST ${RELEASE_ASSET_UPLOAD_URL}\?name=$zip.sha512 \
"Authorization: token $GITHUB_TOKEN" \
'Accept: application/vnd.github.v3+json' \
'Content-Type: text/plain' | jq .state
done
update website:
image: icpctools/website
stage: website
rules:
- if: '$CI_COMMIT_REF_NAME == "main"'
when: always
- when: never
before_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY_WEBSITE" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
- git config --global user.email "[email protected]"
- git config --global user.name "ICPC Tools bot"
script:
- website/scripts/populate-releases.py
- website/scripts/copy-readmes.py $CI_PROJECT_DIR/dist
- cp ChangeLog.md website/
- sed -i 's/^# .*//' website/ChangeLog.md
- sed -r 's/^## (.*)/#### \1/' -i website/ChangeLog.md
- mkdir ~/website
- git clone [email protected]:icpctools/icpctools.github.io.git ~/website
- ln -s ~/website $CI_PROJECT_DIR/website/public
- cd $CI_PROJECT_DIR/website
- hugo
- cd ~/website
- git add .
- git commit --allow-empty -m "Update website for icpctools commit $CI_COMMIT_SHA"
- git push
push cds docker image:
image: docker:19.03.12
stage: docker
rules:
- if: '$CI_COMMIT_REF_NAME == "main"'
when: always
- when: never
services:
- docker:19.03.12-dind
before_script:
- apk add git
- docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_ACCESS_TOKEN}
script:
- export VERSION_PREFIX=$(awk -F '=' '{ print $2 } ' version.properties)
- VERSION=${VERSION_PREFIX}.$(git rev-list $CI_COMMIT_SHA --count)
- cd build/cds/Docker
- docker build -t icpctools/cds:${VERSION} --build-arg CDS_VERSION=${VERSION} .
- docker push icpctools/cds:${VERSION}