-
-
Notifications
You must be signed in to change notification settings - Fork 87
161 lines (142 loc) · 5.47 KB
/
main.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
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
name: Python application and Docker image CI
on:
push:
branches: [ master, develop ]
tags: [ '*.*.*' ] # Enable pipeline on tag pushes
pull_request:
branches: [ master, develop ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get -qq update
sudo apt-get install -y libemail-outlook-message-perl
pip install ".[dev, test]"
export PERL_MM_USE_DEFAULT=1
sudo cpan -f -i Email::Outlook::Message
- name: Run tests
env:
PYTHONPATH: src
run: |
pytest --cov=mailparser --cov-report=xml
python -m mailparser -v
python -m mailparser -h
mail-parser -f tests/mails/mail_malformed_3 -j
cat tests/mails/mail_malformed_3 | mail-parser -k -j
- name: Run pre-commit
if: matrix.python-version == '3.10'
run: |
make pre-commit
- name: Report to Coveralls
if: matrix.python-version == '3.10'
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build
if: matrix.python-version == '3.10'
run: |
python -m build
- name: Upload artifacts
if: matrix.python-version == '3.10'
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
dist/mail-parser-*.tar.gz
dist/mail_parser-*.whl
- name: Publish to PyPI
if: matrix.python-version == '3.10' && startsWith(github.ref, 'refs/tags/')
uses: pypa/[email protected]
with:
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}
docker:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract branch or tag name
id: extract_ref
run: |
if [ -n "${GITHUB_HEAD_REF}" ]; then
REF_NAME=${GITHUB_HEAD_REF}
else
REF_NAME=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --abbrev-ref HEAD)
fi
echo "REF_NAME=${REF_NAME,,}" >> $GITHUB_ENV
- name: Debug REF_NAME
run: echo "REF_NAME=${{ env.REF_NAME }}"
- name: Build and push Docker image on GitHub Container Registry
run: |
cd docker
IMAGE_NAME=ghcr.io/ghcr.io/spamscope/mail-parser/mailparser
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=$TAG \
-t $IMAGE_NAME:$TAG \
-t $IMAGE_NAME:latest .
docker push $IMAGE_NAME:$TAG
docker push $IMAGE_NAME:latest
else
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=${{ env.REF_NAME }} \
-t $IMAGE_NAME:develop .
docker push $IMAGE_NAME:develop
fi
- name: Build and push Docker image on Docker Hub
run: |
cd docker
IMAGE_NAME=docker.io/${{ secrets.DOCKER_USERNAME }}/spamscope-mail-parser
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=$TAG \
-t $IMAGE_NAME:$TAG \
-t $IMAGE_NAME:latest .
docker push $IMAGE_NAME:$TAG
docker push $IMAGE_NAME:latest
else
docker build \
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
--label "org.opencontainers.image.description=Easy way to pass from raw mail to Python object" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--build-arg BRANCH=${{ env.REF_NAME }} \
-t $IMAGE_NAME:develop .
docker push $IMAGE_NAME:develop
fi