.gitlab-ci.yml 5.11 KB
Newer Older
Creak's avatar
Creak committed
1
2
image: jangrewe/gitlab-ci-android

3
variables:
Ryan Harg's avatar
Ryan Harg committed
4
5
6
  COBERTURA_REPORT: '$CI_PROJECT_DIR/app/build/reports/cobertura.xml'
  JACOCO_CSV_LOCATION: '$CI_PROJECT_DIR/app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.csv'
  JACOCO_XML_LOCATION: '$CI_PROJECT_DIR/app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml'
Creak's avatar
Creak committed
7

8
9
10
11
12
stages:
  - test
  - visualize
  - build
  - deploy
Creak's avatar
Creak committed
13

14
.gradle-default:
Georg Krause's avatar
Georg Krause committed
15
  before_script:
16
17
18
    - export GRADLE_USER_HOME=$(pwd)/.gradle
    - chmod +x ./gradlew
    - mkdir -p .android && touch .android/repositories.cfg
Georg Krause's avatar
Georg Krause committed
19
  script:
20
    - echo "Overwrite me"
Georg Krause's avatar
Georg Krause committed
21
22
23
24

  cache:
    key: ${CI_PROJECT_ID}
    paths:
25
26
27
      - .gradle/

.build:
28
29
30
  stage: build
  variables:
    apk_file: 'app/build/outputs/apk/debug/app-debug.apk'
31
32
33
    metadata_file: 'metadata/audio.funkwhale.android.dev.yml'
    metadata_template: 'metadata/preview.template.yml'
    output_metadata: 'app/build/outputs/apk/debug/output-metadata.json'
Georg Krause's avatar
Georg Krause committed
34
  before_script: 
Georg Krause's avatar
Georg Krause committed
35
    - git fetch --unshallow --tags
36
37
38
  after_script:
    - export versionCode=`$ANDROID_HOME/build-tools/30.0.2/aapt dump badging $apk_file | grep versionCode | awk '{print $3}' | sed s/versionCode=//g | sed s/\'//g`
    - apt update && apt install gettext-base
39
    - cat $metadata_template | envsubst > $metadata_file
40
41
42
  extends: .gradle-default
  artifacts:
    paths:
43
44
      - $apk_file
      - $metadata_file
45
      - $output_metadata
Georg Krause's avatar
Georg Krause committed
46

47
48
49
test:
  extends: .gradle-default
  stage: test
50
51
  except:
    - tags
52
  script:
Ryan Harg's avatar
Ryan Harg committed
53
    - ./gradlew test jacocoTestReport
54
    - awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' $JACOCO_CSV_LOCATION
Creak's avatar
Creak committed
55
  artifacts:
56
57
    reports:
      junit: app/build/test-results/test**/TEST-*.xml
Creak's avatar
Creak committed
58
    paths:
Ryan Harg's avatar
Ryan Harg committed
59
      - $JACOCO_XML_LOCATION
60
61
62
63
64
65

coverage:
  stage: visualize
  image: gjrtimmer/jacoco2cobertura:1.0.8
  script:
    # convert report from jacoco to cobertura, use relative project path
Ryan Harg's avatar
Ryan Harg committed
66
    - 'python /opt/cover2cover.py $JACOCO_XML_LOCATION $CI_PROJECT_DIR/app/src/main/java > app/build/reports/cobertura.xml'
67
68
69
  needs: [ "test" ]
  dependencies:
    - test
70
71
  except:
    - tags
72
73
  artifacts:
    reports:
Ryan Harg's avatar
Ryan Harg committed
74
      cobertura: $COBERTURA_REPORT
75

Georg Krause's avatar
Georg Krause committed
76
77
78
build-develop:
  extends: .build
  script:
79
80
    - echo -n $PREVIEW_SIGNING_KEY_STORE | base64 -d > app/android.keystore
    - ./gradlew assembleDebug -Psigning.store=android.keystore -Psigning.store_passphrase=$PREVIEW_SIGNING_KEY_PASS -Psigning.key_passphrase=$PREVIEW_SIGNING_KEY_PASS
