Sitelet https://github.com/cytopia/docker-mypy/commit/f795d40a3e061ee5aadfd7856297a8e56c252570
Skip to content

Commit f795d40

Browse files
committed
Replace Travis with GitHub Actions
1 parent 7963888 commit f795d40

6 files changed

Lines changed: 506 additions & 107 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
3+
# -------------------------------------------------------------------------------------------------
4+
# Job Name
5+
# -------------------------------------------------------------------------------------------------
6+
name: build
7+
8+
9+
# -------------------------------------------------------------------------------------------------
10+
# When to run
11+
# -------------------------------------------------------------------------------------------------
12+
on:
13+
# Runs on Pull Requests
14+
pull_request:
15+
# Runs on Push
16+
push:
17+
18+
19+
# -------------------------------------------------------------------------------------------------
20+
# What to run
21+
# -------------------------------------------------------------------------------------------------
22+
jobs:
23+
build:
24+
name: "[ ${{ matrix.version }} ]"
25+
runs-on: ubuntu-latest
26+
strategy:
27+
fail-fast: False
28+
matrix:
29+
version:
30+
- 'latest'
31+
steps:
32+
33+
# ------------------------------------------------------------
34+
# Checkout repository
35+
# ------------------------------------------------------------
36+
- name: Checkout repository
37+
uses: actions/checkout@v2
38+
with:
39+
fetch-depth: 0
40+
41+
- name: Set variables
42+
id: vars
43+
run: |
44+
# Retrieve git info (tags, etc)
45+
git fetch --all
46+
47+
# Branch, Tag or Commit
48+
GIT_TYPE="$( \
49+
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
50+
| sh \
51+
| grep '^GIT_TYPE' \
52+
| sed 's|.*=||g' \
53+
)"
54+
# Branch name, Tag name or Commit Hash
55+
GIT_SLUG="$( \
56+
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
57+
| sh \
58+
| grep '^GIT_NAME' \
59+
| sed 's|.*=||g' \
60+
)"
61+
# Docker Tag
62+
if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then
63+
DOCKER_TAG="${VERSION}"
64+
else
65+
DOCKER_TAG="${VERSION}-${GIT_SLUG}"
66+
fi
67+
68+
# Output
69+
echo "GIT_TYPE=${GIT_TYPE}"
70+
echo "GIT_SLUG=${GIT_SLUG}"
71+
echo "DOCKER_TAG=${DOCKER_TAG}"
72+
73+
# Export variable
74+
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
75+
echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV}
76+
echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV}
77+
echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV}
78+
env:
79+
VERSION: ${{ matrix.version }}
80+
81+
82+
# ------------------------------------------------------------
83+
# Build
84+
# ------------------------------------------------------------
85+
- name: Build
86+
run: |
87+
retry() {
88+
for n in $(seq ${RETRIES}); do
89+
echo "[${n}/${RETRIES}] ${*}";
90+
if eval "${*}"; then
91+
echo "[SUCC] ${n}/${RETRIES}";
92+
return 0;
93+
fi;
94+
sleep 2;
95+
echo "[FAIL] ${n}/${RETRIES}";
96+
done;
97+
return 1;
98+
}
99+
retry make build VERSION=${VERSION}
100+
env:
101+
VERSION: ${{ matrix.version }}
102+
RETRIES: 20
103+
104+
- name: Test
105+
run: |
106+
retry() {
107+
for n in $(seq ${RETRIES}); do
108+
echo "[${n}/${RETRIES}] ${*}";
109+
if eval "${*}"; then
110+
echo "[SUCC] ${n}/${RETRIES}";
111+
return 0;
112+
fi;
113+
sleep 2;
114+
echo "[FAIL] ${n}/${RETRIES}";
115+
done;
116+
return 1;
117+
}
118+
retry make test VERSION=${VERSION}
119+
git diff --quiet || { echo "Build Changes"; git diff; git status; false; }
120+
env:
121+
VERSION: ${{ matrix.version }}
122+
RETRIES: 20
123+
124+
125+
# ------------------------------------------------------------
126+
# Deploy
127+
# ------------------------------------------------------------
128+
- name: Publish images (only repo owner)
129+
run: |
130+
retry() {
131+
for n in $(seq ${RETRIES}); do
132+
echo "[${n}/${RETRIES}] ${*}";
133+
if eval "${*}"; then
134+
echo "[SUCC] ${n}/${RETRIES}";
135+
return 0;
136+
fi;
137+
sleep ${PAUSE};
138+
echo "[FAIL] ${n}/${RETRIES}";
139+
done;
140+
return 1;
141+
}
142+
143+
# Output
144+
echo "GIT_TYPE=${GIT_TYPE}"
145+
echo "GIT_SLUG=${GIT_SLUG}"
146+
echo "DOCKER_TAG=${DOCKER_TAG}"
147+
148+
# Tag image
149+
retry make tag TAG=${DOCKER_TAG}
150+
docker images
151+
152+
# Login and Push
153+
retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }}
154+
retry make push TAG=${DOCKER_TAG}
155+
env:
156+
RETRIES: 20
157+
PAUSE: 10
158+
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
159+
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
160+
&& (
161+
(github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
162+
||
163+
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
164+
||
165+
(github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-'))
166+
)

‎.github/workflows/lint.yml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
3+
# -------------------------------------------------------------------------------------------------
4+
# Job Name
5+
# -------------------------------------------------------------------------------------------------
6+
name: lint
7+
8+
9+
# -------------------------------------------------------------------------------------------------
10+
# When to run
11+
# -------------------------------------------------------------------------------------------------
12+
on:
13+
# Runs on Pull Requests
14+
pull_request:
15+
16+
17+
# -------------------------------------------------------------------------------------------------
18+
# What to run
19+
# -------------------------------------------------------------------------------------------------
20+
jobs:
21+
lint:
22+
name: "Lint"
23+
runs-on: ubuntu-latest
24+
steps:
25+
# ------------------------------------------------------------
26+
# Setup repository
27+
# ------------------------------------------------------------
28+
- name: Checkout repository
29+
uses: actions/checkout@v2
30+
with:
31+
fetch-depth: 0
32+
33+
# ------------------------------------------------------------
34+
# Lint repository
35+
# ------------------------------------------------------------
36+
- name: Lint
37+
id: vars
38+
run: |
39+
make lint
40+

‎.github/workflows/nightly.yml‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
3+
# -------------------------------------------------------------------------------------------------
4+
# Job Name
5+
# -------------------------------------------------------------------------------------------------
6+
name: nightly
7+
8+
9+
# -------------------------------------------------------------------------------------------------
10+
# When to run
11+
# -------------------------------------------------------------------------------------------------
12+
on:
13+
# Runs daily
14+
schedule:
15+
- cron: '0 0 * * *'
16+
17+
18+
# -------------------------------------------------------------------------------------------------
19+
# What to run
20+
# -------------------------------------------------------------------------------------------------
21+
jobs:
22+
nightly:
23+
name: "[ ${{ matrix.version }} ] (ref: ${{ matrix.refs }})"
24+
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: False
27+
matrix:
28+
version:
29+
- 'latest'
30+
refs:
31+
- 'master'
32+
steps:
33+
34+
# ------------------------------------------------------------
35+
# Checkout repository
36+
# ------------------------------------------------------------
37+
- name: Checkout repository
38+
uses: actions/checkout@v2
39+
with:
40+
fetch-depth: 0
41+
ref: ${{ matrix.refs }}
42+
43+
- name: Set variables
44+
id: vars
45+
run: |
46+
# Retrieve git info (tags, etc)
47+
git fetch --all
48+
49+
# Branch, Tag or Commit
50+
GIT_TYPE="$( \
51+
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
52+
| sh \
53+
| grep '^GIT_TYPE' \
54+
| sed 's|.*=||g' \
55+
)"
56+
# Branch name, Tag name or Commit Hash
57+
GIT_SLUG="$( \
58+
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
59+
| sh \
60+
| grep '^GIT_NAME' \
61+
| sed 's|.*=||g' \
62+
)"
63+
# Docker Tag
64+
if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then
65+
DOCKER_TAG="${VERSION}"
66+
else
67+
DOCKER_TAG="${VERSION}-${GIT_SLUG}"
68+
fi
69+
70+
# Output
71+
echo "GIT_TYPE=${GIT_TYPE}"
72+
echo "GIT_SLUG=${GIT_SLUG}"
73+
echo "DOCKER_TAG=${DOCKER_TAG}"
74+
75+
# Export variable
76+
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
77+
echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV}
78+
echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV}
79+
echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV}
80+
env:
81+
VERSION: ${{ matrix.version }}
82+
83+
84+
# ------------------------------------------------------------
85+
# Build
86+
# ------------------------------------------------------------
87+
- name: Build
88+
run: |
89+
retry() {
90+
for n in $(seq ${RETRIES}); do
91+
echo "[${n}/${RETRIES}] ${*}";
92+
if eval "${*}"; then
93+
echo "[SUCC] ${n}/${RETRIES}";
94+
return 0;
95+
fi;
96+
sleep 2;
97+
echo "[FAIL] ${n}/${RETRIES}";
98+
done;
99+
return 1;
100+
}
101+
retry make build VERSION=${VERSION}
102+
env:
103+
VERSION: ${{ matrix.version }}
104+
RETRIES: 20
105+
106+
- name: Test
107+
run: |
108+
retry() {
109+
for n in $(seq ${RETRIES}); do
110+
echo "[${n}/${RETRIES}] ${*}";
111+
if eval "${*}"; then
112+
echo "[SUCC] ${n}/${RETRIES}";
113+
return 0;
114+
fi;
115+
sleep 2;
116+
echo "[FAIL] ${n}/${RETRIES}";
117+
done;
118+
return 1;
119+
}
120+
retry make test VERSION=${VERSION}
121+
git diff --quiet || { echo "Build Changes"; git diff; git status; false; }
122+
env:
123+
VERSION: ${{ matrix.version }}
124+
RETRIES: 20
125+
126+
127+
# ------------------------------------------------------------
128+
# Deploy
129+
# ------------------------------------------------------------
130+
- name: Publish images (only repo owner)
131+
run: |
132+
retry() {
133+
for n in $(seq ${RETRIES}); do
134+
echo "[${n}/${RETRIES}] ${*}";
135+
if eval "${*}"; then
136+
echo "[SUCC] ${n}/${RETRIES}";
137+
return 0;
138+
fi;
139+
sleep ${PAUSE};
140+
echo "[FAIL] ${n}/${RETRIES}";
141+
done;
142+
return 1;
143+
}
144+
145+
# Output
146+
echo "GIT_TYPE=${GIT_TYPE}"
147+
echo "GIT_SLUG=${GIT_SLUG}"
148+
echo "DOCKER_TAG=${DOCKER_TAG}"
149+
150+
# Tag image
151+
retry make tag TAG=${DOCKER_TAG}
152+
docker images
153+
154+
# Login and Push
155+
retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }}
156+
retry make push TAG=${DOCKER_TAG}
157+
env:
158+
RETRIES: 20
159+
PAUSE: 10
160+
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
161+
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
162+
&& (
163+
(github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
164+
||
165+
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
166+
||
167+
(github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-'))
168+
)

0 commit comments

Comments
 (0)