summaryrefslogtreecommitdiffstats
path: root/.circleci/config.yml
blob: c818976bb26027a5d64358250853200919b07430 (plain)
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
134
135
136
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
version: 2.1

executors:
  docker-publisher:
    environment:
      IMAGE_NAME: bukuserver/bukuserver
    docker:
      - image: circleci/buildpack-deps:stretch

test-template: &test-template
  working_directory: ~/Buku
  environment:
    CI_FORCE_TEST: 1
  steps:
    - run: &init
        command: |
          apt update && apt install -y --no-install-recommends git
          pip install --upgrade pip
          pip install --upgrade setuptools flake8 pylint
    - checkout
    - run: &deps
        command: |
          pip install -e .[tests]
          pip install -r requirements.txt
    - run:
        command:
          python3 -m pytest ./tests/test_*.py --cov buku -vv --durations=0 -c ./tests/pytest.ini

lint-template: &lint-template
  working_directory: ~/Buku
  environment:
    CI_FORCE_TEST: 1
  steps:
    - run: *init
    - checkout
    - run: *deps
    - run:
        command: |
          python3 -m flake8
          echo buku | xargs pylint --rcfile tests/.pylintrc
          find . -iname "*.py" ! -path "./api/*" | xargs pylint --rcfile tests/.pylintrc

jobs:
  lint:
    docker:
      - image: python:3.11-slim
    <<: *lint-template

  py38:
    docker:
      - image: python:3.8-slim
    <<: *test-template

  py39:
    docker:
      - image: python:3.9-slim
    <<: *test-template

  py310:
    docker:
      - image: python:3.10-slim
    <<: *test-template

  py311:
    docker:
      - image: python:3.11-slim
    <<: *test-template

#  package-and-publish:
#    machine: true
#    working_directory: ~/Buku
#    steps:
#      - checkout
#      - run:
#          name: "package with packagecore"
#          command: |
#            # Use latest installed python3 from pyenv
#            export PYENV_VERSION="$(pyenv versions | grep -Po '\b3\.\d+\.\d+' | tail -1)"
#            pip install packagecore
#            packagecore -o ./dist/ ${CIRCLE_TAG#v}
#      - run:
#          name: "publish to GitHub"
#          command: |
#            go get github.com/tcnksm/ghr
#            ghr -t ${GITHUB_API_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace ${CIRCLE_TAG} ./dist/

  build-docker-image:
    executor: docker-publisher
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Build Docker image
          command: docker build -t $IMAGE_NAME:latest .
      - run:
          name: Archive Docker image
          command: docker save -o image.tar $IMAGE_NAME
      - persist_to_workspace:
          root: .
          paths:
            - ./image.tar

  publish-on-docker-hub:
    executor: docker-publisher
    steps:
      - attach_workspace:
          at: /tmp/workspace
      - setup_remote_docker
      - run:
          name: Load archived Docker image
          command: docker load -i /tmp/workspace/image.tar
      - run:
          name: Publish Docker Image to Docker Hub
          command: |
            echo "${DOCKERHUB_PASS}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
            docker push ${IMAGE_NAME}:latest

workflows:
  version: 2.1

  CircleCI:
    jobs: &all-tests
      - lint
      - py38
      - py39
      - py310
      - py311

  nightly:
    triggers:
      - schedule:
          cron: "0 0 * * 6"
          filters:
            branches:
              only:
                - master
    jobs: *all-tests

#  publish-github-release:
#    jobs:
#      - package-and-publish:
#          filters:
#            tags:
#              only: /^v.*/
#            branches:
#              ignore: /.*/

  publish-docker-image:
    jobs:
      - build-docker-image:
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
      - publish-on-docker-hub:
          requires:
            - build-docker-image
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/