aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/.github/workflows/ci.yml
blob: 3b95f9f290de2fcc0ea6bece70da2193720e2720 (plain) (blame)
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
name: CI

on:
  push:
  pull_request:
  workflow_dispatch:

jobs:
  test_local:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.6, 3.7, 3.8, 3.9, 3.x]
    name: 'Test: ${{ matrix.python-version }}'
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '${{ matrix.python-version }}'
      - name: Initialize Git
        run: |
          git config --global user.name 'John Doe'
          git config --global user.email 'John.Doe@example.com'
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Integration test (local)
        run: ./test/integration/local/test.sh
      - name: Unit tests
        run: python -m unittest --buffer

  test_example_config:
    runs-on: ubuntu-latest
    name: 'Test: example config'
    env:
      # API request rate limit is easily exceeded otherwise:
      CGITIZE_GITHUB_ACCESS_TOKEN: '${{ secrets.CGITIZE_GITHUB_ACCESS_TOKEN }}'
      # Consider creating a separate user (without my private repositories)
      # for testing Bitbucket).
      #CGITIZE_BITBUCKET_USERNAME: egor-tensin
      #CGITIZE_BITBUCKET_APP_PASSWORD: '${{ secrets.CGITIZE_BITBUCKET_APP_PASSWORD }}'
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Integration test (example config)
        run: ./test/integration/example/test.sh

  test_docker:
    runs-on: ubuntu-latest
    name: 'Test: Docker'
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Integration test (Docker)
        run: ./test/integration/docker/test.sh

  publish_docker:
    needs: [test_local, test_example_config, test_docker]
    runs-on: ubuntu-latest
    name: 'Publish: Docker Hub'
    if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags'))
    steps:
      # https://github.com/docker/metadata-action#semver
      - id: meta
        name: Docker Hub metadata
        uses: docker/metadata-action@v3
        with:
          images: '${{ secrets.DOCKERHUB_USERNAME }}/cgitize'
          flavor: |
            latest=auto
          tags: |
            type=ref,event=branch
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
            type=semver,pattern={{major}}
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: '${{ secrets.DOCKERHUB_USERNAME }}'
          password: '${{ secrets.DOCKERHUB_TOKEN }}'
      - name: Build and publish
        uses: docker/build-push-action@v2
        with:
          platforms: linux/amd64,linux/armhf
          push: true
          tags: '${{ steps.meta.outputs.tags }}'
          labels: '${{ steps.meta.outputs.labels }}'

  publish_pypi:
    needs: [test_local, test_example_config, test_docker, publish_docker]
    runs-on: ubuntu-latest
    name: 'Publish: PyPI'
    env:
      # Same rate limit thing:
      CGITIZE_GITHUB_ACCESS_TOKEN: '${{ secrets.CGITIZE_GITHUB_ACCESS_TOKEN }}'
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
      - name: Verify package can be installed
        run: python3 -m pip install .
      - name: Integration test (example config)
        run: cgitize --config examples/cgitize.toml
      - name: Install package builder
        run: python3 -m pip install --upgrade build
      - name: Build package
        run: python3 -m build
      - name: Publish as artifact
        uses: actions/upload-artifact@v2
        with:
          name: dist
          path: dist
          if-no-files-found: error
      - name: Publish to PyPI
        if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          user: __token__
          password: '${{ secrets.PYPI_API_TOKEN }}'