forked from psf/httpbin
-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (119 loc) · 4.2 KB
/
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
name: Run CI
on: [push, pull_request]
permissions:
contents: write
packages: write
jobs:
unit-tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev", "pypy-3.8", "pypy-3.9", "pypy-3.10"]
os: [ubuntu-22.04, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# from https://github.com/actions/cache/blob/main/examples.md#python---pip
- name: Get pip cache dir
id: pip-cache
shell: bash
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
# the action does not permit updating an existing cache, so we need
# unique keys
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-pip-
- name: Set up environment & install dependencies
run: |
python -m pip install pip-tools
pip-compile --quiet --generate-hashes --extra mainapp > requirements.txt
python -m pip install --requirement requirements.txt
python -m pip install .[test]
- name: Run tests
run: tox
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/release-') && github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
files: |
requirements.txt
Dockerfile
- name: Store tested requirements.txt file as artifact
uses: actions/upload-artifact@v3
with:
name: requirements.txt
path: |
requirements.txt
publish-docker-image:
runs-on: ubuntu-latest
needs: [unit-tests]
steps:
- name: System Dependencies for Packaging
run: |
sudo apt-get update
sudo apt-get install -y python3-pip python3-venv
python3 -m venv /tmp/tomlq
/tmp/tomlq/bin/pip install --upgrade pip
/tmp/tomlq/bin/pip install yq
- name: Checkout
uses: actions/checkout@v3
- name: Set Environment
run: |
echo "APP_VERSION=$(/tmp/tomlq/bin/tomlq -r .project.version pyproject.toml)" >> $GITHUB_ENV
echo "APP_DESC=$(/tmp/tomlq/bin/tomlq -r .project.description pyproject.toml)" >> $GITHUB_ENV
- name: Retrieve tested requirements file
uses: actions/download-artifact@v3
with:
name: requirements.txt
- name: Build Image
run: >
docker build
--build-arg "APP_VERSION=${APP_VERSION}"
--build-arg "APP_DESC=${APP_DESC}"
-t "ghcr.io/${GITHUB_REPOSITORY}:${APP_VERSION}"
-t "ghcr.io/${GITHUB_REPOSITORY}:latest"
.
# - name: Login to Docker Hub
# if: github.event_name == 'push'
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
if: startsWith(github.ref, 'refs/tags/release-') && github.event_name == 'push'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker Image
if: startsWith(github.ref, 'refs/tags/release-') && github.event_name == 'push'
run: |
docker push "ghcr.io/${GITHUB_REPOSITORY}:${APP_VERSION}"
pypi-publish:
needs: [unit-tests]
if: startsWith(github.ref, 'refs/tags/release-') && github.event_name == 'push'
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/httpbin
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- name: Build distribution
run: |
python -m pip install --upgrade pip build
pyproject-build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1