-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (103 loc) · 3.66 KB
/
docker-publish.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
129
130
131
132
133
name: Docker
on:
push:
pull_request:
env:
IMAGE_NAME: pylerplate
jobs:
test:
runs-on: ubuntu-latest
env:
POETRY_VERSION: '1.8.1'
PYTHON_VERSION: '3.12.3'
PIP_DISABLE_PIP_VERSION_CHECK: 1
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
# libcurl4-openssl-dev - for pycurl
# gettext-base - for envsubst
packages: libcurl4-openssl-dev gettext-base
version: 2.0
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.local
key: poetry-1
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: Ensure `~/.local/bin` is in PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: poetry
cache-dependency-path: poetry.lock
- name: Set Poetry environment
run: poetry env use $PYTHON_VERSION
- name: Set VIRTUAL_ENV
run: echo "VIRTUAL_ENV=$(poetry env info -p)" >> $GITHUB_ENV
- run: poetry install --no-root
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: pre-commit
run: poetry run pre-commit run -a --show-diff-on-failure --color=always
- run: |
poetry run pytest \
--junitxml=pytest.xml \
--cov --cov-report=term-missing:skip-covered \
2>&1 | tee pytest-cov.txt; exit ${PIPESTATUS[0]}
if: ${{ always() }}
- name: Get Coverage
if: ${{ always() }}
uses: MishaKav/pytest-coverage-comment@main
continue-on-error: true
with:
junitxml-path: pytest.xml
pytest-coverage-path: pytest-cov.txt
default-branch: master
github-token: ${{ secrets.GITHUB_TOKEN }}
# Uncomment to enable SSH to Actions
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
# if: ${{ failure() }}
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
permissions: write-all
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION