Skip to content

Commit 0576887

Browse files
committed
Replace Travis CI with GitHub Actions
1 parent b93e411 commit 0576887

7 files changed

Lines changed: 584 additions & 296 deletions

File tree

.github/workflows/build.yml

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

.github/workflows/lint.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 Files
37+
run: |
38+
make lint-files
39+
40+
# ------------------------------------------------------------
41+
# Lint Workflow
42+
# ------------------------------------------------------------
43+
- name: Lint Workflow
44+
run: |
45+
make lint-workflow

.github/workflows/mysql-ci.yml

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)