.gitlab-ci.yml 5.88 KB
Newer Older
1
2
3
4
5
6
variables:
  POSTGRES_DB: "MaarchParapheur"
  POSTGRES_USER: maarch
  POSTGRES_PASSWORD: ""

stages:
7
  - logs
8
  - test
9
  - synchronization
10
11
12
13
14
15

before_script:
  - apt-get update -yqq > /dev/null
  - apt-get install cron -yqq > /dev/null
  - bash ci/docker_install_php.sh > /dev/null
  - bash ci/docker_install_database.sh > /dev/null
Florian Azizian's avatar
Florian Azizian committed
16
  - mkdir -p /opt/maarchparapheur/docservers/{documents,attachments,signatures,esigned_documents,original_documents}
17
18
  - ln -s $CI_PROJECT_DIR /var/www/html/MaarchParapheur
  - cd /var/www/html/MaarchParapheur
19
  - sed 's!<server>.*</server>!<server>postgres</server>!;s!<password>.*</password>!<password>maarch</password>!;s!<name>.*</name>!<name>MaarchParapheur</name>!;s!<user>.*</user>!<user>maarch</user>!;s!<enable>.*</enable>!<enable>true</enable>!' config/config.xml.default > config/config.xml
20
21
22
23
24
  - sed -i 's/rights="none" pattern="PDF"/rights="read | write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml

job_php-7.4:
  image: php:7.4-apache
  stage: test
25
26
27
  services:
    - name: postgres:10.1
      command: [ "-c", "datestyle=iso,dmy" ]
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  script:
    - curl --location -s --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-9.phar
    - chmod +x /usr/local/bin/phpunit
    - phpunit --coverage-text --colors=never -c phpunit.xml
  only:
    - develop
  except:
    - schedules
  artifacts:
    paths:
      - test/unitTests/build/
    expire_in: 2h

job_php-7.3:
  image: php:7.3-apache
  stage: test
44
45
46
  services:
    - name: postgres:10.1
      command: [ "-c", "datestyle=iso,dmy" ]
47
48
49
50
51
52
53
54
  script:
    - curl --location -s --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-9.phar
    - chmod +x /usr/local/bin/phpunit
    - phpunit --coverage-text --colors=never
  only:
    - develop
  except:
    - schedules
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

commits:
 image: debian:10-slim
 stage: synchronization
 only:
   - master
   - develop
   - "21.03"
 except:
   - tags
   - schedules
 before_script:
   # Skip the synchronisation if it is not enabled
   - if [ $SYNC_ENABLED = "true" ]; then echo "Sync enabled"; else echo "Sync disabled, stopping the job" && exit 0; fi
   # Configure ssh, with the private key to push to the private repository
   - 'which ssh-agent || ( 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 "$GITLAB_URL" >> ~/.ssh/known_hosts
   - chmod 644 ~/.ssh/known_hosts
78
   - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
79
80
81
   # Install git command
   - apt install -y git
 script:
82
83
84
   - chmod +x ./ci/commit_synchronization.sh
   - ./ci/commit_synchronization.sh

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

tags:
 image: debian:10-slim
 stage: synchronization
 only:
   - tags
 except:
   - schedules
 before_script:
   # Skip the synchronisation if it is not enabled
   - if [ $SYNC_ENABLED = "true" ]; then echo "Sync enabled"; else echo "Sync disabled, stopping the job" && exit 0; fi
   # Configure ssh, with the private key to push to the private repository
   - 'which ssh-agent || ( 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 "$GITLAB_URL" >> ~/.ssh/known_hosts
   - chmod 644 ~/.ssh/known_hosts
104
   - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
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
   # Install git and curl command
   - apt install -y git
   - apt install -y curl
   # Install npm
   - curl -sL https://deb.nodesource.com/setup_14.x | bash -
   - apt install -y nodejs
 script:
   - git config --global user.email "$CI_EMAIL" && git config --global user.name "$CI_USER"
   # We will work in another directory, to avoid git conflicts
   - mkdir tmp
   - cd tmp
   # Find the branch name from tag name
   - VERSION1=$(echo $CI_COMMIT_TAG| cut -d'.' -f 1)
   - VERSION2=$(echo $CI_COMMIT_TAG| cut -d'.' -f 2)
   - VERSION="${VERSION1}.${VERSION2}"
   # Pull the private repository
   - git init && git remote add origin $PRIVATE_REPOSITORY_URL_SSH
   - git pull origin $VERSION
   # Update and push build prod
   - npm install
   - npm run build-prod
   - git status
   - git add -f dist/
   - git status
   - git commit -m "Build prod for tag ${CI_COMMIT_TAG}"
   - git show-ref
   - git push origin HEAD:$VERSION
   - git status
   # Do the tag on the private repo
   - git tag $CI_COMMIT_TAG
   - git status
   - git push origin --tags
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177


logs:
  image: debian:10-slim
  stage: logs
  except:
    - schedules
    - tags
    - master
  before_script:
    # Skip the logging if in pro (=> sync disabled)
    - if [ $SYNC_ENABLED = "true" ]; then echo "Sync enabled"; else echo "Sync disabled, stopping the job" && exit 0; fi
    - apt-get update -y
    - apt install -y curl
  script:
    - |
      if [[ $CI_COMMIT_MESSAGE == "FEAT"* ]]; then \
        ISSUE_ID=`echo $CI_COMMIT_MESSAGE | grep -o 'FEAT \#[0-9]*' | grep -o '[0-9]*'`; \
        echo "found FEAT !"; \
      else \
        if [[ $CI_COMMIT_MESSAGE == "FIX"* ]]; then \
          ISSUE_ID=`echo $CI_COMMIT_MESSAGE | grep -o 'FIX \#[0-9]*' | grep -o '[0-9]*'`; \
          echo "found FIX !"; \
        else \
          echo "no FEAT or FIX found :("; \
          exit 0; \
        fi; \
      fi
    - echo $ISSUE_ID
    - NOTE_MESSAGE="Commit ajouté sur la branche **$CI_COMMIT_REF_NAME** de **$CI_PROJECT_NAME**"
    - COMMIT_URL="$CI_PROJECT_URL/commit/$CI_COMMIT_SHA"
    - echo $NOTE_MESSAGE
    - echo "$CI_COMMIT_MESSAGE"
    - CI_COMMIT_MESSAGE=$(echo $CI_COMMIT_MESSAGE) # Remove the line returns
    - echo "$CI_COMMIT_MESSAGE"
    - echo $COMMIT_URL
    - NOTE="$NOTE_MESSAGE \n $CI_COMMIT_MESSAGE \n $COMMIT_URL"
    - echo "$NOTE"
    - BODY="{\"issue\":{\"notes\":\"$NOTE\",\"private_notes\":false}}"
    - echo "$BODY"
    - curl -v -H 'Content-Type:application/json' -H "X-Redmine-API-Key:$REDMINE_API_KEY" -d "$BODY" -X PUT https://forge.maarch.org/issues/$ISSUE_ID.json