-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
139 lines (133 loc) · 4.26 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
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS"
when: never
- if: "$CI_COMMIT_BRANCH || $CI_COMMIT_TAG"
stages:
- test
- format
- output
- push
execute changes:
stage: test
tags:
- docker
image: python:3.10
script:
- apt-get update && apt-get install -y libgl1-mesa-dev
- pip install pipenv
- pipenv install --skip-lock
- |-
for NBPATH in $(git diff --name-only HEAD^..HEAD | grep '.ipynb' | grep -v 'demo'); do
echo "[NbConvertApp] Executing notebook $NBPATH"
OUTPUT=$(pipenv run jupyter nbconvert --to html --stdout --execute "$NBPATH" --log-level WARN 2>&1 >/dev/null) || true
if [ -n "$OUTPUT" ]; then
echo "$OUTPUT" 1>&2
STATUS=1
fi
done
rules:
- changes:
- notebooks/**/*.ipynb
execute all:
stage: test
tags:
- docker
image: python:3.10
script:
- apt-get update && apt-get install -y libgl1-mesa-dev
- pip install pipenv
- pipenv install --skip-lock
- |-
for NBPATH in $(/bin/ls -1 notebooks/{en,ja}/{tutorials,examples}/*.ipynb); do
echo "[NbConvertApp] Executing notebook $NBPATH"
OUTPUT=$(pipenv run jupyter nbconvert --to html --stdout --execute "$NBPATH" --log-level WARN 2>&1 >/dev/null) || true
if [ -n "$OUTPUT" ]; then
echo "$OUTPUT" 1>&2
STATUS=1
fi
done
- if [ -n "$STATUS" ]; then exit 1; fi
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
changes:
- notebooks/**/*.ipynb
when: on_success
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
when: manual
allow_failure: true
format:
stage: format
tags:
- docker
image: python:3.10
script:
- git remote set-url origin https://gitlab-ci-token:$GITLAB_API_ACCESS_TOKEN@${CI_REPOSITORY_URL##*@}
- git config user.email "[email protected]"
- git config user.name "GitLab Bot"
- git fetch origin $CI_COMMIT_REF_NAME
- git switch -C $CI_COMMIT_REF_NAME origin/$CI_COMMIT_REF_NAME
- git clean -xfd
- apt-get update && apt-get install -y jq
- pip install pipenv
- pipenv install --skip-lock
- pipenv run ./format.sh
- git add -u
- |-
if [ $(git status -s -uno --ignore-submodules=all | wc -l) -gt 0 ]; then
git commit -m "🎨 Format"
git push origin $CI_COMMIT_REF_NAME
exit 1
fi
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
html:
stage: output
tags:
- docker
image: python:3.10
script:
- git remote set-url origin https://gitlab-ci-token:$GITLAB_API_ACCESS_TOKEN@${CI_REPOSITORY_URL##*@}
- git config user.email "[email protected]"
- git config user.name "GitLab Bot"
- git fetch origin $CI_COMMIT_REF_NAME
- git switch -C $CI_COMMIT_REF_NAME origin/$CI_COMMIT_REF_NAME
- git clean -xfd
- pip install pipenv
- pipenv install --skip-lock
- rm -rf html
- pipenv run ./make-html.sh
- git add -u
- |-
if [ $(git status -s -uno --ignore-submodules=all | wc -l) -gt 0 ]; then
git commit -m "📝 Update html files"
git push origin $CI_COMMIT_REF_NAME
exit 1
fi
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
sync-repositories:
stage: push
tags:
- docker
image: bitnami/git
resource_group: git-push
script:
# prepare remote repositories
- git remote set-url origin https://gitlab-ci-token:$GITLAB_API_ACCESS_TOKEN@${CI_REPOSITORY_URL##*@}
- git config remote.github.url >&- && git remote set-url github https://$GITHUB_USERNAME:[email protected]/fixstars/amplify-examples.git || git remote add github https://$GITHUB_USERNAME:[email protected]/fixstars/amplify-examples.git
- git config user.email "[email protected]"
- git config user.name "GitLab Bot"
- git fetch github main
- git fetch origin main develop
- git switch -C develop origin/develop
- git clean -xfd
# rebase and push
- git status
- git rebase github/main
- git push origin develop
- git push origin develop:main
- git push github develop:main
rules:
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "develop"'