3
3
# -------------------------------------------------------------------------------------------------
4
4
# Job Name
5
5
# -------------------------------------------------------------------------------------------------
6
- name : PHP-CI
6
+ name : build
7
7
8
8
9
9
# -------------------------------------------------------------------------------------------------
@@ -12,55 +12,14 @@ name: PHP-CI
12
12
on :
13
13
# Runs on Pull Requests
14
14
pull_request :
15
-
16
- # Runs on master Branch and Tags
15
+ # Runs on Push
17
16
push :
18
- branches :
19
- - master
20
- tags :
21
- - ' [0-9]+.[0-9]+*'
22
17
23
18
24
19
# -------------------------------------------------------------------------------------------------
25
20
# What to run
26
21
# -------------------------------------------------------------------------------------------------
27
22
jobs :
28
- diagnostics :
29
- name : Diagnostics
30
- runs-on : ubuntu-latest
31
- strategy :
32
- fail-fast : False
33
- steps :
34
- - name : Checkout repository
35
- uses : actions/checkout@v2
36
-
37
- - name : Show environment
38
- run : |
39
- env
40
-
41
- # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context
42
- - name : Show GitHub variables
43
- run : |
44
- echo "github.actor: ${{ github.actor }}"
45
- echo "github.ref: ${{ github.ref }}"
46
- echo "github.base_ref: ${{ github.base_ref }}"
47
- echo "github.head_ref: ${{ github.head_ref }}"
48
- echo "github.event: ${{ github.event }}"
49
- echo "github.event_name: ${{ github.event_name }}"
50
- echo "github.event.pull_request.base.repo.id: ${{ github.event.pull_request.base.repo.id }}"
51
- echo "github.event.pull_request.head.repo.id: ${{ github.event.pull_request.head.repo.id }}"
52
-
53
- - name : Dump GitHub context
54
- env :
55
- GITHUB_CONTEXT : ${{ toJson(github) }}
56
- run : echo "${GITHUB_CONTEXT}"
57
-
58
- - name : Dump Runner context
59
- env :
60
- RUNNER_CONTEXT : ${{ toJson(runner) }}
61
- run : echo "${RUNNER_CONTEXT}"
62
-
63
-
64
23
build :
65
24
name : " [ PHP-${{ matrix.version }} ]"
66
25
runs-on : ubuntu-latest
83
42
steps :
84
43
85
44
# ------------------------------------------------------------
86
- # Checkout repository
45
+ # Setup repository
87
46
# ------------------------------------------------------------
88
47
- name : Checkout repository
89
48
uses : actions/checkout@v2
97
56
# Retrieve git info (tags, etc)
98
57
git fetch --all
99
58
100
- # BRANCH, TAG or COMMIT
59
+ # Branch, Tag or Commit
101
60
GIT_TYPE="$( \
102
61
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
103
62
| sh \
@@ -111,15 +70,37 @@ jobs:
111
70
| grep '^GIT_NAME' \
112
71
| sed 's|.*=||g' \
113
72
)"
73
+ # Docker Tag
74
+ if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then
75
+ DOCKER_TAG_BASE="${VERSION}-base"
76
+ DOCKER_TAG_MODS="${VERSION}-mods"
77
+ DOCKER_TAG_PROD="${VERSION}-prod"
78
+ DOCKER_TAG_WORK="${VERSION}-work"
79
+ else
80
+ DOCKER_TAG_BASE="${VERSION}-base-${GIT_SLUG}"
81
+ DOCKER_TAG_MODS="${VERSION}-mods-${GIT_SLUG}"
82
+ DOCKER_TAG_PROD="${VERSION}-prod-${GIT_SLUG}"
83
+ DOCKER_TAG_WORK="${VERSION}-work-${GIT_SLUG}"
84
+ fi
114
85
115
86
# Output
116
87
echo "GIT_TYPE=${GIT_TYPE}"
117
88
echo "GIT_SLUG=${GIT_SLUG}"
89
+ echo "DOCKER_TAG_BASE=${DOCKER_TAG_BASE}"
90
+ echo "DOCKER_TAG_MODS=${DOCKER_TAG_MODS}"
91
+ echo "DOCKER_TAG_PROD=${DOCKER_TAG_PROD}"
92
+ echo "DOCKER_TAG_WORK=${DOCKER_TAG_WORK}"
118
93
119
94
# Export variable
120
95
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
121
- echo "GIT_TYPE=${GIT_TYPE}" >> $GITHUB_ENV
122
- echo "GIT_SLUG=${GIT_SLUG}" >> $GITHUB_ENV
96
+ echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV}
97
+ echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV}
98
+ echo "DOCKER_TAG_BASE=${DOCKER_TAG_BASE}" >> ${GITHUB_ENV}
99
+ echo "DOCKER_TAG_MODS=${DOCKER_TAG_MODS}" >> ${GITHUB_ENV}
100
+ echo "DOCKER_TAG_PROD=${DOCKER_TAG_PROD}" >> ${GITHUB_ENV}
101
+ echo "DOCKER_TAG_WORK=${DOCKER_TAG_WORK}" >> ${GITHUB_ENV}
102
+ env :
103
+ VERSION : ${{ matrix.version }}
123
104
124
105
125
106
# ------------------------------------------------------------
@@ -139,6 +120,7 @@ jobs:
139
120
done;
140
121
return 1;
141
122
}
123
+ retry make _pull-base-image VERSION=${VERSION}
142
124
retry make build-base VERSION=${VERSION}
143
125
env :
144
126
VERSION : ${{ matrix.version }}
@@ -310,9 +292,8 @@ jobs:
310
292
311
293
312
294
# ------------------------------------------------------------
313
- # Push build artifacts
295
+ # Deploy
314
296
# ------------------------------------------------------------
315
- # Only run this, if the PR was created by the repo owner
316
297
- name : Publish images (only repo owner)
317
298
run : |
318
299
retry() {
@@ -328,42 +309,39 @@ jobs:
328
309
return 1;
329
310
}
330
311
331
- # Info output
332
- echo "Git Type: ${GIT_TYPE}"
333
- echo "Git Slug: ${GIT_SLUG}"
312
+ # Output
313
+ echo "GIT_TYPE=${GIT_TYPE}"
314
+ echo "GIT_SLUG=${GIT_SLUG}"
315
+ echo "DOCKER_TAG_BASE=${DOCKER_TAG_BASE}"
316
+ echo "DOCKER_TAG_MODS=${DOCKER_TAG_MODS}"
317
+ echo "DOCKER_TAG_PROD=${DOCKER_TAG_PROD}"
318
+ echo "DOCKER_TAG_WORK=${DOCKER_TAG_WORK}"
319
+
320
+ # Tag image
321
+ retry make tag OLD_TAG="${VERSION}-base" NEW_TAG="${DOCKER_TAG_BASE}"
322
+ retry make tag OLD_TAG="${VERSION}-mods" NEW_TAG="${DOCKER_TAG_MODS}"
323
+ retry make tag OLD_TAG="${VERSION}-prod" NEW_TAG="${DOCKER_TAG_PROD}"
324
+ retry make tag OLD_TAG="${VERSION}-work" NEW_TAG="${DOCKER_TAG_WORK}"
325
+ docker images
334
326
335
327
# Login
336
- echo " retry make login USER= PASS="
328
+ retry make login USERNAME=${{ secrets.DOCKERHUB_USERNAME }} PASSWORD=${{ secrets.DOCKERHUB_PASSWORD }}
337
329
338
330
# Push
339
- if [ "${GIT_TYPE}" = "TAG" ]; then
340
- echo "retry make push-base VERSION=${VERSION}-${GIT_SLUG}"
341
- echo "retry make push-mods VERSION=${VERSION}-${GIT_SLUG}"
342
- echo "retry make push-prod VERSION=${VERSION}-${GIT_SLUG}"
343
- echo "retry make push-work VERSION=${VERSION}-${GIT_SLUG}"
344
- else
345
- if [ "${GIT_SLUG}" = "master" ]; then
346
- echo "retry make push-base VERSION=${VERSION}"
347
- echo "retry make push-mods VERSION=${VERSION}"
348
- echo "retry make push-prod VERSION=${VERSION}"
349
- echo "retry make push-work VERSION=${VERSION}"
350
- else
351
- echo "retry make push-base VERSION=${VERSION}-${GIT_SLUG}"
352
- echo "retry make push-mods VERSION=${VERSION}-${GIT_SLUG}"
353
- echo "retry make push-prod VERSION=${VERSION}-${GIT_SLUG}"
354
- echo "retry make push-work VERSION=${VERSION}-${GIT_SLUG}"
355
- fi
356
- fi
331
+ retry make push TAG=${DOCKER_TAG_BASE}
332
+ retry make push TAG=${DOCKER_TAG_MODS}
333
+ retry make push TAG=${DOCKER_TAG_PROD}
334
+ retry make push TAG=${DOCKER_TAG_WORK}
357
335
env :
358
336
VERSION : ${{ matrix.version }}
359
337
RETRIES : 20
360
338
PAUSE : 10
361
339
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
362
340
if : github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
363
341
&& (
364
- (github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
342
+ (github.event_name == 'schedule' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
365
343
||
366
- (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
344
+ (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
367
345
||
368
- (github.event_name == 'pull_request' && ( startsWith(github.head_ref , 'release-') ))
346
+ (github.event_name == 'push' && startsWith(github.ref , 'refs/heads/ release-'))
369
347
)
0 commit comments