-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.gitlab-ci.yml
133 lines (124 loc) · 4.12 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
image: registry.gitlab.com/portlandlabs/containers/php/8.2:latest
stages:
- test
- build
- deploy
# Gitlab provided testing
include:
- template: SAST.gitlab-ci.yml
- template: Dependency-Scanning.gitlab-ci.yml
# - template: License-Scanning.gitlab-ci.yml
.ssh_key_setup: &ssh_key_setup
- composer config gitlab-token.gitlab.com gitlab-ci-token ${CI_JOB_TOKEN}
# Adding support for ssh keys in order to download packages from bitbucket.
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "[email protected]"
- git config --global user.name "Gitlab CI"
# # Test with PHPUnit
# test:phpunit:
# stage: test
# rules:
# - if: $CI_PIPELINE_SOURCE == 'external_pull_request_event' || $CI_PIPELINE_SOURCE == 'push'
# cache:
# paths:
# - vendor/
# artifacts:
# reports:
# junit: junit.xml
# coverage_report:
# coverage_format: cobertura
# path: coverage.cobertura.xml
# before_script:
# - *ssh_key_setup
# - composer install --dev --no-interaction --optimize-autoloader
# script:
# - XDEBUG_MODE=coverage vendor/bin/phpunit --configuration phpunit.xml.dist --log-junit=junit.xml --coverage-text --colors=never --coverage-cobertura=coverage.cobertura.xml
# # Test with PHPCS
# test:phpcs:
# stage: test
# rules:
# - if: $CI_PIPELINE_SOURCE == 'external_pull_request_event' || $CI_PIPELINE_SOURCE == 'push'
# cache:
# paths:
# - vendor/
# artifacts:
# reports:
# junit: junit.xml
# codequality: phpcs-quality-report.json
# before_script:
# - *ssh_key_setup
# - composer install --no-interaction --optimize-autoloader
# script:
# - >
# vendor/bin/phpcs --basepath=.
# --report=code --report-junit=junit.xml --report-\\Micheh\\PhpCodeSniffer\\Report\\Gitlab=phpcs-quality-report.json
# phpcs.xml.dist tests public/application
build:tar:
stage: build
needs: []
cache:
- key:
files:
- composer.lock
paths:
- vendor/
artifacts:
paths:
- release.tar.gz
rules:
- if: $CI_COMMIT_BRANCH =~ /(develop|master)/
before_script:
- *ssh_key_setup
# Install production dependencies
- composer install --no-dev --no-interaction --optimize-autoloader
# Load in the concrete_cms_auth package
- git clone --branch=1.0.1 https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/portlandlabs/addons/concrete_cms_auth.git
- rm -rf public/packages/concrete_cms_auth/.git
script:
# Delete anything we don't want to include in the tar
- rm -rf tests resources
- tar -zcvf /builds/release.tar.gz .
# Move the built tar to the correct location. This also verifies the file was created.
- mv /builds/release.tar.gz $CI_PROJECT_DIR/release.tar.gz
.job_template: &deploy
stage: deploy
cache:
- key:
files:
- composer.lock
paths:
- vendor/
before_script:
- apt-get update && apt-get install gettext-base
# Write GitLab Variables into the .codedeployvars file
- tar -xzf release.tar.gz ./.codedeployvars && mv .codedeployvars .codedeployvars.template
- envsubst < .codedeployvars.template > .codedeployvars
# Update appspec with environment variables
- tar -xzf release.tar.gz ./appspec.yml && mv appspec.yml appspec.yml.template
- envsubst < appspec.yml.template > appspec.yml
# Pack the files back into the tar
- gunzip release.tar.gz
- tar -rf release.tar ./.codedeployvars
- tar -rf release.tar appspec.yml
- gzip release.tar
script:
- deploy release.tar.gz
deploy:stage:
<<: *deploy
environment:
name: Stage deploy
rules:
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == 'develop'
deploy:production:
<<: *deploy
environment:
name: Production deploy
when: manual
rules:
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == 'master'