Georg Krause's avatar
Georg Krause committed
81
  only:
82
    - develop
Georg Krause's avatar
Georg Krause committed
83

84
85
86
87
88
89
90
91
92
93
94
95
96
build-release:
  variables:
    apk_file: 'app/build/outputs/apk/release/app-release.apk'
    output_metadata: 'app/build/outputs/apk/release/output-metadata.json'
    metadata_template: 'metadata/release.template.yml'
    metadata_file: 'metadata/audio.funkwhale.android.yml'
  extends: .build
  script:
    - echo -n $SIGNING_KEY_STORE | base64 -d > app/android.keystore
    - ./gradlew assembleRelease -Psigning.store=android.keystore -Psigning.store_passphrase=$SIGNING_KEY_PASS -Psigning.key_passphrase=$SIGNING_KEY_PASS
  only:
    - tags

Georg Krause's avatar
Georg Krause committed
97
98
99
build-bleeding-edge:
  extends: .build
  script:
100
    - ./gradlew assembleDebug
Georg Krause's avatar
Georg Krause committed
101
  except:
102
    - develop
103
    - tags
Georg Krause's avatar
Georg Krause committed
104

Georg Krause's avatar
Georg Krause committed
105
106
107
.deploy:
  image: debian
  before_script: 
108
    - apt update && apt -y install openssh-server
Georg Krause's avatar
Georg Krause committed
109

110
deploy-develop:
Georg Krause's avatar
Georg Krause committed
111
  extends: .deploy
112
  stage: deploy
113
114
  only:
    - develop
115
  script:
116
117
118
    - eval `ssh-agent -s`
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    - scp -o StrictHostKeyChecking=no app/build/outputs/apk/debug/app-debug.apk fdroid@apps.funkwhale.audio:/srv/fdroid/fdroid/develop/repo/audio.funkwhale.ffa.dev-$CI_COMMIT_SHORT_SHA.apk
119
    - scp -o StrictHostKeyChecking=no app/build/outputs/apk/debug/output-metadata.json fdroid@apps.funkwhale.audio:/srv/fdroid/fdroid/develop/output-metadata.json
120
121
122
123
    - scp -o StrictHostKeyChecking=no metadata/audio.funkwhale.android.dev.yml fdroid@apps.funkwhale.audio:/srv/fdroid/fdroid/develop/metadata/audio.funkwhale.ffa.dev.yml      
    - ssh -o StrictHostKeyChecking=no fdroid@apps.funkwhale.audio 'docker run --rm -u $(id -u):$(id -g) -v /srv/fdroid/fdroid/develop:/repo registry.gitlab.com/fdroid/docker-executable-fdroidserver:master update'

deploy-release:
Georg Krause's avatar
Georg Krause committed
124
  extends: .deploy
125
126
127
128
129
130
131
132
133
134
  stage: deploy
  only:
    - tags
  script:
    - eval `ssh-agent -s`
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
      #- scp -o StrictHostKeyChecking=no app/build/outputs/apk/release/app-release.apk fdroid@apps.funkwhale.audio:/srv/fdroid/fdroid/develop/repo/audio.funkwhale.ffa.-$CI_COMMIT_TAG.apk
    - scp -o StrictHostKeyChecking=no app/build/outputs/apk/release/app-release.apk fdroid@apps.funkwhale.audio:/srv/fdroid/fdroid/develop/repo/audio.funkwhale.ffa.-0.0.1.apk
    - scp -o StrictHostKeyChecking=no app/build/outputs/apk/release/output-metadata.json fdroid@apps.funkwhale.audio:/srv/fdroid/fdroid/develop/output-metadata.json
    - scp -o StrictHostKeyChecking=no metadata/audio.funkwhale.android.yml fdroid@apps.funkwhale.audio:/srv/fdroid/fdroid/develop/metadata/audio.funkwhale.ffa.yml      
135
    - ssh -o StrictHostKeyChecking=no fdroid@apps.funkwhale.audio 'docker run --rm -u $(id -u):$(id -g) -v /srv/fdroid/fdroid/develop:/repo registry.gitlab.com/fdroid/docker-executable-fdroidserver:master update'